VTD-XML 是否允许复杂的 xpath 表达式?
Does VTD-XML allow complex xpath expressions?
我一直在使用 VTD-XML 到 运行 xpath 表达式,但我发现任何 XPath 表达式都比使用文件类型地址(即 //Books/authors)更复杂分解并简单地求助于 returning 整个文件。
我有两个示例,一个使用 concat() 方法,另一个使用 contains() 方法。
我的test.xml文档:
<a>
<b>The</b>
<c>fox</c>
<d>
<e>jumps</e>
</d>
</a>
第一期
我在 运行 进行这样的连接时遇到问题:
concat(//b, ' ', //c, ' ', '- Found: ', \"'\", //d/e, \"'\")
这应该return:
The fox - Found: 'jumps'
而是 returns:
Thefoxjumps Thefoxjumps - Found: 'Thefoxjumps'
VTD 用于第一期
File f = new File("C:/Users/../test.xml");
FileInputStream fis = new FileInputStream(f);
byte[] b = new byte[(int) f.length()];
fis.read(b);
VTDGen vg = new VTDGen();
vg.setDoc(b);
vg.parse(true);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("concat(//b, ' ', //c, ' ', '- Found: ', \"'\", //d/e, \"'\")");
System.out.println(ap.evalXPathToString());
第二期
当我 运行 a 包含这样一个:
//a[contains('|jumps|runs|', d/e)]
这应该 return "a" 标签,因为 "e" 标签包含 'jumps'。但是这 return 什么都不是。
第二期使用的VTD代码
File f = new File("C:/Users/../test.xml");
FileInputStream fis = new FileInputStream(f);
byte[] b = new byte[(int) f.length()];
fis.read(b);
VTDGen vg = new VTDGen();
vg.setDoc(b);
vg.parse(true);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
int r;
while((r = ap.evalXPath()) != -1){
System.out.println("Tag: "+vn.toString(r));
}
对于第一个问题,我运行查询最新版本...它returns
The fox - Found: 'jumps'
不幸的是,这似乎是 2.12 中引入的错误,已报告并已修复...注意它应该在 2.10 或 2.11 中正常工作
转到http://vtd-xml.cvs.sourceforge.net/viewvc/vtd-xml/ximple-dev/com/ximpleware/LocationPathExpr.java?revision=1.64并下载文件和
使用与发行版捆绑在一起的 build.bat 脚本自己构建一个 jar...
我还 运行 对最新版本(定于 2.13)进行的第二次测试工作正常并且 returns 单个节点...
它们似乎与同一个错误有关...
我一直在使用 VTD-XML 到 运行 xpath 表达式,但我发现任何 XPath 表达式都比使用文件类型地址(即 //Books/authors)更复杂分解并简单地求助于 returning 整个文件。
我有两个示例,一个使用 concat() 方法,另一个使用 contains() 方法。
我的test.xml文档:
<a>
<b>The</b>
<c>fox</c>
<d>
<e>jumps</e>
</d>
</a>
第一期
我在 运行 进行这样的连接时遇到问题:
concat(//b, ' ', //c, ' ', '- Found: ', \"'\", //d/e, \"'\")
这应该return:
The fox - Found: 'jumps'
而是 returns:
Thefoxjumps Thefoxjumps - Found: 'Thefoxjumps'
VTD 用于第一期
File f = new File("C:/Users/../test.xml");
FileInputStream fis = new FileInputStream(f);
byte[] b = new byte[(int) f.length()];
fis.read(b);
VTDGen vg = new VTDGen();
vg.setDoc(b);
vg.parse(true);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("concat(//b, ' ', //c, ' ', '- Found: ', \"'\", //d/e, \"'\")");
System.out.println(ap.evalXPathToString());
第二期
当我 运行 a 包含这样一个:
//a[contains('|jumps|runs|', d/e)]
这应该 return "a" 标签,因为 "e" 标签包含 'jumps'。但是这 return 什么都不是。
第二期使用的VTD代码
File f = new File("C:/Users/../test.xml");
FileInputStream fis = new FileInputStream(f);
byte[] b = new byte[(int) f.length()];
fis.read(b);
VTDGen vg = new VTDGen();
vg.setDoc(b);
vg.parse(true);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
int r;
while((r = ap.evalXPath()) != -1){
System.out.println("Tag: "+vn.toString(r));
}
对于第一个问题,我运行查询最新版本...它returns
The fox - Found: 'jumps'
不幸的是,这似乎是 2.12 中引入的错误,已报告并已修复...注意它应该在 2.10 或 2.11 中正常工作
转到http://vtd-xml.cvs.sourceforge.net/viewvc/vtd-xml/ximple-dev/com/ximpleware/LocationPathExpr.java?revision=1.64并下载文件和 使用与发行版捆绑在一起的 build.bat 脚本自己构建一个 jar...
我还 运行 对最新版本(定于 2.13)进行的第二次测试工作正常并且 returns 单个节点...
它们似乎与同一个错误有关...