且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 XPATH java 提取 XML 嵌套内容

更新时间:2023-11-24 23:33:40

在 XPath 中 // 可以匹配任意数量的子路径,因此它也可以在构建部分中找到依赖项.如果我改变你的代码说

In XPath // can match any number of subpaths, so it finds dependencies inside the build section too. If I change your code to say

 String xpathStr = "/project/dependencies";

我得到了你想要的输出.一个斜杠是精确匹配 XML 中的一级,因此我们从根获取项目,然后直接在项目下获取依赖项.

I get the output you wanted. One slash is to match exactly one level in the XML, so we get project from the root, then dependencies straight under project.