XmlAttribute.OwnerElement Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the XmlElement to which the attribute belongs.

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

Public Overridable ReadOnly Property OwnerElement As XmlElement

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.

Imports System
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()

    Dim doc as XmlDocument = new XmlDocument()
    doc.LoadXml("<book>" & _
                "<title>Pride And Prejudice</title>" & _

    'Create an attribute.
    Dim attr as XmlAttribute
    attr = doc.CreateAttribute("bk","genre","urn:samples")
    attr.Value = "novel"

    'Try to display the attribute's owner element.
    if attr.OwnerElement is nothing
      Console.WriteLine("The attribute has not been added to an element")
    end if

    'Add the attribute to an element.

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

  end sub
end class

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