Export (0) Print
Expand All

XmlNode.CreateNavigator Method

Creates an XPathNavigator for navigating this object.

[Visual Basic]
Public Overridable Function CreateNavigator() As XPathNavigator _
   Implements IXPathNavigable.CreateNavigator
[C#]
public virtual XPathNavigator CreateNavigator();
[C++]
public: virtual XPathNavigator* CreateNavigator();
[JScript]
public function CreateNavigator() : XPathNavigator;

Return Value

An XPathNavigator object. The XPathNavigator is positioned on the node from which the method was called. It is not positioned on the root of the document.

Implements

IXPathNavigable.CreateNavigator

Remarks

The XPathNavigator provides read-only, random access to data. Because it is optimized for XSLT transformations, it provides performance benefits when used as an input mechanism to the XslTransform.Transform method.

This method is a Microsoft extension to the Document Object Model (DOM).

Example

The following example loads and edits an XML document before performing an XSLT transform.

[Visual Basic] 
Dim doc as XmlDocument = new XmlDocument()
doc.Load("books.xml")

' Modify the XML file.
Dim root as XmlElement = doc.DocumentElement
root.FirstChild.LastChild.InnerText = "12.95"

' Create an XPathNavigator to use for the transform.
Dim nav as XPathNavigator = root.CreateNavigator()

' Transform the file.
Dim xslt as XslTransform = new XslTransform()
xslt.Load("output.xsl")
Dim writer as XmlTextWriter = new XmlTextWriter("books.html", nothing)
xslt.Transform(nav,nothing, writer, nothing)

[C#] 
XmlDocument doc = new XmlDocument();
doc.Load("books.xml");

// Modify the XML file.
XmlElement root = doc.DocumentElement;
root.FirstChild.LastChild.InnerText = "12.95";

// Create an XPathNavigator to use for the transform.
XPathNavigator nav = root.CreateNavigator();

// Transform the file.
XslTransform xslt = new XslTransform();
xslt.Load("output.xsl");
XmlTextWriter writer = new XmlTextWriter("books.html", null);
xslt.Transform(nav, null, writer, null);

[C++] 
XmlDocument* doc = new XmlDocument();
doc -> Load(S"books.xml");

// Modify the XML file.
XmlElement * root = doc -> DocumentElement;
root -> FirstChild -> LastChild -> InnerText = S"12.95";

// Create an XPathNavigator to use for the transform.
XPathNavigator * nav = root -> CreateNavigator();

// Transform the file.
XslTransform* xslt = new XslTransform();
xslt -> Load(S"output.xsl");
XmlTextWriter* writer = new XmlTextWriter(S"books.html", 0);
xslt -> Transform(nav, 0, writer, 0);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

XmlNode Class | XmlNode Members | System.Xml Namespace | XslTransform

Show:
© 2014 Microsoft