Java tutorial
//package com.java2s; import org.w3c.dom.*; public class Main { public static int getElementIndex(Node node) { String s = node.getNodeName(); int i = 0; for (Node node1 = node.getPreviousSibling(); node1 != null; node1 = node1.getPreviousSibling()) if (node1.getNodeName().equals(s) && node1.getNodeType() == 1) i++; return i; } }