XmlDocumentFragment.OwnerDocument 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得這個節點所屬的 XmlDocument。
public:
virtual property System::Xml::XmlDocument ^ OwnerDocument { System::Xml::XmlDocument ^ get(); };
public override System.Xml.XmlDocument OwnerDocument { get; }
member this.OwnerDocument : System.Xml.XmlDocument
Public Overrides ReadOnly Property OwnerDocument As XmlDocument
屬性值
這個節點所屬的 XmlDocument。
範例
下列範例會將新的節點新增至檔片段。
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
// Create the XmlDocument.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<items/>");
// Create a document fragment.
XmlDocumentFragment docFrag = doc.CreateDocumentFragment();
// Display the owner document of the document fragment.
Console.WriteLine(docFrag.OwnerDocument.OuterXml);
// Add nodes to the document fragment. Notice that the
// new element is created using the owner document of
// the document fragment.
XmlElement elem = doc.CreateElement("item");
elem.InnerText = "widget";
docFrag.AppendChild(elem);
Console.WriteLine("Display the document fragment...");
Console.WriteLine(docFrag.OuterXml);
}
}
Option Explicit
Option Strict
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
' Create the XmlDocument.
Dim doc As New XmlDocument()
doc.LoadXml("<items/>")
' Create a document fragment.
Dim docFrag As XmlDocumentFragment = doc.CreateDocumentFragment()
' Display the owner document of the document fragment.
Console.WriteLine(docFrag.OwnerDocument.OuterXml)
' Add nodes to the document fragment. Notice that the
' new element is created using the owner document of
' the document fragment.
Dim elem As XmlElement = doc.CreateElement("item")
elem.InnerText = "widget"
docFrag.AppendChild(elem)
Console.WriteLine("Display the document fragment...")
Console.WriteLine(docFrag.OuterXml)
End Sub
End Class
備註
當將節點加入至目前節點中,使用XmlDocument所傳回OwnerDocument來建立節點的屬性。