【问题标题】:How to select a node which has an empty element in xml如何在xml中选择具有空元素的节点
【发布时间】:2020-06-18 04:08:56
【问题描述】:

我正在寻找一个具有空元素的节点。

下面是我的xml

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

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

但它没有获取任何东西

【问题讨论】:

    标签: java xml xpath


    【解决方案1】:

    问题:address 元素没有文本节点子节点。

    解决方案:测试address元素的字符串值,而不是其(不存在的)文本节点子节点...

    这个 XPath,

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

    将选择那些address 字符串值为空字符串且LVN 元素的字符串值为test'contact 元素。

    另请参阅

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多