共用方式為


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 物件。 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 延伸模組。

適用於

另請參閱