SelectCount (XmlDoc/XmlNode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (xpath expression)
 
m (minor cleanup)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Template:XmlDoc/XmlNode:SelectCount subtitle}}
{{Template:XmlDoc/XmlNode:SelectCount subtitle}}
<var>SelectCount</var> counts the number of nodes selected by an [[XPath#XPath_syntax|XPath expression]].


This method counts the number of nodes selected by an <var>[[XPath#XPath_syntax|Xpath expression]]</var>.
==Syntax==
==Syntax==
{{Template:XmlDoc/XmlNode:SelectCount syntax}}
{{Template:XmlDoc/XmlNode:SelectCount syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%number</th>
<tr><th>%number</th>
<td>A numeric variable for the number of nodes on <var>XmlNodelist</var> <i>nlis</i>. </td></tr>
<td>A numeric variable that receives the count of nodes on the nodelist selected by the <var class="term">xpath</var> expression.</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 Root node is the context node. </td></tr>
<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>
 
<tr><th>xpath</th>
<tr><th>xpath</th>
<td>A <var>Unicode</var> string that is an <var>[[XPath#XPath_syntax|Xpath expression]]</var> that results in a nodelist. The count of nodes in this nodelist is returned.
<td>A <var>Unicode</var> string that is an [[XPath#XPath_syntax|XPath expression]] that results in a nodelist. The count of nodes in this nodelist is returned.
 
<p>
Prior to ''Sirius Mods'' version 7.6, this is an EBCDIC string.</td></tr>
Prior to <var class="product">[[Sirius Mods]]</var> Version 7.6, this is an EBCDIC string.</p></td></tr>
 
</table>
</table>


==Usage notes==
==Usage notes==
<ul>
<ul>
<li>If the result of the argument XPath expression (<i>XPath</i>) is empty,
<li>If the result of the argument XPath expression (<var class="term">xpath</var>) is empty, numeric zero is returned.
zero is returned.
</ul>
</ul>


==Examples==
==Examples==
<ul>
<ol>
<li>In the following example, <var>SelectCount</var> counts the "a" node
<li>In the following example, <var>SelectCount</var> counts the "a" node children of node "top," then the text node children of those "a" nodes:
children of node "top," then the text node children of
<p class="code">begin
those "a" nodes:
  %doc is object XmlDoc
<p class="code">Begin
  %j is float
%doc is Object XmlDoc
  %k is float
%j is Float
  %doc = new
%k is Float
  %doc:[[LoadXml_(XmlDoc/XmlNode_function)|loadXml]]('<top> <a>a1</a> <a>a2</a> <a>a3</a> </top>')
%doc = New
  [[Notation_conventions_for_methods#Callable_methods|Call]] %doc:print('/')
%doc:LoadXml('<top> <a>a1</a> <a>a2</a> <a>a3</a> </top>')
  %j = %doc:selectCount('/top/a')
Call %doc:Print('/')
  %k = %doc:selectCount('/top/a/text()')
%j = %doc:SelectCount('/top/a')
  print %j ' and ' %k
%k = %doc:SelectCount('/top/a/text()')
end
Print %j ' and ' %k
End
</p>
</p>
The example results follow:
The example results follow:
<p class="code"><top>
<p class="output"><top>
   <a>a1</a>
   <a>a1</a>
   <a>a2</a>
   <a>a2</a>
Line 48: Line 46:
</top>
</top>
3 and 3
3 and 3
</p>
</p></li>
<li>The following
 
statements count all the nodes in the document
<li>The following statements count all the nodes and all the attributes in the document, respectively.
and all the attributes in the document, respectively.
<p class="code">print 'Count of non-attribute nodes:' and %doc:countSelected('//node()')
<p class="code">Print 'Count of non-attribute nodes:' And %doc:CountSelected('//node()')
print 'Count of    attribute nodes:' and %doc:countSelected('//@*')
Print 'Count of    attribute nodes:' And %doc:CountSelected('//@*')
</p></li>
</p>
</ol>
</ul>


==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><i>XPath</i> is invalid.
<li>The <var class="term">xpath</var> expression is invalid.
<li>Insufficient free space exists in CCATEMP.
<li>Insufficient free space exists in CCATEMP.
</ul>
</ul>


==See also==
==See also==
{{Template:XmlDoc/XmlNode:SelectCount footer}}
<ul>
<li><var>[[Count_(XmlNodelist_function)|Count]]</var> counts the number of nodes on an <var>XmlNodelist</var>.</li>


<ul>
<li>For more information about using XPath expressions, see [[XPath]].</li>
<li>[[??]] reftxt=Count refid=count. counts the number of nodes on an <var>XmlNodelist</var>.
<li>For more information about using XPath expressions, see [[XPath]].
</ul>
</ul>
{{Template:XmlDoc/XmlNode:SelectCount footer}}

Latest revision as of 17:47, 18 February 2015

Number of selected nodes (XmlDoc and XmlNode classes)

SelectCount counts the number of nodes selected by an XPath expression.

Syntax

%number = nr:SelectCount( xpath) Throws XPathError

Syntax terms

%number A numeric variable that receives the count of nodes on the nodelist selected by the xpath expression.
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 count of nodes in this nodelist is returned.

Prior to Sirius Mods Version 7.6, this is an EBCDIC string.

Usage notes

  • If the result of the argument XPath expression (xpath) is empty, numeric zero is returned.

Examples

  1. In the following example, SelectCount counts the "a" node children of node "top," then the text node children of those "a" nodes:

    begin %doc is object XmlDoc %j is float %k is float %doc = new %doc:loadXml('<top> <a>a1</a> <a>a2</a> <a>a3</a> </top>') Call %doc:print('/') %j = %doc:selectCount('/top/a') %k = %doc:selectCount('/top/a/text()') print %j ' and ' %k end

    The example results follow:

    <top> <a>a1</a> <a>a2</a> <a>a3</a> </top> 3 and 3

  2. The following statements count all the nodes and all the attributes in the document, respectively.

    print 'Count of non-attribute nodes:' and %doc:countSelected('//node()') print 'Count of attribute nodes:' and %doc:countSelected('//@*')

Request-cancellation errors

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

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

See also

  • Count counts the number of nodes on an XmlNodelist.
  • For more information about using XPath expressions, see XPath.