XPath 递归
我的 xml 文件的一部分:
<table>
<row id="aant">
<radio id="radaant">
<omschrijving>test radio</omschrijving>
<omschrijving>part 2</omschrijving>
<table>
<row id="testrow">
<radio id="testrad">
<omschrijving>test radio deeper</omschrijving>
<table/>
</radio>
</row>
</table>
</radio>
</row>
</table>
我想从 id="radaant" 的标签收音机下获取“omschrijving”。由于“omschrijving”在孩子身上也更深,所以我总是得到“测试radiopart 2测试无线电更深”作为结果,但我只想“测试radiopart 2”。
我目前正在使用 xpath: expr = xpath.compile("/table/row[@id='aant']/radio[@id='radaant']/omschrijving")
如何更改我的 xpath 字符串以仅获取当前的“omschrijving”节点?
A part of my xml-file:
<table>
<row id="aant">
<radio id="radaant">
<omschrijving>test radio</omschrijving>
<omschrijving>part 2</omschrijving>
<table>
<row id="testrow">
<radio id="testrad">
<omschrijving>test radio deeper</omschrijving>
<table/>
</radio>
</row>
</table>
</radio>
</row>
</table>
I would like to get the "omschrijving" from under the tag radio with id="radaant". Since "omschrijving" is also deeper in the child i always get "test radiopart 2test radio deeper" as result, but I just want "test radiopart 2".
I'm currently using xpath:
expr = xpath.compile("/table/row[@id='aant']/radio[@id='radaant']/omschrijving")
How can I change my xpath string to get only the "omschrijving" from the current node?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您显然正在谈论另一个 XML 文档或另一个 XPath 表达式。
应用于提供的 XML 文档时:
您的 XPath 表达式:
准确选择所需的节点:
You obviously are talking about another XML document or another XPath expression.
When applied on the provided XML document:
your XPath expression:
selects exactly the wanted nodes:
尝试 expr = xpath.compile("/table/row[@id='aant']/radio[@id='radaant']/child::omschrijving")
try expr = xpath.compile("/table/row[@id='aant']/radio[@id='radaant']/child::omschrijving")