• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Arrays and XML

LEGEND ,
Aug 03, 2009 Aug 03, 2009

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,

^_^

Views

859

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 03, 2009 Aug 03, 2009

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 03, 2009 Aug 03, 2009

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,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 04, 2009 Aug 04, 2009

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!.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 04, 2009 Aug 04, 2009

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.

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 04, 2009 Aug 04, 2009

Copy link to clipboard

Copied

LATEST

Does your error message specify a line number?  If so, what's on that line?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation