Java examples for XML:DOM Node
finding the location of the current XML node of its kind.
//package com.java2s; import org.w3c.dom.Node; public class Main { /**/*from w w w . j a va 2s .c om*/ * aims at finding the location of the current node of its kind. * the idea is to count how many previous siblings does it have, * @param aNode * @return */ public static int getLocHomoSibling(Node aNode) { int countOfBranch = 0; Node preSibling = aNode; while ((preSibling = preSibling.getPreviousSibling()) != null) { if (preSibling.getNodeName().equals(aNode.getNodeName())) { countOfBranch++; } } return countOfBranch; } }