XmlAttribute.OwnerElement Property
.NET Framework 3.0
Gets the XmlElement to which the attribute belongs.
Namespace: System.Xml
Assembly: System.Xml (in system.xml.dll)
Assembly: System.Xml (in system.xml.dll)
The following example creates an attribute and displays the OwnerElement of the attribute.
using System; using System.IO; using System.Xml; public class Sample { public static void Main(){ XmlDocument doc = new 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==null) 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); } }
import System.*;
import System.IO.*;
import System.Xml.*;
public class Sample
{
public static void main(String[] args)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book>"
+ "<title>Pride And Prejudice</title>"
+ "</book>");
//Create an attribute.
XmlAttribute attr;
attr = doc.CreateAttribute("bk", "genre", "urn:samples");
attr.set_Value("novel");
//Try to display the attribute's owner element.
if (attr.get_OwnerElement() == null) {
Console.WriteLine("The attribute has not been added to an"
+ " element\r\n");
}
else {
Console.WriteLine(attr.get_OwnerElement().get_OuterXml());
}
//Add the attribute to an element.
doc.get_DocumentElement().SetAttributeNode(attr);
//Display the attribute's owner element.
Console.WriteLine("Display the owner element...");
Console.WriteLine(attr.get_OwnerElement().get_OuterXml());
} //main
} //Sample
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.