Item (XmlNodelist function): Difference between revisions
m (edits, tags and links) |
(No difference)
|
Revision as of 12:30, 16 May 2011
Retrieve an item from this nodelist (XmlNodelist class)
Item creates an XmlNode from one of the items on an XmlNodelist.
Syntax
%nod = nodl:Item( number)
Syntax terms
%nod | An XmlNode that points to the selected node. |
---|---|
nodl | The XmlNodelist from which the item is taken. |
number | A positive integer that identifies which item to select. |
Usage notes
- Under "Sirius Mods" Version 6.8 and later, the method name, Item, is not necessary on an XmlNodelist Item reference. For example (showing that the Item method name can be left off), if
%nlis
is an XmlNodelist in the following code:for %i from 1 To %nlis:count %nod = %nlis(%i) ...
The preceding example is the same as this one, with the Item method name coded:
for %i from 1 To %nlis:count %nod = %nlis:item(%i) ...
Examples
-
This example prints the node type and the names and/or values of items on an XmlNodelist;
%nod = %nlis(%i)
implicitly uses the Item method:begin %i is float %doc is object xmlDoc %nod is object xmlNode %nlis is object xmlnodelist %t enumeration xmlNodeType %doc = new %doc:loadXml('<top><a b="b1"><a1/></a> - <a><a2 b="b2"></a2></a></top>') %nlis = %doc:selectNodes('//.') for %i from 1 To %nlis:count %nod = %nlis(%i) %t = %nod:type if %t eq root then print 'Item ' %i ': Root' elseIf %t eq element then print 'Item ' %i ': Element' and %nod:qName elseIf %t eq attribute then print 'Item ' %i ': Attribute' and %nod:qName - with '="' with %nod:value with '"' else print 'Item ' %i ':' and %t:ToString - and '=' and %nod:value end if end for %doc:print end
The example result follows:
Item 1: Root Item 2: Element top Item 3: Element a Item 4: Element a1 Item 5: Element a Item 6: Element a2 <top> <a b="b1"> <a1/> </a> <a> <a2 b="b2"/> </a> </top>
Request-Cancellation Errors
- The selected item number (number) is not in the range from 1 to the number of items on the nodl.