使用 XPATH 获取非空元素 [英] Get the non-empty element using XPATH
本文介绍了使用 XPATH 获取非空元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下 XML
<?xml version = "1.0" encoding = "UTF-8"?>
<root>
<group>
<p1></p1>
</group>
<group>
<p1>value1</p1>
</group>
<group>
<p1></p1>
</group>
</root>
是否有可能获得最后一个有值的节点?在这种情况下,获取第二组/p1 的值.
is it possible to get the last the node with value? in this case get the value of the second group/p1.
推荐答案
/root/group/p1[text() 而 not(../following-sibling::group/p1/text())]
换句话说:获取具有文本且其父组后面没有包含非空 p1 元素的组节点的 p1 元素.
In other words: get the p1 elements that have text and whose group parents are not followed by group nodes that have non-empty p1 elements.
这篇关于使用 XPATH 获取非空元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文