Exists (XmlDoc/XmlNode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Created page with "<span style="font-size:120%; color:black"><b>Is XPath result non-empty?</b></span> Exists function Exists function [[Cate...")
 
m (1 revision)
(No difference)

Revision as of 00:33, 7 December 2010

Is XPath result non-empty?

Exists is a member of the XmlDoc and XmlNode classes.

Available as of Sirius Mods version 6.6, this function returns a Boolean enumeration (??Using Boolean enumerations) whose value is True if the XPath result is non-empty, and False otherwise.

Syntax

  %bool = nr:Exists(XPath)

Syntax Terms

%bool
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. 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 (??SelectCount) has the relative disadvantage that it may continue to examine the XmlDoc tree after the first matching node is found. SelectSingleNode (??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.

Example

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

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

See Also

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