CollectionNode - cXMLDOMNodeList
Accesses items of a collection by item number
Type: Function
Return Data Type: Handle
Parameters
| Parameter | Type | Description |
|---|---|---|
| I | Integer | The item number |
Syntax
Function CollectionNode Integer I Returns Handle
Call Example
Get CollectionNode I to HandleVariable
Description
CollectionNode is used to access items of a collection by item number I.
Sample
For iItem From 0 To iItems
Get CollectionNode Of hoList iItem to hoNode
:
Loop
Parsing an XML Document within a BPO
This sample shows you how to access an XML Document. To access an XML document for editing or reporting purposes you do the following: Declare an object of the cXmlDomDocument class and set its propertiesGet a handle to the document by sending a "Get LoadXMLDocument" message (and preferably testing for a valid response)Get a handle to the main document element by sending a "Get DocumentElement" messageGet a handle to the rootnode of the element you are interested in by sending a "Get FindNodeList" message with an appropriate parameterFind the number of items in the returened NodeList by sending a "Get NodeListLength" messageDecrement the length by one (because it is zero-based)Loop through the nodelist, sending a "Get CollectionNode" message; working on the value, then destroying the handle to the nodelist itemDestroy the handles to the nodelist and the document The translates into DataFlex code as follows:
Object oBPOXML is a BusinessProcess
:
Procedure OnProcess
Handle hoXML hoRoot hoList hoCust
Integer iItems i bOK
Get Create U_cXMLDOMDocument to hoXML
// you can use Create (as above) or create
// the object using standard Object syntax (as below)
// Object oXML is a cXmlDomDocument
// Move Self to hoXML
// End_Object
Set psDocumentName of hoXML to "http://localhost/xml/customer.xml"
Set pbAsync of hoXML to False
Set pbValidateOnParse of hoXML to True
Get LoadXMLDocument of hoXML to bOK
If not bOK Begin
Send BasicParseErrorReport of hoXml
Procedure_Return
End
Showln 'loaded'
Get DocumentElement of hoXML to hoRoot
Get FindNodeList of hoRoot "CUSTOMER" to hoList
Get NodeListLength of hoList to iItems
Decrement iItems
For i from 0 to iItems
Get CollectionNode of hoList i to hoCust
Send ShowCust hoCust
Send Destroy of hoCust
Loop
Send Destroy of hoList
Send Destroy of hoXML
End_Procedure
Procedure ShowCust Handle hoCust
String sName sPhone sState
Get AttributeValue of hoCust "NAME" to sName
Get ChildNodeValue of hoCust "TELEPHONE" to sPhone
Get ChildNodeValue of hoCust "ADDRESS/STATE" to sState
Showln sName ' ' sPhone ' ' sState
End_Procedure
End_Object
See Also
Return Value
Should return a valid DataFlex object. Remove the object using the Destroy message when it is no longer needed.