Each node has a parent that is specified by the Node.ParentNode property. A node does not have a parent node (ParentNode is null) when a node has just been created and not yet added to the tree, or if it has been removed from the tree. You can remove a node from its parent by calling Node.Remove.
The parent node of the root Document node is always null.
Example AccessParentNode
Shows how to access the parent node.
[C#]
// Create a new empty document. It has one section.
Document doc = new Document();
// The section is the first child node of the document.
Node section = doc.FirstChild;
// The section's parent node is the document.
Assert.AreEqual(doc, section.ParentNode);
[Visual Basic]
' Create a new empty document. It has one section.
Dim doc As Document = New Document()
' The section is the first child node of the document.
Dim section As Node = doc.FirstChild
' The section's parent node is the document.
Assert.AreEqual(doc, section.ParentNode)
[Java]
// Create a new empty document. It has one section.
Document doc = new Document();
// The section is the first child node of the document.
Node section = doc.getFirstChild();
// The section's parent node is the document.
Assert.assertEquals(doc, section.getParentNode());