tags:

views:

310

answers:

6

The question says it all... looking for the n00b overview w/ best practices.

Thanks, -greg

+4  A: 

If you are working with .NET 3.5, LINQ to XML is certainly a very good way to interact with XML.

MSDN Link

Jason Miesionczek
+2  A: 

There are classes to read XML:

  • XmlDocument is slow and memory-intensive: it parses the XML and loads it into an in-RAM DOM, which is good if you want to edit it.
  • XmlReader is less memory-intensive: it scans the XML from front to back, never needing to keep all of it in RAM at once.

Similarly, for writing you can construct an XmlDocument and then save it, or use an XmlWriter.

ChrisW
What about other stuff like XPathNavigator?
Roger Lipscombe
I haven't used other stuff like XPathNavigator; feel free to edit my answer if you want to include/mention it.
ChrisW
+1  A: 

In a performance critical application XmlReader/XmlWriter are a good choice (see here) for the sake of simplicity which is offered by Linq to XML and XmlDocument.

Darin Dimitrov
+1  A: 

By far the simplest method I've found for dealing with XML in C# is to use the XML Serialization tools. For example: http://www.dotnetjohn.com/articles.aspx?articleid=173.

Essentially, you can define C# classes that match your XML file (in fact, you can have them created for you if you have an XML definition file) and then you simply initialize instances of those classes directly from the XML file. Once you have them as instances, you can manipulate them as you wish and rewrite them back into XML files just as easily.

dominic hamon
A: 

I've found the MvpXml project very useful in past scenarios where performance is a consideration. There's a wealth of knowledge about good practice within their project pages: http://www.codeplex.com/MVPXML

FreddyB