如何检查节点在xpath中包含空字符串或空格或空值? [英] How to check a node contains empty string or space or null in xpath?
本文介绍了如何检查节点在xpath中包含空字符串或空格或空值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 xpath 检查 xml 中的一个节点是否包含空字符串/空格.我需要使用什么 xpath 表达式?
I want to check using xpath an node in the xml contains empty string/spaces. What is the xpath expression i need to use?
例如:
<p:insert_acc_data_file xmlns:p="http://ws.wso2.org/dataservice">
<p:Id>123</p:Id>
<p:Name></p:pName>
</p:insert_acc_data_file>
如何检查Name节点是否为空或包含空格值?
How to check the Name node is empty or containing space values?
推荐答案
通过检查节点是否为空 我猜你的意思是没有子元素(文本或节点).
By checking if a node is empty I guess you mean has no child element (text or node).
可以使用 normalize-space()
函数检查节点是否仅包含空间值.
Checking if a node contains only space values can be done using normalize-space()
function.
我建议你使用这个条件:not(./*) and normalize-space(.)=""
,即
I suggest you use this condition: not(./*) and normalize-space(.)=""
, i.e.
- 没有子节点
- 如果它有子文本元素,则节点的空白规范化字符串表示为空字符串
这篇关于如何检查节点在xpath中包含空字符串或空格或空值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文