Item (XmlNodelist function)

From m204wiki
Revision as of 00:13, 7 December 2010 by 198.242.244.47 (talk) (Created page with "<span style="font-size:120%; color:black"><b>XmlNode from XmlNodelist</b></span> Item function Category:XmlDoc API methods [[Category:System ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

XmlNode from XmlNodelist

Item is a member of the XmlNodelist class.

This function creates an XmlNode from one of the items on an XmlNodelist.

Syntax

  %nod = nlis[:Item](num)

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.