XmlAttribute::OwnerElement Property

 

Gets the XmlElement to which the attribute belongs.

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

public:
property XmlElement^ OwnerElement {
	virtual XmlElement^ get();
}

Property Value

Type: System.Xml::XmlElement^

The XmlElement that the attribute belongs to or null if this attribute is not part of an XmlElement.

The following example creates an attribute and displays the OwnerElement of the attribute.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book><title>Pride And Prejudice</title></book>" );

   //Create an attribute.
   XmlAttribute^ attr;
   attr = doc->CreateAttribute( "bk", "genre", "urn:samples" );
   attr->Value = "novel";

   //Try to display the attribute's owner element.
   if ( attr->OwnerElement == nullptr )
      Console::WriteLine( "The attribute has not been added to an element\r\n" );
   else
      Console::WriteLine( attr->OwnerElement->OuterXml );


   //Add the attribute to an element.
   doc->DocumentElement->SetAttributeNode( attr );

   //Display the attribute's owner element.
   Console::WriteLine( "Display the owner element..." );
   Console::WriteLine( attr->OwnerElement->OuterXml );
}

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