XmlNode.CreateNavigator XmlNode.CreateNavigator XmlNode.CreateNavigator XmlNode.CreateNavigator Method

定義

建立 XPathNavigator 以瀏覽這個物件。Creates an XPathNavigator for navigating this object.

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 Function CreateNavigator () As 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.

實作

範例

下列範例會先載入和編輯 XML 檔,然後再執行 XSLT 轉換。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.Transform做為方法的輸入機制時,會提供效能優勢。Because 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).

適用於

另請參閱