XmlNode.CreateNavigator 方法

定义

创建 XPathNavigator 以浏览此对象。

public:
 virtual System::Xml::XPath::XPathNavigator ^ CreateNavigator();
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 定位在从其调用方法的节点上。 它不定位在文档的根上。

实现

示例

以下示例在执行 XSLT 转换之前加载和编辑 XML 文档。

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提供对数据的只读随机访问。 由于它针对 XSLT 转换进行了优化,因此在用作 方法的输入机制 XslTransform.Transform 时可提供性能优势。

此方法是文档对象模型 (DOM) 的Microsoft扩展。

适用于

另请参阅