XML Access Modes, Object Models, and Serialization in .Net

When I researched the topic of my recent post about the XmlSerializer I became aware that there are more ways to process XML data in .Net than I knew about. Here is an overview of how you can access XML data in .Net.

XML data

The .Net framework provides the following classes to store XML data in memory:

  • XSD proxy classes

XML serialization

The .Net framework implements a set of dependent classes to serialize and deserialize XML data. Each class in this list can be instantiated using a parameter of the classes below it:

  • filename (string)

XML query and manipulation

Besides the classes named above, other classes exist to query and manipulate XML data:

Putting it all together

 

Data model Access (MSDN summary) Serialization XML Query
XmlDocument “Represents an XML document.”
In-Memory
OuterXml
LoadXml()
Load(XmlReader), Save(XmlWriter)
XPath SelectSingleNode(), SelectNodes();
Linq To Objects;
XPathNavigator CreateNavigator()
XDocument “Represents an XML document.”
In-Memory
Load(XmlReader), Save(XmlWriter),
Parse()
XmlReader CreateReader();
Linq To Xml;
XPathNavigator CreateNavigator()
XSD proxy classes In-Memory XmlSerializer,
Introduction on MSDN
Linq To Objects
XmlReader “a reader that provides fast, non-cached, forward-only access to XML data.” Create(…) GetAttribute(), MoveTo*(),
Read*()
XmlNodeReader “a reader that provides fast, non-cached forward only access to XML data in an XmlNode.” (XmlNode) derived from XmlReader
XPathNavigator “a cursor model for navigating and editing XML data.”
“read-only if created by XPathDocument; editable if created by XmlDocument
(CreateNavigator()) GetAttribute(), Value*,
MoveTo();
XPath Select(), Select*();
XmlReader ReadSubtree()
XPathDocument “a fast, read-only, in-memory representation of an XML document” Constructor() XPathNavigator CreateNavigator()

Conversion and Comparison

MSDN

Converting from XmlDocument to XDocument

Comparing XmlReader to SAX Reader

StackOverflow

Use XDocument as the source for XmlSerializer.Deserialize?

Converting XDocument to XmlDocument and vice versa

XDocument or XMLDocument

XMLSerializer vs XMLReader vs XMLDocument vs XDocument Performance Comparison

Other
XmlDocument versus XDocument versus XmlReader/XmlWriter

Performance: LINQ to XML vs XmlDocument vs XmlReader

One Response to XML Access Modes, Object Models, and Serialization in .Net

  1. [...] Therefore we first need to know which tag@k attributes are used in the XML. Given the size of .osm files (the extract for Austria is currently 3GB), a simple XmlDocument.Load() is bound to fail due to memory restrictions. Remember that both XmlDocument and XDocument are in-memory representations of the XML tree. See also my earlier comparison of XML access methods in .Net. [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 65 other followers

%d bloggers like this: