Try and Catch will always work :) But if you want a different, 'more
elegent' solution...

Is the problem that some 'ProductInformation' elements do not contain all
the
expected sub-elements? i.e. you are expecting:

productinfo[x].productid
productinfo[x].productLink
productinfo[x].productName

And sometimes you only get:

productinfo[x].productid
productinfo[x].productName

If so, I imagine you want to display a record even if it does not contain
all the correct fields and instead of try & catch you should be able to use
<cfif StructKeyExists(productinfo[x], 'productLink')>Show it</cfif>

But maybe I'm still getting the wrong end of the stick?

Regards,

Dominic


On 15/11/2007, Che Vilnonis <[EMAIL PROTECTED]> wrote:
>
> Dominic, I solved the problem with the cftry/cfcatch combo that Dave
> suggested in a previous email.
>
> But in a nutshell, imagine this. You are looping through an array. You
> expect that the array will have 5 elements of xml data because that has
> been
> the case for the last 2 years. For whatever reason, now some arrays only
> contain 4 elements. (Not 5 elements with one blank value.) I was/am trying
> to figure out how to elegantly to display the data w/o any errors when the
> missing element was cfoutput-ted.
>
> XMLSearch, isdefined, cfparam and ArrayIsDefined were not working (at
> least
> for me).
>
> Thanks, Che
>
> -----Original Message-----
> From: Dominic Watson [mailto:[EMAIL PROTECTED]
> Sent: Thursday, November 15, 2007 6:45 AM
> To: CF-Talk
> Subject: Re: I really code use some Web Service/XML help.
>
> If the problem is that the array you are looping contains 'undefined'
> values, you could try this code to remove them:
>
> <cfscript>
> foo = ArrayNew(1);
> foo[2] = "";
>
> myArray.RemoveAll(foo);
> </cfscript>
>
> Or is it that some 'ProductInformation' elements do not contain all the
> expected sub-elements?
>
> Another thing to try is to use XMLSearch to return an array of
> 'ProductInformation' elements which will simplify the code and perhaps
> solve
> the problem:
>
> <cfset aProducts = XMLSearch(xmlContent,"//ProductInformation");
> <cfloop from="1" to="#ArrayLen(aProducts)#" index="i"> <cfoutput>Product
> link: #aProducts[i].productLink.xmlText#</cfoutput>
> </cfloop>
>
> Regards,
>
> Dominic
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Enterprise web applications, build robust, secure 
scalable apps today - Try it now ColdFusion Today
ColdFusion 8 beta - Build next generation apps

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:293391
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to