M
Moiristo
I am trying to evaluate an XML document using the javax.xml libraries,
but I guess I'm doing something wrong. I need to get all 'layer'
attributes from the document. To do this, I did this:
NodeList layers = (NodeList) path.evaluate("/root//layer",
<xml inputsource>, XPathConstants.NODESET);
Then, I need to use the elements within that layer. The code I use is:
for(int i = 0;i<layers.getLength();i++){
Node layer = layers.item(i);
lname = layer.getNextSibling().getNodeValue().trim();
lsource = layer.getNextSibling().getNodeValue().trim();
ldest = layer.getNextSibling().getNodeValue().trim();
}
It finds the layers within the document, but when I store the element
values in the for-loop, it stores empty strings (when I call
getNodeName(), it returns "#text"). Do I need to evaluate the expression
differently, because it seems like the elements within the layers aren't
evaluated.
As an example, a layer node:
<layer>
<name>
Name
</name>
<sourceTable>
Source
</sourceTable>
<destColumn>
gcolName
</destColumn>
</layer>
TIA.
but I guess I'm doing something wrong. I need to get all 'layer'
attributes from the document. To do this, I did this:
NodeList layers = (NodeList) path.evaluate("/root//layer",
<xml inputsource>, XPathConstants.NODESET);
Then, I need to use the elements within that layer. The code I use is:
for(int i = 0;i<layers.getLength();i++){
Node layer = layers.item(i);
lname = layer.getNextSibling().getNodeValue().trim();
lsource = layer.getNextSibling().getNodeValue().trim();
ldest = layer.getNextSibling().getNodeValue().trim();
}
It finds the layers within the document, but when I store the element
values in the for-loop, it stores empty strings (when I call
getNodeName(), it returns "#text"). Do I need to evaluate the expression
differently, because it seems like the elements within the layers aren't
evaluated.
As an example, a layer node:
<layer>
<name>
Name
</name>
<sourceTable>
Source
</sourceTable>
<destColumn>
gcolName
</destColumn>
</layer>
TIA.