.NET Framework API Reference

System.Xml.XPath

XPathNavigator Class

Namespace: System.Xml.XPath

Represents a node in an XML document or stream, and provides methods for navigating to related nodes.

Overview

The XPathNavigator class provides a read-only, forward-only, non-cached random access interface to an XML document. It allows you to navigate through the document, select nodes, and retrieve their values. This class is fundamental for implementing XPath queries and XSLT transformations.

XPathNavigator is designed to be lightweight and efficient, making it suitable for processing large XML documents. It supports various node types, including elements, attributes, text nodes, comments, and processing instructions.

Constructors

The XPathNavigator class itself is abstract and cannot be instantiated directly. You typically obtain an instance of a concrete XPathNavigator implementation (such as XPathDocument.CreateNavigator()) from an XML document or data source.

Properties

Methods

Remarks

XPathNavigator is an abstract base class. To use it, you typically create an instance of a class that implements it, such as:

You can obtain a navigator from these classes using their CreateNavigator() method.

using System; using System.Xml; using System.Xml.XPath; public class Example { public static void Main(string[] args) { string xmlString = @" Everyday Italian Giada De Laurentiis 2005 30.00 Harry Potter J K. Rowling 2005 29.99 "; XmlDocument doc = new XmlDocument(); doc.LoadXml(xmlString); XPathNavigator navigator = doc.CreateNavigator(); // Move to the first book element if (navigator.MoveToChild("bookstore", "")) { if (navigator.MoveToChild("book", "")) { // Get the category attribute string category = navigator.GetAttribute("category", ""); Console.WriteLine($"Category: {category}"); // Move to the title element if (navigator.MoveToChild("title", "")) { Console.WriteLine($"Title: {navigator.Value}"); navigator.MoveToParent(); // Back to book } navigator.MoveToParent(); // Back to bookstore } navigator.MoveToParent(); // Back to root } } }

Requirements

Namespace: System.Xml.XPath

Assembly: System.Xml (in System.Xml.dll)

Platforms: .NET Framework 2.0, .NET Framework 3.0, .NET Framework 3.5, .NET Framework 4.0, .NET Framework 4.5, .NET Framework 4.6, .NET Framework 4.7, .NET Framework 4.8

Security: Full trust for the immediate caller. This member cannot be used by code that is executing in a partially trusted context.