Java Utililty Methods XML Node Path

List of utility methods to do XML Node Path

Description

The list of methods to do XML Node Path are organized into topic(s).

Method

VectorgetVectorPathFromNode(Node node)
get Vector Path From Node
Vector path = new Vector();
while (node != null) {
    path.insertElementAt(node, 0);
    node = node.getParentNode();
return path;
StringpathTo(Node xmlNode)
path To
StringBuilder result = new StringBuilder();
for (Node node = xmlNode; node != null; node = node.getParentNode()) {
    if (node.getNodeType() == Node.DOCUMENT_NODE)
        result.insert(0, node.getNodeName());
    else
        result.insert(0, " -> " + node.getNodeName());
return result.toString();
...
StringpathUp(Node node, int level)
calculates the path of the node up in the hierarchy, example of result is project/build/plugins/plugin level parameter designates the number of parents to climb eg.
StringBuffer buf = new StringBuffer();
int current = level;
while ((node != null) && (current > 0)) {
    if (node instanceof Element) {
        if (buf.length() > 0) {
            buf.insert(0, "/");
        buf.insert(0, node.getNodeName());
...
StringpathUp(Node node, int level)
path Up
StringBuffer buf = new StringBuffer();
int current = level;
while (node != null && current > 0) {
    if (node instanceof Element) {
        if (buf.length() > 0) {
            buf.insert(0, "/");
        buf.insert(0, node.getNodeName());
...