javaxmlxml-attributejoox

Can I use jOOX to find the xPath of an attribute?


jOOX can be used to find the xPath of an element using something like this:

Element element = (Element) someNode;
String xPath = $(element).xpath();  

Can I do the same for an attribute? I tried this:

Attr attr = (Attr) someAttributeNode;
String xPath = $(attr).xpath();   

But it returns null.

Edit: I've managed to work around it by creating my own xPath from the node's xPath and the attribute's name, but it seems like I shouldn't have to do this. Here's the complete work around:

Element element = (Element) someNode;
String elementXpath = $(element).xpath();
String attributeName = someAttributeNode.getNodeName();
String attributeXpath = elementXpath + "/@" + attributeName;  // <-- work around

Solution

  • Until someone gives me a better answer, I'll use my own work around:

    I've managed to work around it by creating my own xPath from the node's xPath and the attribute's name, but it seems like I shouldn't have to do this. Here's the complete work around:

    Element element = (Element) someNode;
    String elementXpath = $(element).xpath();
    String attributeName = someAttributeNode.getNodeName();
    String attributeXpath = elementXpath + "/@" + attributeName;  // <-- work around