如何获取整个 XML 文档中具有特定名称的第 n 个元素? [英] How do I get the nth element with a certain name in the entire XML document?
本文介绍了如何获取整个 XML 文档中具有特定名称的第 n 个元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 Hpple Xpath 这样的东西也会工作
so will something like this work using Hpple Xpath
//a[4]
html 树中的第四个标签?或者我是否需要通过在 for() 循环中计数来以编程方式完成?
The fourth tag in a html tree? Or do i need to do it programmatically by counting in a for() loop?
推荐答案
The XPath for the fourth <a>
in an HTML document is:
(//a)[4]
您的示例 //a[4]
将生成一组所有 ,它们是第四个
> 在他们各自的父级中,这不是您想要的.
Your example //a[4]
will produce a set of all <a>
s that are the fourth <a>
in their respective parent, and that is not what you want here.
另见:https://stackoverflow.com/a/14209492/1945651
这篇关于如何获取整个 XML 文档中具有特定名称的第 n 个元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文