After translating the Javascript code to Java, I came across an issue within the sib; portion. More information can be found at:
I am unfamiliar with such for statements. What is the function of adding a semicolon? Does it behave like a while() statement?
public static String getElementXpath(DOMElement elt){
String path = "";
for (;elt.ELEMENT_NODE == elt.getNodeType(); elt = (DOMElement) elt.getParentNode()){
int idx = getElementIdx(elt);
}
return path;
}
private static int getElementIdx(DOMElement elt) {
int count = 1;
for (DOMElement sib = (DOMElement) elt.getPreviousSibling(); sib ; sib = (DOMElement) sib.getPreviousSibling())
{
if(sib.ELEMENT_NODE == sib.getNodeType() && sib.getTagName() == elt.getTagName()) count++;
}
return count;
}