Skip to main content
Participating Frequently
February 1, 2010
Question

Reading XML

  • February 1, 2010
  • 2 replies
  • 367 views

If you have an XML string like this:

<ZipCodes>
<string>98001</string>
<string>98002</string>
<string>98003</string>
.....
<string>98380</string>
<string>98383</string>
<string>98392</string>
<string>98422</string>
</ZipCodes>

and the number of <string> nodes are unknown, is there a way to find that number.

Currently I just loop 1 to 10000 and use cftry to break out of the loop when it gets to too high a number.

Is there a better way?

    This topic has been closed for replies.

    2 replies

    Owainnorth
    Inspiring
    February 1, 2010

    Hi Paul

    There certainly is.

    Get your file, run it through xmlParse(). Once you've searched/navigated through to your root object, the children appear as an array of nodes called XmlChildren.

    I do something simliar to this in one of my systems:

    for ( LOCAL.i=1; LOCAL.i LTE arrayLen(thisSection.xmlChildren); LOCAL.i++ ) {
         LOCAL.CONF[thisSection.xmlName][thisSection.xmlChildren[LOCAL.i].xmlAttributes.name] =           thisSection.xmlChildren[LOCAL.i].xmlAttributes.value ;
    }

    So yes you do have a better way - use arrayLen(xmlChildren).

    Inspiring
    February 1, 2010