//For compliance with legacy behavior where selecting an empty node returns true,
//selectNodeIterator is attempted in case of a failure.
CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
XObject result = cachedXPathAPI.eval(doc, xpath);
if (result.bool())
return true;
else {
NodeIterator iterator = cachedXPathAPI.selectNodeIterator(doc, xpath);
return (iterator.nextNode() != null);
}