Here you can find the source of getXPath(Node node)
public static String getXPath(Node node)
//package com.java2s; //License from project: Apache License import org.w3c.dom.Node; public class Main { public static String getXPath(Node node) { Node parent = node.getParentNode(); if (parent == null) { return ""; }// ww w. j av a 2s. co m return getXPath(parent) + "/" + node.getLocalName(); } }