Exists (XmlDoc/XmlNode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Template:XmlDoc/XmlNode:Exists subtitle}}
{{Template:XmlDoc/XmlNode:Exists subtitle}}
<var>Exists</var> returns a [[Enumerations#Using_Boolean_enumerations|"Boolean Enumeration"]] whose value is <code>True</code> if the XPath result is non-empty, and <code>False</code> otherwise.
<var>Exists</var> returns a [[Enumerations#Using_Boolean_enumerations|Boolean enumeration]] whose value is <var>True</var> if the XPath result is non-empty, and <var>False</var> otherwise.


==Syntax==
==Syntax==
{{Template:XmlDoc/XmlNode:Exists syntax}}
{{Template:XmlDoc/XmlNode:Exists syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%boolean</th>
<tr><th nowrap>%boolean</th>
<td>A declared enumeration object of type <var>[[Boolean]]</var> to contain the returned value of <var>Exists</var>.</td></tr>
<td>A declared enumeration object of type <var>Boolean</var> to contain the returned value of <var>Exists</var>.</td></tr>
 
<tr><th>nr</th>
<tr><th>nr</th>
<td>An <var>XmlDoc</var> or <var>XmlNode</var>, used as the context node for the <var class="term">XPath</var> expression. If an <var>XmlDoc</var>, the <var>Root</var> node is the context node.</td></tr>
<td>An <var>XmlDoc</var> or <var>XmlNode</var>, used as the context node for the XPath expression, <var class="term">xpath</var>. If an <var>XmlDoc</var>, the <var>Root</var> node is the context node.</td></tr>
 
<tr><th>xpath</th>
<tr><th>xpath</th>
<td>A <var>Unicode</var> string that is an [[XPath#XPath_syntax|XPath expression]] that results in a <var>nodelist</var>. The expression default is a period (<code>.</code>), that is, the node referenced by the method object (<var class="term">nr</var>).
<td>A <var>Unicode</var> string that is an [[XPath#XPath_syntax|XPath expression]] that results in a nodelist. The expression default is a period (<code>.</code>), that is, the node referenced by the method object (<var class="term">nr</var>).


Prior to <var class="product">[[Sirius Mods|Sirius Mods]]</var> Version 7.6, this is an EBCDIC string.</td></tr>
Prior to <var class="product">[[Sirius Mods|Sirius Mods]]</var> Version 7.6, this is an EBCDIC string.</td></tr>
Line 18: Line 21:
==Usage notes==
==Usage notes==
<ul>
<ul>
<li>If you are only checking for the existence of some nodes in the document, <var>Exists</var> is the most efficient method.
<li>If you are only checking for the existence of some nodes in the document, <var>Exists</var> is the most efficient method:
<ul><li><var>[[SelectCount (XmlDoc/XmlNode function)|SelectCount]]</var> has the relative disadvantage that it may continue to examine the <var>XmlDoc</var> tree after the first matching node is found.
<ul>
<li><var>[[SelectSingleNode (XmlDoc/XmlNode function)|SelectSingleNode]]</var> 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 <var>XmlDoc</var> order, it may continue even after the first match is found.
<li><var>[[SelectCount (XmlDoc/XmlNode function)|SelectCount]]</var> has the relative disadvantage that it may continue to examine the <var>XmlDoc</var> tree after the first matching node is found. </li>
</ul></ul>
 
<li><var>[[SelectSingleNode (XmlDoc/XmlNode function)|SelectSingleNode]]</var> 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 <var>XmlDoc</var> order, it may continue even after the first match is found. </li>
</ul></li>
</ul>


===Examples===
==Examples==
<ol><li>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 object xmlDoc
Line 33: Line 39:
</p>
</p>
The example results follow:
The example results follow:
<p class="code">Root exist? True
<p class="output">Root exist? True
Elem of empty doc exist? False
Elem of empty doc exist? False
</p></ol>
</p>


===Request-Cancellation Errors===
==Request-cancellation errors==
This list is not exhaustive: it does <i>not</i> include all the errors that are request  cancelling.
<ul>
<ul>
<li><var class="term">xpath</var> is invalid.
<li><var class="term">xpath</var> is invalid.</li>
<li>Insufficient free space exists in CCATEMP.
<li>Insufficient free space exists in CCATEMP.</li>
</ul>
</ul>


==See also==
==See also==
<ul>
<ul>
<li>For more information about using XPath expressions, see [[XPath|"XPath"]].
<li>For more information about using XPath expressions, see [[XPath]].</li>
</ul>
</ul>
{{Template:XmlDoc/XmlNode:Exists footer}}
{{Template:XmlDoc/XmlNode:Exists footer}}

Latest revision as of 21:16, 2 September 2015

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.

Syntax

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

Examples

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.