XmlAttribute.OwnerElement Property


Gets the XmlElement to which the attribute belongs.

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

public virtual XmlElement OwnerElement { 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;
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>" +

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

    //Add the attribute to an element.

    //Display the attribute's owner element.
    Console.WriteLine("Display the owner element...");


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