Document Representations

This guide explains the differences between the XML document representations available in .NET and XmlPrime.

This topic contains the following sections.

Overview

XmlPrime operates on XPathNavigatorXPathNavigatorXPathNavigator instances for node values. There are a number of XML document representations available in .NET implementing IXPathNavigableIXPathNavigableIXPathNavigable, all of which have different strengths and weaknesses. Whilst all these document representations are compatible with XmlPrime, there are different performance and conformance issues with the different representations. For these reasons, we recommend using an XdmDocumentXdmDocumentXdmDocument, whenever possible for use with XmlPrime, which is a new document representation designed to comply with the XQuery 1.0 and XPath 2.0 Data Model (XDM) specification.

This article outlines the differences between the document representations.

Limitations of the XmlReader

The XmlReaderXmlReaderXmlReader class does not publicly expose the full XML Information Set (InfoSet), and in particular does not publicly report the (DTD) type of attributes. It does not provide any way of examining the external DTDs used by a document. For these reasons it is impossible to determine which nodes are XML IDs and IDREFs if the document uses an external DTD, and it is not possible to identify if this is the case.

Therefore, when loading from an XML reader, the XdmDocumentXdmDocumentXdmDocument is unable to identify ID and IDREF nodes which have been identified by an external DTD.

Limitations of the XPathNavigator

The MoveToIdMoveToIdMoveToId method does not correspond to the id or element-with-id functions, as it fails to account for xml:id attributes, and attributes and elements that have been validated against a schema. The id and element-with-id functions compensate for these limitations at run time.

The XPathNavigator.BaseURIXPathNavigator.BaseURIXPathNavigator::BaseURI property by definition returns the document URI of a node, and not the base URI. The base-uri function scans the ancestors of a node looking for xml:base attributes in order to compute the base URI of a node.

The XPathNavigatorXPathNavigatorXPathNavigator does not expose any DTD type information, and in particular exposes no way of identifying attributes that are typed IDREF from the DTD. As a consequence, the idref function does not see these nodes. The XdmDocumentXdmDocumentXdmDocument does expose this information to the idref function.

System.Xml.XmlDocument

The XmlDocumentXmlDocumentXmlDocument is modelled on the Document Object Model (DOM) Level 1 and Document Object Model (DOM) Level 2 Core. It is an editable document format. However it is not optimized for querying so is not recommended for use with XmlPrime.

 
 
Warning
XmlDocumentXmlDocumentXmlDocument does not provide any indexing of node names, and so can exhibit poor performance when used in XPath expressions.
 
 
 
Warning
The XPathNavigatorXPathNavigatorXPathNavigators returned from an XmlDocumentXmlDocumentXmlDocument do not perform any fixup of namespace declarations. When adding a node to a document, it is important to ensure any prefixes added already have the correct bindings in scope. If this is not the case then XmlPrime may produce unexpected results.
 
 
 
Note
Since XmlDocumentXmlDocumentXmlDocument implements the DOM and not the XDM, insignificant whitespace in elements with complex content is not stripped.
 

System.Xml.XPath.XPathDocument

The XPathDocumentXPathDocumentXPathDocument is modelled on the XPath 1.0 Data Model (XDM). It is designed for high performance read-only use.

 
 
Warning
Since XPathDocumentXPathDocumentXPathDocument was designed with XPath 1.0 in mind, it does not preserve any schema information. Thus all documents are treated as untyped by XmlPrime.
 
 
 
Note
Since XPathDocumentXPathDocumentXPathDocument ignores schema information, insignificant whitespace in elements with complex content is not stripped.
 

System.Xml.Linq.XDocument

Whilst XDocumentXDocumentXDocument does not implement IXPathNavigableIXPathNavigableIXPathNavigable, an XPathNavigatorXPathNavigatorXPathNavigator instance can be created with the CreateNavigatorCreateNavigatorCreateNavigator method. The XDocument is an editable document designed to support LINQ. However it is not optimized for querying, so is not recommended for use with XmlPrime.

 
 
Warning
XDocumentXDocumentXDocument does not provide any indexing of node names, and so can exhibit poor performance when used in XPath expressions.
 
 
 
Warning
XDocumentXDocumentXDocument does not preserve any schema information. Thus all documents are treated as untyped by XmlPrime.
 
 
 
Note
Since XDocumentXDocumentXDocument ignores schema information, insignificant whitespace in elements with complex content is not stripped.
 

XmlPrime.XdmDocument

The XdmDocumentXdmDocumentXdmDocument is modelled on the XQuery 1.0 and XPath 2.0 Data Model (XDM) and is designed for high performance read-only use. It is similar to XPathDocumentXPathDocumentXPathDocument, but also preserves schema information. It is recommended to use this document format for documents passed to XmlPrime.

 
 
Note
As mentioned above the XmlReaderXmlReaderXmlReader does not expose DTD information. XmlPrime parses the DTD in the internal subset and uses this to identify ID and IDREF attributes, but any DTD types in external DTDs cannot be used. If you are using DTDs with your document, but are not using schema types then consider using an XPathDocumentXPathDocumentXPathDocument instead.