Item (XmlNodelist function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
m (1 revision)
m (1 revision)
Line 1: Line 1:
{{Template:XmlNodelist:Item subtitle}}
{{Template:XmlNodelist:Item subtitle}}


This function creates an XmlNode from one of the items on an XmlNodelist.
This function creates an <var>XmlNode</var> from one of the items on an <var>XmlNodelist</var>.
==Syntax==
==Syntax==
{{Template:XmlNodelist:Item syntax}}
{{Template:XmlNodelist:Item syntax}}
Line 7: Line 7:
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%nod</th>
<tr><th>%nod</th>
<td>An XmlNode that points to the selected node. </td></tr>
<td>An <var>XmlNode</var> that points to the selected node. </td></tr>
<tr><th>nlis</th>
<tr><th>nlis</th>
<td>The XmlNodelist from which the item is taken. </td></tr>
<td>The <var>XmlNodelist</var> from which the item is taken. </td></tr>
<tr><th>num</th>
<tr><th>num</th>
<td>A positive integer that identifies which item to select.</td></tr>
<td>A positive integer that identifies which item to select.</td></tr>
Line 15: Line 15:
==Usage notes==
==Usage notes==


Under ''Sirius Mods'' version 6.8 and later, the method name, <tt>Item</tt>, is not
Under ''Sirius Mods'' version 6.8 and later, the method name, <tt><var>Item</var></tt>, is not
necessary on an XmlNodelist Item reference.
necessary on an <var>XmlNodelist</var> <var>Item</var> reference.
For example (showing that the Item method name can be left off),
For example (showing that the <var>Item</var> method name can be left off),
if <tt>%nlis</tt> is an XmlNodelist in the following code:
if <tt>%nlis</tt> is an <var>XmlNodelist</var> in the following code:
<p class="code">For %i From 1 To %nlis:Count
<p class="code">For %i From 1 To %nlis:Count
   %nod = %nlis(%i)
   %nod = %nlis(%i)
   ...
   ...
</p>
</p>
The preceding example is the same as this one, with the Item method name coded:
The preceding example is the same as this one, with the <var>Item</var> method name coded:
<p class="code">For %i From 1 To %nlis:Count
<p class="code">For %i From 1 To %nlis:Count
   %nod = %nlis:Item(%i)
   %nod = %nlis:<var>Item</var>(%i)
   ...
   ...
</p>
</p>
Line 31: Line 31:


This example prints the node type and the names and/or values of items on
This example prints the node type and the names and/or values of items on
an XmlNodelist; <tt>%nod = %nlis(%i)</tt>
an <var>XmlNodelist</var>; <tt>%nod = %nlis(%i)</tt>
implicitly uses the Item method:
implicitly uses the <var>Item</var> method:
<p class="code">Begin
<p class="code">Begin
%i is Float
%i is <var>Float</var>
%doc is Object XmlDoc
%doc is <var>Object</var> <var>XmlDoc</var>
%nod is Object XmlNode
%nod is <var>Object</var> <var>XmlNode</var>
%nlis is object xmlnodelist
%nlis is object xmlnodelist
%t Enumeration XmlNodeType
%t Enumeration <var>XmlNode</var>Type
%doc = New
%doc = New
%doc:LoadXml('<top><a b="b1"><a1/></a> -
%doc:LoadXml('<top><a b="b1"><a1/></a> -
Line 48: Line 48:
   %t = %nod:Type
   %t = %nod:Type
   If %t EQ Root Then
   If %t EQ Root Then
     Print 'Item ' %i ': Root'
     Print '<var>Item</var> ' %i ': Root'
   ElseIf %t EQ Element Then
   ElseIf %t EQ Element Then
     Print 'Item ' %i ': Element' And %nod:QName
     Print '<var>Item</var> ' %i ': Element' And %nod:QName
   ElseIf %t EQ Attribute Then
   ElseIf %t EQ Attribute Then
     Print 'Item ' %i ': Attribute' And %nod:QName -
     Print '<var>Item</var> ' %i ': Attribute' And %nod:QName -
       With '="' With %nod:Value With '"'
       With '="' With %nod:Value With '"'
   Else
   Else
     Print 'Item ' %i ':' And %t:ToString -
     Print '<var>Item</var> ' %i ':' And %t:To<var>String</var> -
       And '=' And %nod:Value
       And '=' And %nod:Value
   End If
   End If
Line 65: Line 65:


The example result follows:
The example result follows:
<p class="output">Item 1: Root
<p class="output"><var>Item</var> 1: Root
Item 2: Element top
<var>Item</var> 2: Element top
Item 3: Element a
<var>Item</var> 3: Element a
Item 4: Element a1
<var>Item</var> 4: Element a1
Item 5: Element a
<var>Item</var> 5: Element a
Item 6: Element a2
<var>Item</var> 6: Element a2
<top>
<top>
   <a b="b1">
   <a b="b1">

Revision as of 17:45, 25 January 2011

Retrieve an item from this nodelist (XmlNodelist class)


This function 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.
nlis The XmlNodelist from which the item is taken.
num 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) ...

Example

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 (num) is not in the range from 1 to the number of items on the nodelist.

See also