In short... No! There isn't any easier or shorter way to determine if an array element exists. If you try to access an undefined array element using any native ColdFusion function an error will be thrown. Having dealt with the ATDW feeds in the past, I know how much *fun* they can be to deal with, but having read your original post again, my guess is that what you want is not to test if an array element exists, but whether a key in a structure nested in an array exists. If that's the case then it's slightly simpler: <cfif structKeyExists(aTDWDoc.atdw_data_results.product_distribution[i].product_re cord,'max_star_rating')> <!--- Do your stuff to the max star rating key in here ---> </cfif>
If you really want to know if element i exists in ATDWDOc.atdw_data_results.product_distribution then you have to use the code I posted earlier. Spike ________________________________ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Claude Raiola Sent: Friday, January 30, 2004 4:49 PM To: CFAussie Mailing List Subject: [cfaussie] RE: How To Determining if specific Variable Arrays exist Thanks for all that assistance however is there some alternative way of determining if a array element exists as I am trying to use this as part of my xml input feed where the web service provider drops off an element if the record does not have a value within that element eg lets take a record for an accommodation house if accommodation house 1 provides their star rating then <star_rating>4</star_rating> is included in the xml where as if the accommodation house has not provided a value for star rating then the web services xml document does not even have the <star_rating></star_rating> element in the xml for that record hence the need to test the existence for every element I want to display the output for with each record being passes surely there is an easier and quicker way to determine if the element exists. ?? Kind Regards Claude Raiola (Director) AustralianAccommodation.com Pty. Ltd. Mobile: 0414 228 948 Fax: 07 3319 6444 Websites: www.AustralianAccommodation.com <http://www.australianaccommodation.com/> www.AccommodationNewZealand.com <http://www.accommodationnewzealand.com/> www.HospitalityPurchasing.net <http://www.hospitalitypurchasing.net/> <mailto:[EMAIL PROTECTED]> -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Stephen Milligan Sent: Saturday, 31 January 2004 10:33 AM To: CFAussie Mailing List Subject: [cfaussie] RE: How To Determining if specific Variable Arrays exist Not forgetting of course to replace the *ahem* deliberate line with the re-declared local variable just after the opening <cftry> tag with this: <cfset tmp = arguments.array[arguments.element]> Spike ________________________________ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Stephen Milligan Sent: Friday, January 30, 2004 4:18 PM To: CFAussie Mailing List Subject: [cfaussie] RE: How To Determining if specific Variable Arrays exist The only reliable way to test if an array element exists is to put a try/catch block around it: <cffunction name="isArrayElementDefined"> <cfargument name="array" type="array" required="true"> <cfargument name="element" type="numeric" required="true"> <cfset var tmp = ""> <cftry> <cfset var tmp = arguments.array[arguments.element]> <cfcatch> <cfreturn false> </cfcatch> </cftry> <cfreturn true> </cffunction> <cfset myArray = arrayNew(1)> <cfset myArray[1] = "foo"> <cfset myArray[4] = "bar"> <cfoutput> <cfloop from="1" to="#arrayLen(myArray)#" index="i"> <br> <br> <cfif isArrayElementDefined(myArray,i)> Element #i# exists. <cfelse> Element #i# does not exist. </cfif> </cfloop> </cfoutput> Spike ________________________________ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Claude Raiola Sent: Friday, January 30, 2004 4:06 PM To: CFAussie Mailing List Subject: [cfaussie] RE: How To Determining if specific Variable Arrays exist when I use the arraylen() function eg: <cfif ArrayLen(aTDWDoc.atdw_data_results.product_distribution.product_record.max_s tar_rating.XmlText) LTE i> generates the following error message (I need to include "product_record.max_star_rating" ) as that is the specific array element I am testing for to see whether it exists hence the reason for initially trying to use isdefined() function Object of type class java.lang.String cannot be used as an array The error occurred in D:\inetpub\webhost\4301\www\aus\ATDW\query_products_26_01_04.cfm: line 60 58 : <cfset prodn = QuerySetCell(myquery, "product_description", aTDWDoc.atdw_data_results.product_distribution[i].product_record.product_des cription.XmlText, i)> 59 : </cfif> 60 : <cfif ArrayLen(aTDWDoc.atdw_data_results.product_distribution.product_record.max_s tar_rating.XmlText) LTE i> 61 : <cfset prodn = QuerySetCell(myquery, "star_rating", aTDWDoc.atdw_data_results.product_distribution[i].product_record.max_star_ra ting.XmlText, i)> 62 : </cfif> Kind Regards Claude Raiola (Director) AustralianAccommodation.com Pty. Ltd. Mobile: 0414 228 948 Fax: 07 3319 6444 Websites: www.AustralianAccommodation.com <http://www.australianaccommodation.com/> www.AccommodationNewZealand.com <http://www.accommodationnewzealand.com/> www.HospitalityPurchasing.net <http://www.hospitalitypurchasing.net/> <mailto:[EMAIL PROTECTED]> -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Steve Onnis Sent: Saturday, 31 January 2004 7:50 AM To: CFAussie Mailing List Subject: [cfaussie] RE: How To Determining if specific Variable Arrays exist You cant use isDefined() for arrays You could try using ArrayLen so <cfif ArrayLen(aTDWDoc.atdw_data_results.product_distribution) LTE i> <cfset prodn = QuerySetCell(myquery, "star_rating", aTDWDoc.atdw_data_results.product_distribution[i].product_record.max_star_ra ting.XmlText, i)> </cfif> That might do you Steve -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Claude Raiola Sent: Saturday, 31 January 2004 4:47 AM To: CFAussie Mailing List Subject: [cfaussie] How To Determining if specific Variable Arrays exist I am trying to use the isdefined function to determine with a variable within an array exists. The code is in bedded within the cfloop with index=I when using the syntax in line 60 below the following error message occurs wondering what is the correct syntax in order to be able to determine whether specific variables within the are defined. I look forward to your input Parameter 1 of function IsDefined, which is now "aTDWDoc.atdw_data_results.product_distribution[i].product_record.max_s tar_rating.XmlText", must be a syntactically valid variable name. The error occurred in D:\inetpub\webhost\4301\www\aus\ATDW\query_products_26_01_04.cfm: line 60 60 : <cfif isdefined('aTDWDoc.atdw_data_results.product_distribution[i].product_record. max_star_rating.XmlText')> 61 : <cfset prodn = QuerySetCell(myquery, "star_rating", aTDWDoc.atdw_data_results.product_distribution[i].product_record.max_star_ra ting.XmlText, i)> 62 : </cfif> Kind Regards Claude Raiola (Director) AustralianAccommodation.com Pty. Ltd. Mobile: 0414 228 948 Fax: 07 3319 6444 Websites: www.AustralianAccommodation.com <http://www.australianaccommodation.com/> www.AccommodationNewZealand.com <http://www.accommodationnewzealand.com/> www.HospitalityPurchasing.net <http://www.hospitalitypurchasing.net/> <mailto:[EMAIL PROTECTED]> --- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia http://www.mxdu.com/ + 24-25 February, 2004 --- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia http://www.mxdu.com/ + 24-25 February, 2004 --- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia http://www.mxdu.com/ + 24-25 February, 2004 --- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia http://www.mxdu.com/ + 24-25 February, 2004 --- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia http://www.mxdu.com/ + 24-25 February, 2004 --- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia http://www.mxdu.com/ + 24-25 February, 2004 --- You are currently subscribed to cfaussie as: [EMAIL PROTECTED] To unsubscribe send a blank email to [EMAIL PROTECTED] MXDU2004 + Macromedia DevCon AsiaPac + Sydney, Australia http://www.mxdu.com/ + 24-25 February, 2004
