开发者

XOM getting attribute from Node?

开发者 https://www.devze.com 2022-12-22 03:10 出处:网络
Shouldn\'t something like this work? Assuming a docu开发者_JS百科ment formatted as such: <root>

Shouldn't something like this work?

Assuming a docu开发者_JS百科ment formatted as such:

<root>
   <element id = "a"></element>
</root>

Node node = doc.query("/root/element").get(0);
String id = node.getDocument().getRootElement().getAttribute("id");

When I print the value of the root element, it looks as if this should work. What's failing, here?


Cast your node to an Element, and you're good to go.


node.getDocument().getRootElement() at this point you have the element which does not have an attribute "id".

Try node.getAttribute("id") instead ? (assuming node is not null)

0

精彩评论

暂无评论...
验证码 换一张
取 消