SelectCount (XmlDoc/XmlNode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 7: Line 7:
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%count</th>
<tr><th>%count</th>
<td>A numeric variable for the number of nodes on XmlNodelist <i>nlis</i>. </td></tr>
<td>A numeric variable for the number of nodes on <var>XmlNodelist</var> <i>nlis</i>. </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 count of nodes in this nodelist is returned.
<td>A <var>Unicode</var> string that is an XPath expression that results in a nodelist. The count of nodes in this nodelist is returned.
<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 24: Line 24:
==Examples==
==Examples==
<ul>
<ul>
<li>In the following example, SelectCount 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
children of node "top," then the text node children of
those "a" nodes:
those "a" nodes:
<p class="code">Begin
<p class="code">Begin
%doc is Object XmlDoc
%doc is <var>Object</var> <var>XmlDoc</var>
%j is Float
%j is <var>Float</var>
%k is Float
%k is <var>Float</var>
%doc = New
%doc = New
%doc:LoadXml('<top> <a>a1</a> <a>a2</a> <a>a3</a> </top>')
%doc:LoadXml('<top> <a>a1</a> <a>a2</a> <a>a3</a> </top>')
Call %doc:Print('/')
Call %doc:Print('/')
%j = %doc:SelectCount('/top/a')
%j = %doc:<var>SelectCount</var>('/top/a')
%k = %doc:SelectCount('/top/a/text()')
%k = %doc:<var>SelectCount</var>('/top/a/text()')
Print %j ' and ' %k
Print %j ' and ' %k
End
End
Line 67: Line 67:


<ul>
<ul>
<li>[[??]] reftxt=Count refid=count. counts the number of nodes on an XmlNodelist.
<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]].
<li>For more information about using XPath expressions, see [[XPath]].
</ul>
</ul>

Revision as of 17:46, 25 January 2011

Number of selected nodes (XmlDoc and XmlNode classes)


This method counts the number of nodes selected by an XPath expression.

Syntax

%number = nr:SelectCount( xpath) Throws XPathError

Syntax terms

%count A numeric variable for the number of nodes on XmlNodelist nlis.
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, 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 in the document 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

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