How to find if a node does not exist ? i am using
if ( $item->branch()->siblings($tagNames['desc'])->text())
is there a better way ?
- is there a way to execute an OR query? if tag A exists get its text(), otherwise get B's text() ?
I am using the following :
$desc1 = ( $item->branch()->siblings($tagNames['desc'])->text() ?
$item->branch()->siblings($tagNames['desc']) :
$item->branch()->siblings($tagNames['descAlternative']) ) ;
which doesn't look like the most efficient way of doing things.
Thanks
Regarding the first:
When QueryPath does not find a matching, it's size is 0. So you can do:
So for the second example, you could do:
But there's another way: You can also pass two selectors in at once.
This will select both. However,
text()
will only return the text of the first matched item. So it has the effect of doing an OR.