Quantcast
Channel: Adobe Community : Unanswered Discussions - ColdFusion
Viewing all articles
Browse latest Browse all 5794

Checking for null xml elements

$
0
0

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[i]["SpecialId"]#

     #cfData[i]["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[i]["SpecialId"]#

     <cfif structKeyExists(cfData[i],"ImageUrl")>

          null image

     <cfelse>

          #cfData[i]["ImageUrl"]#

     </cfif>

</cfloop>

 

However, this returns the same error. Is there an issue with the way i am using StructKeyExists?


Viewing all articles
Browse latest Browse all 5794

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>