Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我只想选择节点内的原子值。例如,下面的“here”文本:
<a href="">here</a>
当我在 Java 中使用 Xpath 时,它会返回某种对象/数组,例如
[DomNode[<a href="">here</a>]]
我只想要文字。
这可能吗,怎么做?谢谢!
您可以使用text()节点测试。例如,如果您想选择具有 href 属性的所有锚点的文本,您可以执行以下 XPath 查询:
text()
//*/a/@href/../text()
使用:
//a[@href='']/text()
这将选择作为文档中任何a元素的子元素的所有文本节点,该元素具有空href属性。
a
href