62,614
社区成员
发帖
与我相关
我的任务
分享
<items id="0">
<item id="1" text="a">
<item id="1_1" text="aa">
<item id="1_1_1" text="aaa"/>
</item>
</items>
StringReader reader = new StringReader("<items id=\"0\"><item id=\"1\" text=\"a\"/><item id=\"1_1\" text=\"aa\"><item id=\"1_1_1\" text=\"aaa\"/></item></items>");
InputSource input = new InputSource(reader);
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
NodeList list = (NodeList)xpath.evaluate("//item[@id=\"1\"]/@text",input,XPathConstants.NODESET);
for(int i=0; i <list.getLength(); i++){
System.out.println(list.item(i).getNodeValue());
}