简体   繁体   English

如何 select 在 xml 中有一个空元素的节点

[英]How to select a node which has an empty element in xml

I am looking to fetch a node which has an empty element.我正在寻找一个具有空元素的节点。

below is my xml下面是我的 xml

<sys>
   <platform>
      <contact>
        <name>company</name>
        <LVN>test</LVN>
        <address></address>
        <phone>12345</phone>
        <pager/>
    </contact>
  </platform>
</sys>

I am using the below query /sys/platform/contact[./address/text()='' and./LVN/text()='test']我正在使用以下查询 /sys/platform/contact[./address/text()='' and./LVN/text()='test']

But it is not fetching anything但它没有获取任何东西

Problem: There is no text node child of the address element.问题: address元素没有文本节点子节点。

Solution: Test the string value of the address element rather than its (non-existent) text node child...解决方案:测试address元素的字符串值,而不是其(不存在的)文本节点子...

This XPath,此 XPath,

/sys/platform/contact[address='' and LVN='test']

will select those contact elements whose address string value is an empty string and whose LVN element has a string value of test' .将 select address字符串值为空字符串且LVN元素的字符串值为test'那些contact元素。

See also也可以看看

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM