Here you can find the source of getNodePath(Node node)
public static String[] getNodePath(Node node)
//package com.java2s; //License from project: LGPL import java.util.Deque; import java.util.LinkedList; import org.w3c.dom.Node; public class Main { public static String[] getNodePath(Node node) { Deque<String> list = new LinkedList<String>(); list.addFirst(node.getNodeName()); node = node.getParentNode();// w w w .j a v a 2s . co m while (node != null) { list.addFirst(node.getNodeName()); node = node.getParentNode(); } return list.toArray(new String[0]); } }