您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

XPath-如何获取具有相同名称的多个标签的列表

XPath-如何获取具有相同名称的多个标签的列表

这是一个使用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);
}
其他 2022/1/1 18:16:20 有349人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶