简体   繁体   English

vtd-xml evalXPathToString奇怪的行为/无法正常工作

[英]vtd-xml evalXPathToString strange behavoir/not working

In the second example below, why does evalXPathToString print junk1.45 rather than just 1.45 ? 在下面的第二个例子中,为什么evalXPathToString打印junk1.45而不仅仅是1.45

I am using version 2.12 of vtd-xml. 我使用的是vtd-xml的2.12版本。

String xml = "<xmlDoc><noele>junk</noele><valss>1.45</valss></xmlDoc>";

VTDGen vtdGen = new VTDGen();
vtdGen.setDoc(xml.getBytes(StandardCharsets.UTF_8));
vtdGen.parse(true);
VTDNav vtdNav = vtdGen.getNav();

AutoPilot autoPilot = new AutoPilot(vtdNav);
autoPilot.selectXPath("/xmlDoc/valss");
System.out.println(autoPilot.evalXPathToNumber()); // prints 1.45

autoPilot = new AutoPilot(vtdNav);
autoPilot.selectXPath("/xmlDoc/valss");
System.out.println(autoPilot.evalXPathToString()); // prints junk1.45

I have tried this on the latest build... and both return 1.45... 我在最新版本上尝试了这个...并且都返回1.45 ...

This appears to be one of the bugs that has been introduced in 2.12 and subsequently reported and fixed. 这似乎是2.12中引入并随后报告和修复的错误之一。 The reason it is introduced is because 2.12 aims to fully support mix-content type of XPath evaluation... that is, if you eval xpath "/xmlDoc" to a string, it returns junk1.45.. 引入它的原因是因为2.12旨在完全支持混合内容类型的XPath评估...也就是说,如果你将xpath“/ xmlDoc”评估为一个字符串,它将返回junk1.45 ..

Also, this bug only concerns evalXPathToString...not other three evaluation methods... I believe /xmlDoc/valss/text() will be one workaround... 此外,这个bug只涉及evalXPathToString ...而不是其他三种评估方法...我相信/ xmlDoc / valss / text()将是一个解决方法...

If you don't want to wait for the formal release of 2.13 to amend this issue.. you can download the file and build a jar yourself with the following steps... 如果您不想等待正式发布的2.13来修改此问题..您可以下载该文件并使用以下步骤自行构建一个jar ...

  1. get the patch... go to vtd-xml's cvs host site... http://vtd-xml.cvs.sourceforge.net/viewvc/vtd-xml/ximple-dev/com/ximpleware/LocationPathExpr.java 得到补丁...转到vtd-xml的cvs主机站点... http://vtd-xml.cvs.sourceforge.net/viewvc/vtd-xml/ximple-dev/com/ximpleware/LocationPathExpr.java

  2. drop the file under com.ximpleware 将文件放在com.ximpleware下

  3. run the build.bat on windows... or whatever is equivalent on your unix machine 在Windows上运行build.bat ...或者在你的unix机器上运行相同的东西

  4. get the new jar file and replace the old 2.12 jar in the classpath... 获取新的jar文件并替换类路径中的旧2.12 jar ...

Let me know if it works for you or not... 让我知道它是否适合你...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM