.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Help with reading xml with asp.net

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :ASP.Net

I have to read the following xml in my c# asp.net code:


<?xml version="1.0" encoding="utf-8" ?>
    <Blog id="1" title="kkkkkkkkk">
        <Post id="1">
<Post id="2">

 Any idea how to get the information to my code by blogid and postid ?

View Complete Post

More Related Resource Links

Reading and Writing Images From a Windows Mobile Database using UltraLite 10(C#)

Periodically I get a request for information on how to read and write binary data to a database running on Windows Mobile. If you search the Internet you can typically find examples that are available on Windows Desktops or allow you to read and write to a local file system. The problem is that it can take a bit of work to get this code to work on Windows Mobile accessing a database.

Ultimately you might be asking, why would I want to store and image in a database? Well in an environment where you synchronizing data between a local mobile database and a consolidated (central) database this can be extremely useful. Imagine if an insurance adjuster went to an accident scene, took a picture of a damaged car, loaded it into his Windows Mobile database and then replicated that image up to the Insurance headquarters for approval. All of this could be done in a very short period of time when using images in the database. Another good example might be a doctor who was waiting for a patient chart to become available. If you could store the image in a database this chart could be sent down to the doctor's device once it became available.

For this article I am not going to get into how to synchronize the images to and from a remote and central database as this is typically fairly straightforward when using a data synchronization technologies like MobiLink

XML Reading and Writing

We learned to process XML files using the Document Object Model as implemented by the XmlDocument class. To go further and make XML friendlier, the .NET Framework provides many other classes for different purposes, allowing you to create and manage nodes from custom .NET classes.
Besides the XmlDocument and the derived classes of XmlNode, the .NET Framework provides the XmlTextWriter class, which is derived from XmlWriter. The XmlTextWriter class works in a top-down approach to create, or deal with, the contents of an XML file. This class writes an XML node and moves down without referring

reading values from config files in NUnit tests


One of my NUnit tests has to read in some values from config files.  In my main application this process works perfectly well, however when I run the unit test, the code that reads in the values from the config files doesnt read anything in.  Ive tried putting app.config in my unit test project (I even tried web.config) but nothing seems to work.  Are there any special steps involved when reading from config files in an nunit test ?

Reading data from .doc or .docx and inserting into db



A vendor is providing content which needs to be inserted into the db. The content is basically questions with options and explanations. An example is below.


Maximum memory for string ? . System.MemoryOutOfException Occurs when reading the Content of the fil



I have a C++ code which reads a file [vtk file - its similar to text file only]. and try to store it in string.

here's the code:

String^ ParallelProjectionRenderer::GetVolumeDataAsString(String^ FileName)

    vtkSmartPointer<vtkDataSetWriter> sWriter = vtkSmartPointer<vtkDataSetWriter>::New();

    String^ FileName = "D:\\Users\\...";

    char * sptName = static_cast<char *>(Marshal::StringToHGlobalAnsi(FileName).ToPointer());







    String^ result= File::ReadAllText(FileName);   [it breaks here with system.memoryoutofexception when the file size is huge]

    return result;


this code executes fine when the file size is less than 8mb.

I wanted to know whats the maximum memory allocated to the string.

As a workaround i skipped reading out in C++ code. and i tried to read the file contents in asp.net C# code and stor

reading the result of a web service (XML)


Hi all,

I registered for a service that returns me the geolocation of the visitor and i process it in my exe application (c#).

But i dont know how to read that data in cs?

Here is the link that i send : 


and returning page content ;  

<?xml version="1.0" encoding="UTF-8" ?>
  <provider>Turk Telekom</provider>

Reading values from data access component individually



I am trying to pick data from the database through data access layer and use those values in different text boxes on the page.Basically on a click on the form, modal popup is planned to read the database and put the values into different text boxes which can be latter changed/ updated.

 What I am unable to do is accessing those values on the form itself progamatically. I will be thankful for any ideas and help.

My data access component is as follows:




new SqlParameter ("@reg_id", SqlDbType.Int ));"@reg_id"].Value=reg_id;try




Reading xml data from xml string




i have string like below:

<?xml version="1.0" encoding="utf-8" ?>










reading excel file problem



i have 200 rows in my excel file. im using OleDbConnection to read the excel file.

The problem is that it will read all the blank rows from row 200 onwards. Is there a configuration im missing ? or is there a way to import all rows that has data? Here's some of my code.

string excelConnectionString =
               "Provider=Microsoft.Jet.OLEDB.4.0;" +
                "Data Source=" + filePath + ";" +
                "Extended Properties=Excel 8.0";

OleDbConnection excelConnection =
                    new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties='Excel 8.0;HDR=NO'");

OleDbCommand cmd = new OleDbCommand("Select * from [list$]",excelConnection);

Reading an excel file



i am trying to read an excel file.

when i read the entire file, it works fine.

but when i try to read a single column, i get the following exception message:

"Could not find installable ISAM".

the code i am using is:

string  connString = "Provider=Microsoft.ACE.OLEDB.12.0;" +  


"Data Source="+ fileName + ";" +


"Extended Properties=Excel 12.0;HDR=Yes";

OleDbConnection oledbConn = new OleDbConnection(connString);




// Open connection



// Create OleDbCommand object and select data from worksheet Sheet1

OleDbCommand cmd = new OleDbCommand

MySqlDataReader - Reading special column characters



I have a MySQL database, which contains columns with danish characters like ø æ and å.

When the MySqlDataReader tries to read this column name:

for (int i = 0; i < MysqlReader.FieldCount; i++)
       string Key = MysqlReader.GetName(i);


The result is not the expected character, but some kind of ASCII value of it. For an example, 'å' gets interpreted as 'Ã¥'.

What to do?

Thanks alot for your help :)

Reading/writing Word documents - keeping formatting


I've done some reading about reading from and writing to a Word doc. The reading from worked without issue:

string strPath = "Test.doc";
FileStream fStream = new FileStream
    (strPath, FileMode.Open, FileAccess.Read);
StreamReader sReader = new StreamReader(fStream);
string text = sReader.ReadToEnd();

But of course this is just a string, without any formatting information included. Writing to the document using a StreamWriter worked, but I received errors when opening the document.

I've also read that trying to perform actions on an Office document on a server without the Office products installed on it can result in mayhem. I'm working on a MVC application that will allow users to upload documents to the server, work on them, save their work and email it around. That doesn't specifically require the need to read/write programmatically, but for certain application functions I do need this. Any helpful suggestions are appreciated.

reading some strange file

hi all,I have a file that i want to read created by a program from another company.I fi open the file in notepad it has all kind of funny chars in it, i tried different ways of reading it in vb.net but the funny chars stay.Anyone has any idea how to read something like this?this is an extract from the file  Z "f 2006/05/19 13:44:28 < ----------- uStreetname 91 1745 Opwijk                                                                                  ' 590208356329 SLIN3f )lÿ%g: )' 29.11.2005grtz & thnx to anyone who looked into this.bjorn

Problem when using Activator.CreateObject and reading App.Config file

Hello, this is the scenario. I have an application that load at runtime severals dll. these dll are actually "adapters" that wraps calls to web services, database and so on. The app.config of the "main" application stores in config sections all information necessary to each adapter (i.e.Web ServiceURL..) and I have created inside each adapter a class to ready those values the loading at run time the DLL has been implemented by storing all necessary types into a dictionary of generics and when I need to instanciate it I call the Activate.CreateObject and I pass the specific type (I means the name of the Adapter class) The problem is that the adapter class itself is not able to get the config value because ConfigSection has not been initialized. If I write: IInterfaceAdap adapt = new myAdapter() -> I read the config data IInterfaceAdap adapt = (IInterfaceAdap)Activator.CreateObject (type) -> now way to read the data stored in the App.Config. I think that I undertood the problem but I'm not able to find a workaround to read data store in the app.config!! I need help please!!  

reading xml data and insert into database table

hi friends, .very urgent for me so only i send following script i create for read xml data and to import to table. i got result for reading xml and rows are added to table but the values are showing null pls clarify this problem. thanks alter procedure pizza_sales ( @xml xml ) as begin INSERT INTO pizza_xml (LOC_CODE, CUST_CODE, PRODUCT_ID, INV_TYPE, INV_NO, INV_DT, INV_QTY_IN_INV_UOM, INV_RATE_IN_BS_CURR, INV_VU_IN_INV_CURR, -- TOTAL_DISC_IN_BS_CURR, NET_INV_VU_IN_INV_CURR, NET_INV_VU_IN_BS_CURR, TOTAL_TXES_IN_BS_CURR ) select table1.column1.value('@LOC_CODE','nvarchar(75)'), table1.column1.value('@CUST_CODE','nvarchar(75)'), table1.column1.value('@PROD_CODE','nvarchar(75)'), table1.column1.value('@INV_TYPE','nvarchar(50)'), table1.column1.value('@INV_NO','nvarchar(100)'), table1.column1.value('@INV_DT','datetime'), table1.column1.value('@INV_QTY_IN_INV_UOM','numeric(28,8)'), table1.column1.value('@INV_RATE_IN_BS_CURR','numeric(28,8)'), table1.column1.value('@INV_VU_IN_INV_CURR','numeric(28,8)'), --table1.column1.value('@TOTAL_DISC_IN_BS_CURR','numeric(28,8)'), table1.column1.value('@NET_INV_VU_IN_INV_CURR','numeric(28,8)'), table1.column1.value('@NET_INV_VU_IN_BS_CURR','numeric(28,8)'), table1.column1.value('@TOTAL_TXES_IN_BS_CURR','numeric(28,8)') from @xml.nodes('pizza/pizzaxml')as table1(column1) end declare @id

XSD: Reading string in ROOT of XML

Hi all, I am making a import from XML to SQL. I have chosen to do this via a XSD file, but I have a problem with the ROOT file of the XMLXML:<Dogs bulkmode="0" xmlns="http://scheme01.isp.com">  <UnderDogs>    ...  </UnderDogs></Dogs>XSD:<xsd:element name="Dogs bulkmode="0" xmlns="http://scheme01.isp.com"" sql:is-constant="1">Unfortunately this does not work. If I (for testing) changes the first line of the XML to <Dogs>, (and corrects the XSD) it works like a charm.  It is not an option to change the XML file, so somehow I need to make the changes within my XSD. Does anyone have any suggestions?RegardsBirger Wilhelmsen

reading excel file without saving to disk first

Having an issue.  I need to be able to read an excel file from a file upload control but I can not save the file to disk first, it must be done in memory.string excelConnectionstring = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="; excelConnectionstring += filePath.Replace("/", "\\"); excelConnectionstring += ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1;'"; OleDbConnection con = new OleDbConnection(excelConnectionstring); OleDbDataAdapter da = new OleDbDataAdapter();Above is my code for reading the data file if it IS saved to disk, but again, I have to be able to do this without saving the file to disk, it must be done in memory.  I have not been able to find any sample code anywhere on how to do this from memory, everything seems to force the file be uploaded, saved to disk, and then read in the connection string, which again I can not do.Any advise would be great, thanks in advance.  I'm really in a bind here.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend