XObject.Parent プロパティ

定義

このXElementの親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

プロパティ値

このXElementの親XObject

次の例では、このメソッドを使用します。

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)

この例を実行すると、次の出力が生成されます。

Root

注釈

この XObject に親要素がない場合、このプロパティは nullを返します。

Note

このプロパティは親要素を返し、 XDocument の子ノードには親要素がないため、このプロパティは親要素の null を返します。

適用対象

こちらもご覧ください