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.XmlDocumentPublic 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 的 来创建节点。