Click here to Skip to main content
15,896,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Anyone have a link for: How to work with XML in C#? Thanks!
Posted
Comments
PIEBALDconsult 3-Feb-13 18:27pm    
What are you trying to do?

In the maen time, read up on XmlDocument
http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx

Check this link out.

C# and XML Source Code Documentation[^]
 
Share this answer
 
Comments
[no name] 5-Feb-13 14:48pm    
Thanks!
First of all you should have a look at MSDN:
LINQ to XML[^]
You will probably also like to have a look at:
Understanding C#: Simple LINQ to XML[^]
LINQ to XML[^]

If you're going to work with really large xml files, there is a SAX implementation available at: SAX for .NET[^]


Best regards
Espen Harlinn
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 3-Feb-13 19:06pm    
Nice links, a 5.
Maybe I gave a just bit more comprehensive answer, please see... :-)
—SA
Espen Harlinn 3-Feb-13 19:08pm    
>> please see...
I certainly did :-D
[no name] 5-Feb-13 14:47pm    
Thanks!
There are different XML libraries in .NET. Here is a short overview:


  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 classes System.Xml.XmlTextWriter and 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.xmlwriter.aspx[^], 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[^].


Note that in many cases you don't need to work with XML directly. It can be done for you if you are using serialization. Please see:
http://en.wikipedia.org/wiki/Serialization#.NET_Framework[^],
http://msdn.microsoft.com/en-us/library/vstudio/aa349369%28v=vs.90%29.aspx[^].

One of the most advanced and, at the same time, easiest to use serialization is based on Data Contract. Please see: http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

Please see also my past answer where I advocate this approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^].

—SA
 
Share this answer
 
Comments
Espen Harlinn 3-Feb-13 19:07pm    
That's a nice reply, Sergey :-D
Sergey Alexandrovich Kryukov 3-Feb-13 19:19pm    
Thank you, Espen.
—SA
[no name] 5-Feb-13 14:47pm    
Thanks!
Sergey Alexandrovich Kryukov 5-Feb-13 14:51pm    
You are welcome.
Good luck, call again.
—SA

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