Freigeben über


XmlDocumentFragment.OwnerDocument-Eigenschaft

Ruft das XmlDocument ab, zu dem dieser Knoten gehört.

Namespace: System.Xml
Assembly: System.Xml (in system.xml.dll)

Syntax

'Declaration
Public Overrides ReadOnly Property OwnerDocument As XmlDocument
'Usage
Dim instance As XmlDocumentFragment
Dim value As XmlDocument

value = instance.OwnerDocument
public override XmlDocument OwnerDocument { get; }
public:
virtual property XmlDocument^ OwnerDocument {
    XmlDocument^ get () override;
}
/** @property */
public XmlDocument get_OwnerDocument ()
public override function get OwnerDocument () : XmlDocument

Eigenschaftenwert

Das XmlDocument, zu dem dieser Knoten gehört.

Hinweise

Verwenden Sie beim Hinzufügen von Knoten zum aktuellen Knoten das XmlDocument, das von der OwnerDocument-Eigenschaft zum Erstellen des Knotens zurückgegeben wurde.

Beispiel

Im folgenden Beispiel wird dem Dokumentfragment ein neuer Knoten hinzugefügt.

Option Explicit
Option Strict

Imports System
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 'Main
End Class 'Sample
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);
  }
}
#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   // Create the XmlDocument.
   XmlDocument^ doc = gcnew 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 );
}
import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        // 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.get_OwnerDocument().get_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.set_InnerText("widget");
        docFrag.AppendChild(elem);

        Console.WriteLine("Display the document fragment...");
        Console.WriteLine(docFrag.get_OuterXml());
    } //main
} //Sample

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

XmlDocumentFragment-Klasse
XmlDocumentFragment-Member
System.Xml-Namespace