![]() |
The Java Developers Almanac 1.4 |
|
e527. Getting a Node Relative to Another Node in a DOM DocumentThis 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();
e528. Getting the Notations in a DOM Document e529. Getting the Declared Entities in a DOM Document e530. Getting the Value of an Entity Reference in a DOM Document
© 2002 Addison-Wesley. |