Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Have you read through the docs on using XML in CF:
http://livedocs.adobe.com/coldfusion/8/htmldocs/XML_01.html
Particularly these pages:
http://livedocs.adobe.com/coldfusion/8/htmldocs/XML_06.html
http://livedocs.adobe.com/coldfusion/8/htmldocs/XML_08.html
http://livedocs.adobe.com/coldfusion/8/htmldocs/XML_16.html
If you read these, you should be able to pick up what you need to do.
--
Adam
Copy link to clipboard
Copied
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).