Can't get xml back from Amazon Web Service?

I can put the feed url in the browser and all is well, but I can't seem to get a response using the code below

function GetFeed()
{
var r = Web.Network.createRequest(
Web.Network.Type.XML,
m_feedUrl,
{proxy:"generic", numItems:m_numItems},
OnFeedReceived);

r.execute();
}

Is the m_feedUrl just too long maybe?

http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&Version=2006-06-07&AWSAccessKeyId=1CE7SK4ZPTNDQZCWBP82&Operation=ListLookup&ListType=WishList&ListId=241KH7V8OZ7EQ&Sort=DateAdded&ResponseGroup=ListItems

Any help would be greatly appreciated!

[1147 byte] By [incendy] at [2008-2-21]
# 1

If I do this:

var items = response.responseXML.documentElement.selectNodes("*");

m_el.innerHTML = items;

it returns the following:

[object Element],[object Element]

Is there any way I can see what the two Elements it is returning are? I know there are supposed to be many more, but this might at least give me an idea=D

incendy at 2007-9-4 > top of Msdn Tech,Gadgets,Web Gadget Development...
# 2

it's weird because if I use this xpath query at the xpath testbed it returns 6 nodes, but in my gadget it returns nothing

http://www.whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm?Red60urne=e3d627be560414024ad4772a3c7cacbf&context=%2F&xpath=%2F%2FListLookupResponse%2FLists%2FList%2FListItem&eval=Evaluate

//ListLookupResponse/Lists/List/ListItem

var items = response.responseXML.documentElement.selectNodes("ListLookupResponse/Lists/List/ListItem");

Is it maybe because of Namespace?

incendy at 2007-9-4 > top of Msdn Tech,Gadgets,Web Gadget Development...
# 3
ok, it appears it must be a namespace thing, becuase if I change it to //* it shows every single node, but I can't get to any of them by name:(
incendy at 2007-9-4 > top of Msdn Tech,Gadgets,Web Gadget Development...
# 4

sadly I can't figure out how to specify an xmnls namespace without using soap, or at least that is what it seems all the examples show but I can't use xmlpost. I tried the following but that didn't seem to work either.

registerNamespace("xmlns:aws='http://webservices.amazon.com/AWSECommerceService/2006-06-07'");

If anyone has any suggestions I would really appreciate it. Feeling pretty lost right about now

incendy at 2007-9-4 > top of Msdn Tech,Gadgets,Web Gadget Development...
# 5

Addressing a few points:

  • selectNodes() returns an array of XmlNode elements, which are objects. What you're getting ("[object Element]") seems about right. If you want to enumerate the text values of nodes selected, loop over items.length and stuff "itemsIdea.text" into innerHTML.
  • You shouldn't need to specify a namespace in an XPath. If there are prefixed namespaces ("foo:someElement"), you would reference them the same way. In your case, your XPath should be working. I'm not sure why you're getting only four elements instead of six. Maybe the response you're getting only has four such items in it?
  • registerNamespace() is an Atlas (ASP.NET AJAX, now, I guess) method to register a namespace for classes. It has nothing to do with parsing XML. Thus obviously it wouldn't work :)

Two suggestions to try:

  • You seem to be getting a response, so it's not likely you're running up against a MIME type issue, but you should double-check that Amazon is returning text/xml or application/xml.
  • You should debug into your gadget so you can more easily look at the contents of the response object. Verify that you're getting back the data that you expect. It might be the case that your XPath is perfectly correct but the response is slightly different than what you expected.

Hope that helps. If you figure out more, post and maybe someone will have some other ideas.

ToddOs at 2007-9-4 > top of Msdn Tech,Gadgets,Web Gadget Development...
# 6
Thank you for the suggestions Todd0s! I tried looping through the items with innerHTML but it just returned the string undefined. I will try to figure out if it is text/xml or application/xml!
incendy at 2007-9-4 > top of Msdn Tech,Gadgets,Web Gadget Development...
# 7
Ok, Todd0s once I fixed my loop it did return the text of the items, but I still do not know what names are being returned for the containing nodes for my xpath. Is there a way to get the containing nodes text?
incendy at 2007-9-4 > top of Msdn Tech,Gadgets,Web Gadget Development...
# 8
ok, it shows it is text/xml, do I need to change anything to reflect this?
incendy at 2007-9-4 > top of Msdn Tech,Gadgets,Web Gadget Development...
# 9

This is the xml response I get when I monitor it with Firefox

<?xml version="1.0" encoding="UTF-8"?>

<ListLookupResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2005-03-23">

<OperationRequest>

<HTTPHeaders>

<Header Name="UserAgent"></Header>

</HTTPHeaders>

<RequestId>1G0ECBQNFKGRJ3JW17FM</RequestId>

<Arguments>

<Argument Name="XMLEscaping" Value="Single"></Argument>

<Argument Name="ListId" Value="241KH7V8OZ7EQ"></Argument>

<Argument Name="ContentType" Value="text/xml"></Argument

>

<Argument Name="Service" Value="AWSECommerceService"></Argument>

<Argument Name="SubscriptionId" Value="00HY838MXMEHFPKF50G2"></Argument>

<Argument Name="Version" Value="2005-03-23"></Argument>

<Argument Name="ResponseGroup" Value="ListItems"></Argument>

<Argument Name="ListType" Value="WishList"></Argument>

<Argument Name="Operation" Value="ListLookup"></Argument>

</Arguments>

<RequestProcessingTime>

0.123795986175537

</RequestProcessingTime>

</OperationRequest>

<Lists>

<Request>

<IsValid>True</IsValid>

<ListLookupRequest

>

<ListId>241KH7V8OZ7EQ</ListId>

<ListType>WishList</ListType>

<ResponseGroup>ListItems</ResponseGroup>

</ListLookupRequest>

</Request>

<List>

<ListId>241KH7V8OZ7EQ</ListId>

<ListName>Wishlist</ListName>

<TotalItems

>6</TotalItems>

<TotalPages>1</TotalPages>

<ListItem>

<ListItemId>I11OZ042934B72</ListItemId>

<DateAdded>2002-05-17</DateAdded>

<QuantityDesired>1</QuantityDesired>

<QuantityReceived>1</QuantityReceived>

<Item>

<ASIN>B00005AUJQ</ASIN>

<ItemAttributes>

<Title>Platoon (Special Edition)</Title>

</ItemAttributes>

</Item

>

</ListItem>

<ListItem>

<ListItemId>IEMOQ4BV55PEM</ListItemId>

<DateAdded>2004-12-02</DateAdded>

<QuantityDesired

>1</QuantityDesired>

<QuantityReceived>1</QuantityReceived>

<Item>

<ASIN>B0002Y0QV2</ASIN>

<ItemAttributes

>

<Title>Smallville - The Complete Third Season</Title>

</ItemAttributes>

</Item>

</ListItem>

<ListItem>

<ListItemId

>I2DKO0FLSYW5LS</ListItemId>

<DateAdded>2004-12-02</DateAdded>

<QuantityDesired>1</QuantityDesired>

<QuantityReceived

>1</QuantityReceived>

<Item>

<ASIN>B0002XVKMC</ASIN>

<ItemAttributes>

<Title>

Buffy the Vampire Slayer - The

Complete Seventh Season

</Title>

</ItemAttributes>

</Item>

</ListItem>

<ListItem>

<ListItemId>

IMSLCUHAXHQGU

</ListItemId>

<DateAdded>2004-12-02</DateAdded>

<QuantityDesired>1</QuantityDesired>

<QuantityReceived>

1

</QuantityReceived>

<Item>

<ASIN>1400052939</ASIN>

<ItemAttributes>

<Title>

The Hitchhiker's Guide to the

Galaxy, Deluxe 25th Anniversary Edition

</Title>

</ItemAttributes>

</Item>

</ListItem>

<ListItem>

<ListItemId

>I264IZVKJS0M0B</ListItemId>

<DateAdded>2004-12-02</DateAdded>

<QuantityDesired>1</QuantityDesired>

<QuantityReceived

>1</QuantityReceived>

<Item>

<ASIN>0064471195</ASIN>

<ItemAttributes>

<Title>

The Chronicles of Narnia Boxed

Set

</Title>

</ItemAttributes>

</Item>

</ListItem>

<ListItem>

<ListItemId>IP8MPLSRQZUBV</ListItemId>

<DateAdded

>2007-02-03</DateAdded>

<QuantityDesired>1</QuantityDesired>

<QuantityReceived>0</QuantityReceived>

<Item

>

<ASIN>B000JK4YS0</ASIN>

<ItemAttributes>

<Title>

Lensbaby 3G Selective Focus SLR Lens for Canon SLR Cameras

</Title>

</ItemAttributes>

</Item>

</ListItem>

</List>

</Lists>

</ListLookupResponse>

I can copy and paste this into an xml file and use xpath to query it just fine in Visual Studio:( So frustrating
incendy at 2007-9-4 > top of Msdn Tech,Gadgets,Web Gadget Development...
# 10

Finally got it to work... Seems something is wrong with the xml it returns although I cannot figure out what, but selectnodes does not work, however a workaround is to use getElementsByTagName

this is what I ended up using

var TESTxml = response.responseXML.documentElement;

var items = TESTxml.getElementsByTagName("Item");

incendy at 2007-9-4 > top of Msdn Tech,Gadgets,Web Gadget Development...