Copy link to clipboard
Copied
Hello, everyone.
I'm attempting to create a pricing module for Amazon. Basically, I give Amazon ten items at a time to get all pricing information for each item. The data is being returned in XML.
What I'd LIKE to do is take the first XML response that contains up to the first ten offers (sorted by seller name, includes prices for new, used, collectible, and refurbished), the total number of offer pages, and some other tidbits that I don't need, and put what I need into an array to hold on to while I make any necessary additional calls to Amazon for subsequent offers if there are more than ten offers for any item.
Then take that array and push the data into a table on my database for sorting and whatnot.
Problem is: getting the XML data from Amazon into an array. I'm using XMLParse() to at least get it into a CF struct, but creating a specific array is becoming difficult ( I don't work with arrays very often. )
I'm getting the following error message : You have attempted to dereference a scalar variable of type class coldfusion.runtime.Array as a structure with members.
How do I declare members of an array?
Thanks,
^_^
Copy link to clipboard
Copied
If you are having trouble with arrays, the cfml reference manual has good examples. Second, are you sure that xmlParse() returns a structure? Next, does the error message cold fusion provides give you any hints?
Finally, cfdump is your best troubleshooting freind.
Copy link to clipboard
Copied
I was under the impression that XMLParse() converts XML to a CF Struct. Guess not.
Using CFCATCH.Message and CFCATCH.Detail, the only error message I get is what I posted, nothing else; no other hints.
So, since XMLParse takes XML data and makes an XML Document string from it (which I think is totally ridiculous), is there anything available (preferably native as opposed to third-party) that will convert an XML string into a CF Struct?
Thanks,
^_^
Copy link to clipboard
Copied
WolfShade,
Like Dan suggested, you won't find a better tool than <cfdump>!.
Dumping your xml variable using the <cfdump> tag, will give you structure kinda view that you are looking for. Give it a try!.
Copy link to clipboard
Copied
I've been CFDUMPing the response from Amazon. Yes, it shows a kind of structure, but I'm having trouble accessing it.
<cfset AmazonData = XMLParse(cfhttp.FileContent)>
<cfscript>
AmazonData = AmazonResponse.ItemLookupResponse.Items.Item;
thisLength = arrayLen(AmazonData);
pricingData = ArrayNew(2);
for(i=1;i lte thisLength;i++) {
ArrayAppend(pricingData.ASIN,AmazonData.ASIN.XmlText);
ArrayAppend(pricingData.ASIN.TotalOfferPages,AmazonData.Offers.TotalOfferPages.XmlText);
}
</cfscript>
This is giving me the error message mentioned in my first post.
^_^
Copy link to clipboard
Copied
Does your error message specify a line number? If so, what's on that line?