.NET Framework Class Library
XObject.Parent Property
Namespace: System.Xml.Linq
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
Syntax
Visual Basic
Public ReadOnly Property Parent As XElement Get
C#
public XElement Parent { get; }
Visual C++
public: property XElement^ Parent { XElement^ get (); }
F#
member Parent : XElement
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. |
Examples
The following example uses this method.
C#
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);
Visual Basic
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
Version Information
.NET Framework
Supported in: 4, 3.5.NET Framework Client Profile
Supported in: 4, 3.5 SP1Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also
Note