Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Reading XML

New Here ,
Feb 01, 2010 Feb 01, 2010

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?

334
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 01, 2010 Feb 01, 2010
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 01, 2010 Feb 01, 2010
LATEST

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).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources