<a>
<b>123213</b>
<c>
<c1>a</c1>
<c2>b</c2>
</c>
<d>123123</d>
</a>
I'm currently trying to parse nodes in an xml file using Java's xpath (javax.xml.xpath.XPath)
Can't I get a node or a nodelist so that I can tour b,c,d in the lower part of a node?
xml
XPath xpath = XPathFactory.newInstance().newXPath();
NodeList nl = (NodeList)xpath.evaluate("//a/*", document, XPathConstant.NODESET);
for(int i=0;i<nl.getLength();i++) {
Element e = (Element)nl.getItem(i);
}
I think we can do it the same way as above.
In the case of XPathConstant.NODESET, you can convert the return type to NodeList and use it.
The above //a/*
Xpath expression means subnode
of all a.
© 2024 OneMinuteCode. All rights reserved.