SelectCount (XmlDoc/XmlNode function): Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
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| | <var>SelectCount</var> counts the number of nodes selected by an [[XPath#XPath_syntax|XPath expression]]. | ||
==Syntax== | ==Syntax== | ||
Line 11: | Line 11: | ||
<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 <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 [[XPath#XPath_syntax| | <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 <var class="product">[[Sirius Mods]]</var> Version 7.6, this is an EBCDIC string.</p></td></tr> | <p>Prior to <var class="product">[[Sirius Mods]]</var> Version 7.6, this is an EBCDIC string.</p></td></tr> | ||
</table> | </table> | ||
Line 17: | Line 17: | ||
==Usage notes== | ==Usage notes== | ||
<ul> | <ul> | ||
<li>If the result of the argument | <li>If the result of the argument XPath expression (<var class="term">xpath</var>) is empty, numeric zero is returned. | ||
</ul> | </ul> | ||
==Examples== | ==Examples== | ||
<ol> | <ol><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: | ||
<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: | |||
<p class="code">begin | <p class="code">begin | ||
%doc is object XmlDoc | %doc is object XmlDoc | ||
Line 46: | Line 45: | ||
<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> | </p></ol> | ||
</ol> | |||
==Request-Cancellation Errors== | ==Request-Cancellation Errors== | ||
<ul> | <ul> | ||
<li><var class="term"> | <li><var class="term">xpath</var> is invalid. | ||
<li>Insufficient free space exists in CCATEMP. | <li>Insufficient free space exists in CCATEMP. | ||
</ul> | </ul> |
Revision as of 23:51, 23 May 2011
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 XmlNodelist selected by the xpath. |
---|---|
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
- 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
- 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
- xpath 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".