Getting a Node Relative to Another Node in a DOM Document
This example demonstrates the various methods for using a node to
retrieve related nodes --- parent, child, etc.
// Get the parent
Node parent = node.getParentNode();
// Get children
NodeList children = node.getChildNodes();
// Get first child; null if no children
Node child = node.getFirstChild();
// Get last child; null if no children
child = node.getLastChild();
// Get next sibling; null if node is last child
Node sibling = node.getNextSibling();
// Get previous sibling; null if node is first child
sibling = node.getPreviousSibling();
// Get first sibling
sibling = node.getParentNode().getFirstChild();
// Get last sibling
sibling = node.getParentNode().getLastChild();
Post a comment