是否存在XPATH返回所有非空someChild
以及在找不到on值时的默认值?
<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"
答案 0 :(得分:3)
/someFather/someChild/(text()/string(), "not-found")[1]
为避免违反“ /”的RHS无法选择节点和原子值的混合的规则,请仔细编写此代码。在3.0中,您可以使用“!”运算符:
/someFather/someChild ! (text(), "not-found")[1]
答案 1 :(得分:2)
尝试以下表达式:
/someFather/(someChild/string(), '')