是否有XPATH返回所有非null someChild
加上未找到值的默认值?
<someFather>
<someChild/>
<someChild/>
<someChild>some value</someChild>
<someChild/>
<someChild>some other value</someChild>
<someChild/>
</someFather>
我想得到:
""
""
some value
""
some other value
""
, 要么
"not-found"
"not-found"
some value
"not-found"
some other value
"not-found"
请尝试以下表达式:
/someFather/(someChild/string(), '')
/someFather/someChild/(text()/string(), "not-found")[1]
这是经过仔细编写的,以避免违反“/”的RHS不能选择节点和原子值的混合的规则。在3.0中你可以使用“!”运营商:
/someFather/someChild ! (text(), "not-found")[1]