Field-Map Scripting

4.1.11.3.4 Example

Example (TScriptXMLElementList members)


XML syntax:

<ROOTELEMENT>

   <ITEM ITEMNAME="name1">

       <SUBITEM VALUE="1a"/>

       <SUBITEM VALUE="1b"/>

       <SUBITEM VALUE="1c"/>                

   </ITEM>

   <ITEM ITEMNAME="name2">

       <SUBITEM VALUE="2a"/>

       <SUBITEM VALUE="2b"/>                

   </ITEM>

<SUBITEM SUBITEMNAME="name3"/>        

</ROOTELEMENT>


Declaration of variables referred to below:

RootElement_, MyElement_ : TScriptXMLElement;

MyXMLElementList :TScriptXMLElementList;


For the XML input displayed above, these will be the values of GetCount function (a function of the TScriptXMLElementList class which counts the number of items in the list of elements, i.e. the number of returned child elements):

Scripting code (GetCount function)

Result

RootElement_.GetChildElements('ITEM/SUBITEM').GetCount;

5

RootElement_.GetChildElements('ITEM').GetCount;

2

RootElement_.GetChildElements('SUBITEM').GetCount;

1


The following example demonstrates using the GetElement function (containing the index parameter specifying the element within the ElementList):

Scripting code (GetElement function)

Result

MyXMLElementList:=RootElement_.GetChildElements('ITEM');

MyElement_ := MyXMLElementList.GetElement(0);

MyElement_.GetStringAttributeAsString('ITEMNAME')



name1

MyXMLElementList:=RootElement_.GetChildElements('ITEM');

MyElement_ := MyXMLElementList.GetElement(1);

MyElement_.GetStringAttributeAsString('ITEMNAME')



name2




See also:

GetCount; GetElement; FreeXMLElementList


Example