OwnerDocument Property

XmlDocumentFragment.OwnerDocument Property


Gets the XmlDocument to which this node belongs.

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

public override XmlDocument OwnerDocument { get; }

Property Value

Type: System.Xml.XmlDocument

The XmlDocument to which this node belongs.

When adding nodes to the current node, use the XmlDocument returned by the OwnerDocument property to create the node.

The following example adds a new node to the document fragment.

using System;
using System.IO;
using System.Xml;

public class Sample
  public static void Main()
    // Create the XmlDocument.
    XmlDocument doc = new XmlDocument();

    // Create a document fragment.
    XmlDocumentFragment docFrag = doc.CreateDocumentFragment();

    // Display the owner document of the document fragment.

    // 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";

    Console.WriteLine("Display the document fragment...");

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft