xpath

Check if a node's text is empty

Syntax#

  • boolean(path_to_node/text())
  • string(path_to_node) != ”

Remarks#

Boolean function has other uses

  1. Check if a node is present
  2. Check if the argument is not a number (NaN) or is 0

String function is used to return the string value of a node.

Check if Deborah has a master and its text value is not empty

XML

<Deborah>
    <address>Dark world</address>
    <master>Babadi</master>
    <ID>#0</ID>
    <colour>red</colour>
    <side>evil</side>
</Deborah>

XPATH

boolean(/Deborah/master/text())

OR

string(/Deborah/master) != ''

OUTPUT

true

Check if Dobby has a master and its text value is not empty

XML

<Dobby>
    <address>Hogwartz</address>
    <master></master>
    <colour>wheatish</colour>
    <side>all good</side>
</Dobby>

XPATH

boolean(/Dobby/master/text())

OR

string(/Dobby/master) != ''

OUTPUT

false

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow