>I am trying to evaluate an XML document using the javax.xml libraries,
You're actually evaluating an XPath on an XML document, not the XML
document itself.
> but I guess I'm doing something wrong. I need to get all 'layer'
> attributes from the document.
"layer" is an element, not an attribute.
> To do this, I did this:
>
[quoted text clipped - 28 lines]
> </destColumn>
> </layer>
layer.getNextSibling(), which you call 3 times, will always return the
same node, and I don't think it's the node you want anyway. See
http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/Node.html#getChildNodes()
- Oliver
Moiristo - 25 Sep 2006 17:26 GMT
> You're actually evaluating an XPath on an XML document, not the XML
> document itself.
> "layer" is an element, not an attribute.
You're right, sorry for my bad terminology :) I had a rough weekend..
> layer.getNextSibling(), which you call 3 times, will always return
> the same node, and I don't think it's the node you want anyway. See
> http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/Node.html#getChildNodes()
Hmm, RTFM you say? You're right, I thought the method just advanced to
the next node when I called it. Fixed it now :) thnx!
> NodeList layers = (NodeList) path.evaluate("/root//layer",
> <xml inputsource>, XPathConstants.NODESET);
[quoted text clipped - 4 lines]
> Node layer = layers.item(i);
> lname = layer.getNextSibling().getNodeValue().trim();
You can use e.g.
lname = layer.getElementsByTagName("name").item(0);
Or you can use XPath again e.g.
lname = (Node) path.evaluate("name", layer, XPathConstants.NODE);

Signature
Martin Honnen
http://JavaScript.FAQTs.com/