Exists (XmlDoc/XmlNode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 10: Line 10:
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%bool</th>
<tr><th>%bool</th>
<td>A declared enumeration object of type Boolean to contain the returned value of Exists. </td></tr>
<td>A declared enumeration object of type Boolean to contain the returned value of <var>Exists</var>. </td></tr>
<tr><th>nr</th>
<tr><th>nr</th>
<td>An XmlDoc or XmlNode, used as the context node for the <i>XPath</i> expression. If an XmlDoc, the Root node is the context node. </td></tr>
<td>An <var>XmlDoc</var> or <var>XmlNode</var>, used as the context node for the <i>XPath</i> expression. If an <var>XmlDoc</var>, the Root node is the context node. </td></tr>
<tr><th>XPath</th>
<tr><th>XPath</th>
<td>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 (<i>nr</i>).
<td>A <var>Unicode</var> 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 (<i>nr</i>).
<p class="code">Prior to ''Sirius Mods'' version 7.6, this is an EBCDIC string.</td></tr>
<p class="code">Prior to ''Sirius Mods'' version 7.6, this is an EBCDIC string.</td></tr>
</p>
</p>
Line 22: Line 22:
<ul>
<ul>
<li>If you are only checking for the existence of some nodes in the document,
<li>If you are only checking for the existence of some nodes in the document,
Exists is the most efficient method.
<var>Exists</var> is the most efficient method.
[[SelectCount (XmlDoc/XmlNode function)|SelectCount]] has the relative disadvantage that it may
[[SelectCount (XmlDoc/XmlNode function)|SelectCount]] has the relative disadvantage that it may
continue to examine the XmlDoc tree after the first matching node is found.
continue to examine the <var>XmlDoc</var> tree after the first matching node is found.
[[SelectSingleNode (XmlDoc/XmlNode function)|SelectSingleNode]] has a similar
[[SelectSingleNode (XmlDoc/XmlNode function)|SelectSingleNode]] has a similar
disadvantage: it may visit nodes in an order
disadvantage: it may visit nodes in an order
other than the document order, and, since it guarantees to
other than the document order, and, since it guarantees to
return the first node in XmlDoc order, it may continue even after
return the first node in <var>XmlDoc</var> order, it may continue even after
the first match is found.
the first match is found.
</ul>
</ul>
Line 36: Line 36:
The following request tests two XPath results:
The following request tests two XPath results:
<p class="code">Begin
<p class="code">Begin
%d Object XmlDoc
%d <var>Object</var> <var>XmlDoc</var>
%d = New
%d = New
Print 'Root exist?' And %d:Exists('.'):ToString
Print 'Root exist?' And %d:<var>Exists</var>('.'):To<var>String</var>
Print 'Elem of empty doc exist?' And %d:Exists('*'):ToString
Print 'Elem of empty doc exist?' And %d:<var>Exists</var>('*'):To<var>String</var>
End
End
</p>
</p>

Revision as of 17:46, 25 January 2011

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


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

Syntax

%boolean = nr:Exists( xpath) Throws XPathError

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 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.

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.