我有一个这样的xml,
<doc>
<p><c type="changeStart"/><style type="underline">text</style><c type="changeEnd"/><t/>In addition
to voting Finance Company and Business Company, Inc.: (i) the name
of the <c type="changeStart"/>new public entity<c type="changeEnd"/> will be “Finance Company.”
as Finance Company’s corporate existence is perpetual as opposed to Business Company, Inc.’s corprate
existence terminating <c type="changeStart"/> <c type="changeEnd"/>
</p>
</doc>
我需要选择 <c type="changeStart"/>
之间存在的节点和 <c type="changeEnd"/>
.所以在上面的xml中应该选择以下节点,
-
<style type="underline">text</style>
-
new public entity
- 两个空格(' ')
我为此编写了以下 xpath,
//*[preceding-sibling::c[@type = 'changeStart'] and following-sibling::c[@type = 'changeEnd']][not(c [@type="changeStart"])]
但它没有选择正确的节点。有什么建议可以修改我的 xpath 以选择我需要的内容吗?
最佳答案
这是一种可能的 XPath:
//node()[
preceding-sibling::*[1][self::c/@type='changeStart']
and
following-sibling::*[1][self::c/@type='changeEnd']
]
上面的 XPath 选择节点:
- 紧接
<c type="changeStart"/>
, 和.. - 紧跟
<c type="changeEnd"/>
关于xml - Xpath - 根据前 sibling 和后 sibling 选择节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40501661/