Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I'm using c# .net and need to find out how to read an xml file. I found a couple of references but I'm still not sure that c# actually has functions to do what I need. My references are http://andrewsolymosi.sys-con.com/node/40761/mobile[^]

And Introduction to XML and XSLT in C#.Net[^]

For the first reference, I thought it had an example of taking a string and putting it in an xml class for further processing later, but I'm not seeing that now. I know how to read the file into a string, but not how to process the file into usable xml.

The second reference doesn't seem to be what I need either. I have xml already and didn't want to re-process it bit by bit into nodes, attributes, and elements. Surely there must be a good way to do this easily with the functions of c#.

Does anyone have an example of this?

Thanks!
Posted

 
Share this answer
 
Please see my short overview of different methods of XML parsing:


  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^].
  2. Use the class System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^].
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].


I'm not sure you really need working with XML directly. Chances are, you would rather need serialization, in particular, Data Contract. Please see:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

—SA
 
Share this answer
 
v2
Check this article. I have explained briefly. Also source code is attached.

XML to DataSet or GridView and back[^]
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900