code: public static int getXPathLocation(String dom, String xpath) {
  		String dom_lower = dom.toLowerCase();
  		String xpath_lower = xpath.toLowerCase();
  		String[] elements = xpath_lower.split("/");
  		int pos = 0;
  		int temp;
  		int number;
  		for (String element : elements) {
  			if (!element.isEmpty() && !element.startsWith("@") && !element.contains("()")) {
  				if (element.contains("[")) {
  					try {
  						number =
  								Integer.parseInt(element.substring(element.indexOf("[") + 1,
  										element.indexOf("]")));
  					} catch (NumberFormatException e) {
  						return -1;
  					}
  				} else {
  					number = 1;
  				}
  				for (int i = 0; i < number; i++) {
  					// find new open element
  					temp = dom_lower.indexOf("<" + stripEndSquareBrackets(element), pos);
  
  					if (temp > -1) {
  						pos = temp + 1;
  
  						// if depth>1 then goto end of current element
  						if (number > 1 && i < number - 1) {
  							pos =
  									getCloseElementLocation(dom_lower, pos,
  											stripEndSquareBrackets(element));
  						}
  
  					}
  				}
  			}
  		}
  		return pos - 1;
  	}
docs: returns position of xpath element which match the expression xpath in the String dom.
  
  @param dom   the Document to search in
  @param xpath the xpath query
  @return position of xpath element, if fails returns -1