tags:

views:

32

answers:

2

Shouldn't something like this work?

Assuming a document 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?

A: 

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)

Calm Storm
http://www.xom.nu/apidocs/nu/xom/Node.html
Stefan Kendall
Can you try type casting Node to Element and also tell us what is failing. Also, any code pasted shown should not be considered compilable (and I hate downvoting because something does not compile). The idea is what should be looked at ?
Calm Storm
When I print the root element retrieved, it shows <element id = "blah">...</element>, so I'm confused as to why that doesn't work.
Stefan Kendall
A: 

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

Stefan Kendall
I dont get it. Isnt this what I already posted ? ["Can you try type casting Node to Element and also tell us what is failing."]
Calm Storm
Comments are not answers. If you wanted acceptance, you should have posted the answer, rather than comment.
Stefan Kendall