Read / write XML using C # /. NET

What are the best features, methods and / or methods for reading / writing XML using C # /. NET?

+2
source share
5 answers

There are classes for reading XML:

  • XmlDocument slow and memory intensive: it parses the XML and loads it into the DOM in RAM, which is good if you want to edit it.
  • XmlReader consumes less memory: it scans XML from front to back, and it does not need to permanently store everything in RAM.

Similarly, for recording, you can build XmlDocumentand then save it or use it XmlWriter.


After I wrote above, now there is a new set of APIs that are easier to use: for example, XDocumentand classes XElement.

+4

.NET 3.5, LINQ to XML, , XML.

MSDN

+8

, XML #, XML Serialization. : http://www.dotnetjohn.com/articles.aspx?articleid=173.

, #, XML ( , XML), XML. , , XML.

+3

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

+2
source

I found the MvpXml project very useful in past scenarios where performance is a consideration. There is a lot of knowledge about good practice on the project pages: http://www.codeplex.com/MVPXML

+2
source

All Articles