XmlDocumentFragment::OwnerDocument Property

 

Gets the XmlDocument to which this node belongs.

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

public:
property XmlDocument^ OwnerDocument {
	virtual XmlDocument^ get() override;
}

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.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 );
}

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
Show: