Sunday, June 6, 2010

XPathDocument vs XmlDocument

XmlDocument
XPathDocument
- Based on W3C DOM Model
- Loads entire Xml in memory
- Read/Write
- Slower than XPathDocument
- Support for XPath/XSLT
- Supports both XPathNavigator and DOM interfaces
- Based on XPath Data Model
- Loads entire Xml in memory
- Read Only
- Faster than XmlDocument
- Optimized support for XPath/XSLT
- Supports only XPathNavigator interfaces


XmlDocument is based on the W3C XML DOM, which is an object model that basically covers all XML syntaxes, including low-level syntax sugar such as entities, CDATA sections, DTD, notations, etc. That's a document-centric model and it allows for full fidelity when loading/saving XML documents.

XPathDocument is based on an XPath 1.0 data model that is a read-only XML Infoset-compatible data-centric object model that covers only semantically significant parts of XML, leaving out insignificant syntax details - no DTD, no entities, no CDATA, no adjacent text nodes, only significant data expressed as a tree with seven types of nodes.

Simple and lightweight. That's why XPathDocument is a preferred data store for read-only scenarios, especially with XPath or XSLT involved.

No comments: