Retrieving data from XML

The following examples show you how to pull data out from an XMLDocument (or any XML type) using the following XML.

Generally speaking, walking the XML is more efficient than using XPath because it does not call the parser.

The XML example here is the resultSet from an Integration Component. For the purposes of the example, assume that the following XML is stored in a variable called myXML.

<resultSet recordCount="2" columnCount="2">
  <record>
    <column name="FIRST_NAME">Daniel</column>
    <column name="ZIP">78703</column>
  </record>
  <record>
    <column name="FIRST_NAME">Helen</column>
    <column name="ZIP">15228</column>
  </record>
</resultSet>
The following examples illustrate how to retrieve specific values from the XML variable.
tw.local.myXML.resultSet
Returns a node list of records.
tw.local.myXML.resultSet.record[1]
Returns a node list of columns. In the previous example, the values "Helen" and "15228".
tw.local.myXML.resultSet.record[1].column[0].getAttribute( "name")
Returns "FIRST_NAME".
tw.local.myXML.resultSet.record[1].column[1].getAttribute("name")
Returns "ZIP".
tw.local.myXML.resultSet.record[1].column[1].getText()
Returns 15228.