Count (XmlNodelist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 24: Line 24:
%nl1 = %doc:SelectNodes('/top/a')
%nl1 = %doc:SelectNodes('/top/a')
For %j from 1 to %nl1:<var>Count</var>
For %j from 1 to %nl1:<var>Count</var>
<p class="code">%n1 = %nl1:Item(%j)
%n1 = %nl1:Item(%j)
%n2 = %n1:AddElement('b', 'b' With %j)
%n2 = %n1:AddElement('b', 'b' With %j)
</p>
</p>
End For
End For
Line 34: Line 34:
The example results follow:
The example results follow:
<p class="code"><top>
<p class="code"><top>
<p class="code"><a>
<a>
  a1
    a1
  <b>b1</b>
    <b>b1</b>
</a>
</a>
<a>
<a>
  a2
    a2
  <b>b2</b>
    <b>b2</b>
</a>
</a>
<a>
<a>
  a3
    a3
  <b>b3</b>
    <b>b3</b>
</a>
</a>
</p>
</top>
</top>
</p>
</p>

Revision as of 19:04, 7 February 2011

Number of nodes in this nodelist (XmlNodelist class)

Syntax

%number = nodl:Count

Syntax terms

%count A numeric variable for the number of nodes on XmlNodelist nlis.
nlis An XmlNodelist expression, specifying the nodelist to count.

Example

In the following example, the Count method is used to limit a For loop which selectively adds nodes to the document:

Begin %doc is Object XmlDoc %doc = New %doc:LoadXml('<top> <a>a1</a> <a>a2</a> <a>a3</a> </top>') %nl1 is Object XmlNodelist %n1 is Object XmlNode %n2 is Object XmlNode %j is Float %nl1 = %doc:SelectNodes('/top/a') For %j from 1 to %nl1:Count %n1 = %nl1:Item(%j) %n2 = %n1:AddElement('b', 'b' With %j)

End For Call %d1:Print End

The example results follow:

<top> <a> a1 b1 </a> <a> a2 b2 </a> <a> a3 b3 </a> </top>

Request-Cancellation Errors

  • Count has no request cancellation errors.


See also

  • SelectCount counts the number of nodes in an XPath expression result.