这是一个使用
XPathJDK执行查询的示例。它假定变量
xml包含您的XML文档。
XPathFactory factory = XPathFactory.newInstance();XPath xPath = factory.newXPath();NodeList nodeList = (NodeList) xPath.evaluate("//shoes/additional", new InputSource(new StringReader(xml)), XPathConstants.NODESET);for (int i = 0; i < nodeList.getLength(); ++i) { String name = nodeList.item(i).getAttributes().getNamedItem("name").getNodevalue(); String text = nodeList.item(i).getTextContent(); System.out.println(name + ", " + text);}


