manjosh
manjosh

Reputation: 734

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

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

But it is not fetching anything

Upvotes: 1

Views: 167

Answers (1)

kjhughes
kjhughes

Reputation: 111686

Problem: There is no text node child of the address element.

Solution: Test the string value of the address element rather than its (non-existent) text node child...

This 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'.

See also

Upvotes: 1

Related Questions