How to check a node contains empty string or space or null in xpath?

冷暖自知 提交于 2021-01-27 06:44:55

问题


I want to check using xpath an node in the xml contains empty string/spaces. What is the xpath expression i need to use?

eg:

 <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>

How to check the Name node is empty or containing space values?


回答1:


By checking if a node is empty I guess you mean has no child element (text or node).

Checking if a node contains only space values can be done using normalize-space() function.

I suggest you use this condition: not(./*) and normalize-space(.)="", i.e.

  • does not have child nodes
  • and if it has child text element, the whitespace normalized string representation of the node is an empty string



回答2:


For both mentioned type.

<Employee/>
<Employee></Employee>

Below code will work

string(your_node_xpath) != ''


来源:https://stackoverflow.com/questions/23824068/how-to-check-a-node-contains-empty-string-or-space-or-null-in-xpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!