Check For Empty Nodeset

Hi all,

I'm running a query in a policy and need to check if anything was found. At the moment I check:

XPath(count($resultNodeset) > 0

Is there a better way? Does a DirXML nodeset have something like JS .length that I can check?

  • Verified Answer

    +1  

    Hi,

    A nodeset does not have something like len() or .length, then again count() > 0 also works just fine.

    You can also check if the result of an xpath expression is empty.

    There are probably more ways to do this.

  • 0

    In a query-response you can simply look for the existence of an <instance>-element with a src-dn attribute.

    As for nodesets in general, it really depends on what you mean by "empty". A Node with nothing in it (i.e. its value is the empty string) is still included by count(). If you count that as being empty you'd have to filter out those nodes first: count($nodeset[string-length(.) != 0]), otherwise count() should be sufficient.