vtd-xml 我需要做什么去任何元素
我想使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能要求 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.)...