xpathCheck 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