Here you can find the source of getNodePath(Node node)
public static final String getNodePath(Node node)
//package com.java2s; //License from project: Open Source License import java.util.Stack; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { public static final String getNodePath(Node node) { StringBuilder buffer = new StringBuilder("/"); Stack<String> stack = new Stack<String>(); Node n = node;//from ww w. j a va2 s .c o m while (n != null) { String nname = n.getNodeName(); NamedNodeMap attrs = n.getAttributes(); if (attrs != null && attrs.getLength() != 0) { Node attr = attrs.getNamedItem("xconf-uid"); if (attr != null) { nname += "[@xconf-uid=\"" + attr.getNodeValue() + "\"]"; } } stack.push(nname); n = n.getParentNode(); } if (stack.size() >= 3) { stack.pop(); stack.pop(); } else { return null; } while (!stack.empty()) { buffer.append("/"); buffer.append(stack.pop()); } return buffer.toString(); } }