vtd-xml 我需要做什么去任何元素

发布于 2024-11-14 07:53:58 字数 519 浏览 6 评论 0原文

我想使用 vtd-xml 导航 xml,并且想导航到 XPath 给出的任何索引。例如:

vg.parseFile("/tmp/somexml.xml",true);
VTDNav vn = vg.getNav();                
AutoPilot ap = new AutoPilot();
ap.selectXPath("//someelement");                
ap.bind(vn);
for (int i = ap.evalXPath(); i != -1;) {
try {                        
vn.toElement(i);                                               
} catch (Exception ex) {
logger.error(null, ex);
}

我进行了调试,例如我得到了索引 40,但是当我尝试 toElement(40) 时它失败了。我一直收到无效的导航。无论如何我可以导航到任何元素吗?

I want to navigate the xml using vtd-xml, and I want to navigate to any index given by the XPath. For example:

vg.parseFile("/tmp/somexml.xml",true);
VTDNav vn = vg.getNav();                
AutoPilot ap = new AutoPilot();
ap.selectXPath("//someelement");                
ap.bind(vn);
for (int i = ap.evalXPath(); i != -1;) {
try {                        
vn.toElement(i);                                               
} catch (Exception ex) {
logger.error(null, ex);
}

I debugged and for example I get the index 40, but when I try toElement(40) it fails. I keep getting invalid navigation. Is there anyway I can navigate to any element?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

网名女生简单气质 2024-11-21 07:53:58

您不能要求 vtdNav 转到任何索引值,VTD-XML 不会那样工作,原因很简单,索引不能保证是元素的类型。

有多种方法可以保存/加载节点位置,或从索引值恢复节点位置。但一般来说,节点位置不能保证是有效的树位置(例如属性值)......

You can't ask vtdNav to go to any index value, VTD-XML doesn't work like that for the simple reason that the index is not guaranteed to be of the type of element.

There are ways for you to save/load a node position, or recover a node position from an index value. But in general a node position is not guaranteed to be a valid tree position (attribute value e.g.)...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文