Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

XObject.Parent Property

Definition

Namespace:
System.Xml.Linq
Assemblies:
System.Xml.Linq.dll, System.Xml.XDocument.dll
Assemblies:
netstandard.dll, System.Xml.XDocument.dll
Assembly:
System.Xml.XDocument.dll
Assembly:
System.Xml.Linq.dll
Assembly:
netstandard.dll
Source:
XObject.cs
Source:
XObject.cs
Source:
XObject.cs
Source:
XObject.cs
Source:
XObject.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Gets the parent XElement of this XObject.

public:
 property System::Xml::Linq::XElement ^ Parent { System::Xml::Linq::XElement ^ get(); };
public System.Xml.Linq.XElement Parent { get; }
public System.Xml.Linq.XElement? Parent { get; }
member this.Parent : System.Xml.Linq.XElement
Public ReadOnly Property Parent As XElement

Property Value

The parent XElement of this XObject.

Examples

The following example uses this method.

XDocument doc = new XDocument(
 new XComment("A comment in the document."),
 new XElement("Root",
 new XElement("Child", "content")
 )
);
XElement child = doc.Descendants("Child").First();
XElement root = child.Parent;
Console.WriteLine(root.Name);
Dim doc As XDocument = _
 <?xml version="1.0"?>
 <!--A comment in the document.-->
 <Root>
 <Child>content</Child>
 </Root>
Dim child As XElement = doc.Descendants("Child").First()
Dim root As XElement = child.Parent
Console.WriteLine(root.Name)

This example produces the following output:

Root

Remarks

If this XObject has no parent element, this property returns null.

Note

This property returns the parent element, and as children nodes of an XDocument have no parent element, this property returns null for them.

Applies to

See also


Feedback

Was this page helpful?