Here you can find the source of countPrecedingSiblingsOfType(Element inElem)
Parameter | Description |
---|---|
inElem | a parameter |
private static int countPrecedingSiblingsOfType(Element inElem)
//package com.java2s; //License from project: Common Public License import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { /**//from w ww .j av a 2 s. co m * @param inElem * @return */ private static int countPrecedingSiblingsOfType(Element inElem) { int cnt = 1; // Elements are 1-indexed in XPath Node node = inElem.getPreviousSibling(); String typeName = inElem.getNodeName(); while (node != null) { while (node.getNodeType() != Node.ELEMENT_NODE) { node = node.getPreviousSibling(); if (node == null) { break; } } if (node != null) { if (((Element) node).getNodeName().equals(typeName)) { cnt++; } node = node.getPreviousSibling(); } } return cnt; } }