Java tutorial
//package com.java2s; import org.w3c.dom.Document; import org.w3c.dom.Node; public class Main { public static String getPath(Node node) { String path = ""; Node current = node; while ((current != null) && !(current instanceof Document)) { path = current.getNodeName() + "/" + path; current = current.getParentNode(); } if (path != null) { path = path.substring(0, path.lastIndexOf("/")); } return path; } }