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.”
Load(XmlReader), Save(XmlWriter)
XPath SelectSingleNode(), SelectNodes();
Linq To Objects;
XPathNavigator CreateNavigator()
XDocument “Represents an XML document.”
Load(XmlReader), Save(XmlWriter),
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*(),
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*,
XPath Select(), Select*();
XmlReader ReadSubtree()
XPathDocument “a fast, read-only, in-memory representation of an XML document” Constructor() XPathNavigator CreateNavigator()

Conversion and Comparison


Converting from XmlDocument to XDocument

Comparing XmlReader to SAX Reader


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

XmlDocument versus XDocument versus XmlReader/XmlWriter

Performance: LINQ to XML vs XmlDocument vs XmlReader

1 thought on “XML Access Modes, Object Models, and Serialization in .Net

  1. Pingback: Parsing and Analyzing OpenStreetMap Export Files « devioblog

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.