XObject.Parent 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
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
屬性值
範例
以下範例使用了此方法。
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 。