XmlNode.CreateNavigator 方法

定义

创建 XPathNavigator 以浏览此对象。Creates an XPathNavigator for navigating this object.

public:
 virtual System::Xml::XPath::XPathNavigator ^ CreateNavigator();
public virtual System.Xml.XPath.XPathNavigator CreateNavigator ();
public System.Xml.XPath.XPathNavigator CreateNavigator ();
abstract member CreateNavigator : unit -> System.Xml.XPath.XPathNavigator
override this.CreateNavigator : unit -> System.Xml.XPath.XPathNavigator
Public Overridable Function CreateNavigator () As XPathNavigator
Public Function CreateNavigator () As XPathNavigator

返回

XPathNavigator

用于导航节点的 XPathNavigator 对象。An XPathNavigator object used to navigate the node. XPathNavigator 定位在从其调用方法的节点上。The XPathNavigator is positioned on the node from which the method was called. 它不定位在文档的根上。It is not positioned on the root of the document.

实现

示例

下面的示例在执行 XSLT 转换之前加载并编辑 XML 文档。The following example loads and edits an XML document before performing an XSLT transform.

XmlDocument^ doc = gcnew 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 = gcnew XslTransform;
xslt->Load( "output.xsl" );
XmlTextWriter^ writer = gcnew XmlTextWriter( "books.html", nullptr );
xslt->Transform( nav, nullptr, writer, nullptr);
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);
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)

注解

XPathNavigator提供对数据的只读随机访问。The XPathNavigator provides read-only, random access to data. 由于它已针对 XSLT 转换进行了优化,因此它可在用作方法的输入机制时提供性能优势 XslTransform.TransformBecause it is optimized for XSLT transformations, it provides performance benefits when used as an input mechanism to the XslTransform.Transform method.

此方法是文档对象模型 (DOM) 的 Microsoft 扩展。This method is a Microsoft extension to the Document Object Model (DOM).

适用于

另请参阅