Xpath to check for multiple empty children

With the following xml, I am trying to return true

or false

depending on whether all elements are empty <CrucialNumber>

:

<Invoice>
  <Details>
    <LIN1>
      <Quantity>1</Quantity>
      <Product>Test XML</Product>
      <CrucialNumber/>
    </LIN1>
    <LIN1>
      <Quantity>1</Quantity>
      <Product>Test XML</Product>
      <CrucialNumber/>
    </LIN1>
    <LIN1>
      <Quantity>1</Quantity>
      <Product>Test XML</Product>
      <CrucialNumber>123456</CrucialNumber>
    </LIN1>
  </Details>
</Invoice>

      

The item data type CrucialNumber

is string

.

So far, these are the xpath expressions I've tried:

string-length(//CrucialNumber/*) > 0;    

not(//CrucialNumber/*[text()]);

./Details/LIN1[*]/CrucialNumber[1] = "";

      

+3


source to share


1 answer


not(.//CrucialNumber/node())

      



should do this, it will be true if and only if either (a) there are no descendant elements CrucialNumber

at all, or (b) all descendant elements CrucialNumber

are empty.

+2


source







All Articles