Home > Articles > Web Services > XML

XML in .NET: XPathNavigator and XSLT

  • Print
  • + Share This
Dale Michalk continues his tour of the XML landscape of .NET by exploring the discovery of new .NET APIs with the XPathNavigator API and XSLT support of the XslTransform class.
Like this article? We recommend

This article continues our tour through the XML landscape of .NET. So far, we have covered object serialization, the Document Object Model (DOM) API, and the streaming API of XmlReader/XmlWriter. This article continues the discovery of new .NET APIs with the XPathNavigator API and XSLT support of the XslTransform class.

Universal XML API

XPathNavigator provides a generic access API over multiple types of document sources. The XmlDocument class of the DOM world, the XmlDataDocument class that bridges the DOM world with ADO.NET and the DataSet, and the XPathDocument class that we focus on in this article for XPath/XSLT document processing are all capable of producing an XPathNavigator from their XML data sources. They signal this capability to outside clients by implementing the IXPathNavigable interface, which has a single method named CreateNavigator that returns an instance of XPathNavigator. XslTransform, the workhorse class for XSLT processing in .NET, is able to consume XPathNavigator and XPathDocument instances to transform documents in an efficient manner. Figure 1 shows how all the pieces fit together to make XPathNavigator the universal API of XML in .NET.

Figure 1 XPathNavigator and XML in .NET.

XPathNavigator shares the cursor-style access paradigm and the read-only limitation of XmlReader. If you need to create XML content, you have to look at the XmlDocument or XmlWriter classes. Fortunately, XPathNavigator is well suited for quick and easy information retrieval. Data retrieval and cursor movement are accomplished by methods and attributes anchored on the XPathNavigator class. The attributes in the following list are remarkably similar to the XmlReader class.

  • Name
  • Value
  • NodeType
  • LocalName
  • Prefix
  • HasAttributes
  • HasChildren
  • + Share This
  • 🔖 Save To Your Account