SelectCount (XmlDoc/XmlNode function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 19: Line 19:
<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 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.</td></tr>
<p class="code">Prior to ''Sirius Mods'' version 7.6, this is an EBCDIC string.</td></tr>
</p>
</table>
</table>


Line 33: Line 34:
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:
<pre>
<p class="code">Begin
    Begin
%doc is Object XmlDoc
    %doc is Object XmlDoc
%j is Float
    %j is Float
%k is Float
    %k is Float
%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:SelectCount('/top/a')
%k = %doc:SelectCount('/top/a/text()')
    %k = %doc:SelectCount('/top/a/text()')
Print %j ' and ' %k
    Print %j ' and ' %k
End
    End
</p>
</pre>


The example results follow:
The example results follow:
<pre>
<p class="code"><top>
    <top>
  <a>a1</a>
      <a>a1</a>
  <a>a2</a>
      <a>a2</a>
  <a>a3</a>
      <a>a3</a>
</top>
    </top>
3 and 3
    3 and 3
</p>
</pre>
<li>The following
<li>The following
statements count all the nodes in the document
statements count all the nodes in the document
and all the attributes in the document, respectively.
and all the attributes in the document, respectively.
<pre>
<p class="code">Print 'Count of non-attribute nodes:' And %doc:CountSelected('//node()')
    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>
</pre>
</ul>
</ul>



Revision as of 05:42, 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.