1
jOOX可以用來發現使用這樣的元素的XPATH:我可以使用jOOX來查找屬性的xPath嗎?
Element element = (Element) someNode;
String xPath = $(element).xpath();
我可以做同樣的屬性?我試過這個:
Attr attr = (Attr) someAttributeNode;
String xPath = $(attr).xpath();
但它返回null。
編輯:我已經成功從節點的XPath和屬性的名稱創建我自己的XPath來解決它,但它好像我不應該這樣做。下面是完整的解決方法:
Element element = (Element) someNode;
String elementXpath = $(element).xpath();
String attributeName = someAttributeNode.getNodeName();
String attributeXpath = elementXpath + "/@" + attributeName; // <-- work around
創建自己的xpath更好,也是優化的 – chaosguru