Checking for null xml elements
Hello,
i am parsing an xml file by using a CFLoop. Some rows in the file do not contain every element. What is the best way to check if an element exists?
My current code looks something like the following:
<cfloop from="1" to="#arrayLen(cfData)#" index="i">
#cfData["SpecialId"]#
#cfData["ImageUrl"]#
</cfloop>
For some rows, ImageUrl exists, but it doesnt in others. When running the code, i received the following error:
Element ImageUrl is undefined in a CFML structure referenced as part of an expression.
I tried the following:
<cfloop from="1" to="#arrayLen(cfData)#" index="i">
#cfData["SpecialId"]#
<cfif structKeyExists(cfData,"ImageUrl")>
null image
<cfelse>
#cfData["ImageUrl"]#
</cfif>
</cfloop>
However, this returns the same error. Is there an issue with the way i am using StructKeyExists?
