Item (XmlNodelist function)

From m204wiki
Revision as of 20:40, 3 March 2014 by JAL (talk | contribs) (→‎Request-cancellation errors)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

  • 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

This list is not exhaustive: it does not include all the errors that are request cancelling.

  • The selected item number (number argument) is not in the range from 1 to the number of items on the nodl object.

See also