Exists (XmlDoc/XmlNode function)

From m204wiki
Jump to navigation Jump to search

Is XPath result non-empty? (XmlDoc and XmlNode classes)

Exists returns a Boolean enumeration whose value is True if the XPath result is non-empty, and False otherwise.


%boolean = nr:Exists( xpath) Throws XPathError

Syntax terms

%boolean A declared enumeration object of type Boolean to contain the returned value of Exists.
nr An XmlDoc or XmlNode, used as the context node for the XPath expression, xpath. If an XmlDoc, the Root node is the context node.
xpath A Unicode string that is an XPath expression that results in a nodelist. The expression default is a period (.), that is, the node referenced by the method object (nr). Prior to Sirius Mods Version 7.6, this is an EBCDIC string.

Usage notes

  • If you are only checking for the existence of some nodes in the document, Exists is the most efficient method:
    • SelectCount has the relative disadvantage that it may continue to examine the XmlDoc tree after the first matching node is found.
    • SelectSingleNode has a similar disadvantage: it may visit nodes in an order other than the document order, and, since it guarantees to return the first node in XmlDoc order, it may continue even after the first match is found.


The following request tests two XPath results:

begin %d object xmlDoc %d = New print 'Root exist?' And %d:Exists('.'):ToString print 'Elem of empty doc exist?' And %d:Exists('*'):ToString end

The example results follow:

Root exist? True Elem of empty doc exist? False

Request-cancellation errors

This list is not exhaustive: it does not include all the errors that are request cancelling.

  • xpath is invalid.
  • Insufficient free space exists in CCATEMP.

See also

  • For more information about using XPath expressions, see XPath.