简体   繁体   English

我可以使用jOOX查找属性的xPath吗?

[英]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: jOOX可用于使用以下方式查找元素的xPath:

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. 但它返回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. 编辑 :我已经设法通过从节点的xPath和属性的名称创建自己的xPath来解决此问题,但是似乎我不必这样做。 Here's the complete work around: 这是完整的解决方法:

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

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. 我已经设法通过从节点的xPath和属性名称创建自己的xPath来解决此问题,但似乎我不必这样做。 Here's the complete work around: 这是完整的解决方法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM