Click here to Skip to main content
12,400,183 members (57,345 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# XML
Anyone have a link for: How to work with XML in C#? Thanks!
Posted 3-Feb-13 11:42am
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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Nemanja Petrovic 5-Feb-13 14:48pm
   
Thanks!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
v2
Comments
   
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
Nemanja Petrovic 5-Feb-13 14:47pm
   
Thanks!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  
Comments
Espen Harlinn 3-Feb-13 19:07pm
   
That's a nice reply, Sergey :-D
   
Thank you, Espen.
—SA
Nemanja Petrovic 5-Feb-13 14:47pm
   
Thanks!
   
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 3 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100