I am using ColdFusion 8. I am very new to XML.
I am trying to parse some XML. I am looping through the response and getting the info that I need, for the most part.
The trouble appears when I loop through the ResponseNodes array and I try to get access CustomFields, if there are any. CustomFields is only on some records, not all.
for (i = 1; i lte arrayLen(ResponseNodes); i++) {
CustomFields = xmlParse(ResponseNodes[i].CustomFields.Field);
}
This is the error I get:
Element CUSTOMFIELDS.FIELD is undefined in a Java
object of type class coldfusion.xml.XmlNodeMap referenced as ''
I see that the first two array elements are processed just fine, as they have CustomFields. The crash comes on the third element, which does NOT have a CustomeFields node.
How do I test for CustomFields?
You can test for it’s existence before parsing the XML with StructKeyExists()