LINQ to XML and Amazon Webservices

Hi, I'm having a hard time in using LINQ on XML returned from Amazon 
Webservices.

I'm using the 2008 beta 2 on an XP machine.

the code I'm using is:

=========
        Dim s As String
        s = "http://ecs.amazonaws.com/onca/xml?" & _
                  "Service=AWSECommerceService&" & _
                  "AWSAccessKeyId=1234&" & _
                  "AssociateTag=my-tag&" & _
                  "ResponseGroup=Small&" & _
                  "Operation=ItemSearch&" & _
                  "SearchIndex=Music&" & _
                  "Keywords=neil young"
        Dim ResponseDoc As Linq.XDocument = XDocument.Load(s)
        Dim ReturnedItems = From ReturnedItem In 
ResponseDoc.Descendants("Item") _
                    Select ASIN = ReturnedItem.Element("ASIN").Value, _
                           URL = ReturnedItem.Element("DetailPageURL").Value

===========

ReturnedItems is always empty.

Am I doing something wrong?  Is Amazon XML wrong in some way?

thanks

Gil S.
-- 
They don''''t make bugs like bunny anymore
0
mudGil (2)
9/20/2007 3:06:01 PM
dotnet.xml 7266 articles. 0 followers. Follow

4 Replies
554 Views

Similar Articles

[PageSpeed] 42

mudGil wrote:
> Hi, I'm having a hard time in using LINQ on XML returned from Amazon 
> Webservices.
> 
> I'm using the 2008 beta 2 on an XP machine.
> 
> the code I'm using is:
> 
> =========
>         Dim s As String
>         s = "http://ecs.amazonaws.com/onca/xml?" & _
>                   "Service=AWSECommerceService&" & _
>                   "AWSAccessKeyId=1234&" & _
>                   "AssociateTag=my-tag&" & _
>                   "ResponseGroup=Small&" & _
>                   "Operation=ItemSearch&" & _
>                   "SearchIndex=Music&" & _
>                   "Keywords=neil young"
>         Dim ResponseDoc As Linq.XDocument = XDocument.Load(s)
>         Dim ReturnedItems = From ReturnedItem In 
> ResponseDoc.Descendants("Item") _
>                     Select ASIN = ReturnedItem.Element("ASIN").Value, _
>                            URL = ReturnedItem.Element("DetailPageURL").Value
> 
> ===========
> 
> ReturnedItems is always empty.
> 
> Am I doing something wrong?  Is Amazon XML wrong in some way?

Can you show us a sample of the XML you are trying to process? As the 
web service requires an access id it is easier to help you if you 
provide the XML sample.


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
9/20/2007 3:35:17 PM
mudGil wrote:

> Am I doing something wrong?  Is Amazon XML wrong in some way?

Those elements are in a namespace so one way with VB and LINQ is as 
follows, put the following two lines

Imports System.Xml.Linq
Imports 
<xmlns="http://webservices.amazon.com/AWSECommerceService/2005-10-05">

at the beginning of your program, then inside your program use the 
following syntax:

         Dim ResponseDoc As XDocument = XDocument.Load(s)
         Console.WriteLine(ResponseDoc.ToString())
         For Each item As XElement In ResponseDoc...<Item>
             Console.WriteLine("ASIN: {0}", item.<ASIN>.Value)
         Next


-- 

	Martin Honnen --- MVP XML
	http://JavaScript.FAQTs.com/
0
mahotrash (1778)
9/20/2007 3:57:33 PM
Hello mudGil,

Due to VS 2008 has not been final released so far, LINQ issue is not 
supported by MSDN Managed Newsgroup Team.
If you have issue related to LINQ, you may also post it in MSDN Forum,
http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=123&SiteID=1
The people in those groups will be more likely to be able to help and 
familiar in such field.

If you have any more concern, please also feel free to update here. It's my 
pleasure to assist you.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support 
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

0
v-wywang (104)
9/27/2007 9:03:53 AM
WenYuan Wang [MSFT] wrote:
> Hello mudGil,
> 
> Due to VS 2008 has not been final released so far, LINQ issue is not 
> supported by MSDN Managed Newsgroup Team.
> If you have issue related to LINQ, you may also post it in MSDN Forum,
> http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=123&SiteID=1
> The people in those groups will be more likely to be able to help and 
> familiar in such field.
> 
> If you have any more concern, please also feel free to update here. It's my 
> pleasure to assist you.
> 
> Have a great day,
> Best regards,
> 
> Wen Yuan
> Microsoft Online Community Support 
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
> 
Why did this happen to end up on my computer????????////
0
12/25/2007 3:08:02 AM
Reply:

Similar Artilces:

Working with XML Files in Dexterity
I have a lot of programming ahead of me (and behind me) working with XML, and I'm working exclusively with Dex (as I have been for 11 years). We need to do some some pretty serious and robust XML file exchanges for various types of transactions. There seems to be two ways to go about this in Dex: 1) going line-by-line looking at nodes with the "dataNode.childNodes.item..." functions, and maneuvering data types for EACH item in a table, For Example: dataNode = rootnodeDispatch.selectSingleNode("VehicleModel"); if not empty(dataNode) then NodeText = dataNode; dat...

Change the XML elements sequence
I export some database data to an XML file. How do I change the sequence of the elements (fields) appear in the XML document? For example, my XML output from TableA is: <TableA> <Field(0)> <Field(1)> <Field(2)> <Field(3)> </TableA> If I want to change the sequence of the fields to: <TableA> <Field(0)> <Field(3)> <Field(1)> <Field(2)> </TableA> Does anyone know what is the easiest way to do this without using "select" statement? (Because this example has been simplified for easier illustrat...

LINQ to XML - Performance
Hi, Can anyone tell me how the performance compares between working with xml documents in the normal way (i.e. with xpath and the System.Xml) and LINQ. Is it any quicker or slower? Are there are distinct benefits to the user (and not just advantages for the coder) to working with LINQ? The work i will be doing is creating an xml document out of segments from other xml documents, transforming the document (XSL) and then retrieving/amending/appending data to the document. Currentlly xml transformations in .net 2.0 are very slow and performance takes a real hit with complex transforms. ...

XML Inheritance
I posted this message yesterday on a different group which may have been the wrong group, so I am not cross posting on purpose. Hi, I have a question regarding how the .Net framework interprets schema definitions based on existing types. I have (for the purposes of demonstration) a very simple types schema which contains some PersonName (T_PERSONNAME) and Address (T_ADDRESS) details as below. <?xml version="1.0" encoding="utf-16" ?> - <xs:schema xmlns=http://com.test.schemas.BaseTypes xmlns:b="http://schemas.microsoft.com/BizTalk/2003" ...

Generete an XML instance from its XSD
Hi Is there a way to generate in code an empty instance of an XML from it's XSD? I have a lot of schemas and I want at run time to create an empty instance for them (I then have to fill one or two fields). Shahar Shahar Ron wrote: > Is there a way to generate in code an empty instance of an XML from it's XSD? > I have a lot of schemas and I want at run time to create an empty instance > for them (I then have to fill one or two fields). Check out this article <URL:http://msdn2.microsoft.com/en-us/library/aa302296.aspx> which has code to create a sample documen...

How to MoveFirst, MoveNext, MovePrevious, MoveLast in LinQ To XMl Please Help
I have the Next XML var xml = new XElement( "clients", new XElement("client", new XAttribute("id",1), new XElement( "name", "Luis"), new XElement( "country", "Portugal") ), new XElement("client", new XAttribute("id",2), n...

Linq or dictionary
Hi, I am pretty new to Linq and I am not quite sure when it is best to use it and when other methods might be preferable. For example, I need to create a list of Sample objects which I then access by the SampleName property of each sample. The way I have generally done this would be with a Dictionary<string, Sample>, but instead I can use a List<Sample> and access using linq. I don't know which would be preferable. Any thoughts? I have example code below. Thanks! Ethan With Dictionary Dictionary<string, Sample> samples = new Dictionary<strin...

how to write some xml into huge xml file into speceific location???
Hello! Is anyone can help me to figure out how to write some xml into huge xml file into speceific location??? Say, i have a file about 139 Mb and i need to write some data (xml) into it, but in speceific location (specified by XPath for example). i have tryed used MSXML dom for it, but its eats memory like a twice bigger then my file. Is any way to do that without that hurt? thank you, Xenia. Xenia wrote: > Is anyone can help me to figure out how to write some xml into huge xml file > into speceific location??? > > Say, i have a file about 139 Mb and i need to write some d...

XML/DTD interpreted display...
Is there control in VB2005 (VS8.0) that can display & allow editing of mixed content XML as defined in specified DTD WYSIWYG style??? Thanks in Advance... -- Timothy Casey GPEMC! >> 11950 is the number@fieldcraft.com.au 2email Terms & conditions apply. See www.fieldcraft.biz/GPEMC Discover valid interoperable web menus, IE security, TSR Control, & the most advanced speed reading application @ www.fieldcraft.biz Number 11950 - GPEMC! Replace number with 11950 wrote: > Is there control in VB2005 (VS8.0) that can display & allow editing of mixed > cont...

Question about XML schema and blank element
Hey there, I'm running into an issue and wondered if any of you XML gurus know a solution. I'm currently using XML as a data transport mechanism between two applications and an XML schema for format validating purposes. Whenever I have an child element that is nested inside another element, the child element must not be empty or I get the following error message: "'Element' is an invalid node type." I've worked around this by adding a filler element as the first child element with junk as the inner text. The error only occurs if the FIRST child element is empt...

Linq to BindingList
Hello. How can I send the result of a LINQ query to a BindingList? I say not to do this: <Customer> List lst = (from cust in select new dataContext.Customer Customer (cust)). ToList <Customer> (); foreach (Customer c in lst) lbindingListCust.Add (c); Any ideas? ...

Import data from webservice
I've got a web service and I'm looking for a way for my users to easily consume those services in Excel. So..after scanning the Excel help and visiting MSDN I'm still stumped. How do you do it without having to write VBA code? Steven "Steven Doka" <stevendoka@comcast.net> wrote... >I've got a web service and I'm looking for a way for my users to >easily consume those services in Excel. So..after scanning the >Excel help and visiting MSDN I'm still stumped. How do you do it >without having to write VBA code? I believe you'd need...

XML Custom serialization
Hi all, I want to serialize a class in a customized way. But I don't want to implement the ISerializable interafce because I don't want to take care of every new field I insert to the class. What I need is a way to customize the serialization of a specific field in my class but leave the rest to the build-in serialization. Any guidance will be appreciated. Ro'ee <sfa.roy@gmail.com> wrote in message news:7243a1eb-3fa3-43e0-8339-d90f890e6716@b1g2000hsg.googlegroups.com... > Hi all, > > I want to serialize a class in a customized way. But I don't want to >...

populate a DataSet via a LINQ query (Linq to XML)
Is there a way to populate a DataSet via a LINQ query? (Linq to XML) Instead of; DataSet ds = new DataSet(); ds.ReadXml(myfile.xml, XmlReadMode.InferTypedSchema); dataGridView1.DataSource = ds.DefaultViewManager; dataGridView1.DataMember = "myNode"; Anthony Anthony wrote: > Is there a way to populate a DataSet via a LINQ query? > > (Linq to XML) > > Instead of; > DataSet ds = new DataSet(); > ds.ReadXml(myfile.xml, XmlReadMode.InferTypedSchema); > dataGridView1.DataSource = ds.DefaultViewManage...

importing XML doc into SQL Server
Hello, I am trying to import an XML document into SQL Server. I have tried DTS, bulk loading into SQL server and anything else I can think of... The only thing that has worked slightly is : Dim objSQLConn As New SqlConnection(Constants.ConnectionString) Dim objAdapter As SqlDataAdapter Dim objDataRow, objDBRow As DataRow Dim objDSXML As New DataSet() Dim child As Xml.XmlNode Dim objDSDBTable As New DataSet("tblStandardstest") Dim ObjCmdBuilder As SqlCommandBuilder objDSXML.ReadXml("c:/inetpub/wwwroot/olpt7/ACH_STATE_SUBJECT_Ohio_2001_Engli sh.xml") objSQLConn.Open(...

Need Linq Help
I need linq help. I have a dictionary where the keys are strings and I need to select from that dictionary into another dictionary where the first two characters of the key match a parameter. For exmaple here is the code: Dictionary<string, string> origDict =3D new Dictionary<string, string>(); origDict.Add(""BSOne", "1") origDict.Add(""BSTwo", "2") origDict.Add(""PLOne", "11") origDict.Add(""PLTwo", "22") I need to select into a new dictionary only where the keys star...

Linq to XML?
I have five items of information I need to extract from XML covering upwards of 25 separate devices. I'm obtaining these values via five Linq to XML queries as follows: IEnumerable<string> EIDs = (from env in xdoc.Root.Elements("packet"). Elements(ns1 + "data").Elements(ns2 + "server_group"). Elements(ns2 + "env") select (string)env.Element(ns3 + "eid")); IEnumerable<int> IDs = (from env in xdoc.Root.Elements("packet"). Elements(ns1 + "data").Elem...

xml into collections
Hi all, we have an xml file. Based on this file we have to generate menu. This xml file changes every day. We are loading the xml file into the application memory and transforming the data of xml file into collections (using classes). 1. Pumping the whole xml data into collections is the correct way or not? 2. As xml is already a structured representation of data, is it necessary to convert the data into collections? 3. If we converted the data into collections, is it true we can get better performance rather than querying the xml everytime? 4. Querying the xml everytime consumes more ti...

Linq query
Hello, I have the following list: IList<Int32> roles = { 1, 2, 3 } I need to get all users where in user.Roles there is at least one Role which is id 1, 2 OR 3. var a = users.Where(u => u.Roles. ??? ); How can I do this? Thanks, Miguel shapper wrote: > I have the following list: > > IList<Int32> roles = { 1, 2, 3 } > > I need to get all users where in user.Roles there is at least one Role > which is id 1, 2 OR 3. > var a = users.Where(u => u.Roles. ??? ); users.Where(u => u.Roles.Any(r => roles.Contains(r))) ass...

An XML question
I would like to produce the following output based on my XML file: My Album (2005) Elapsed Time (hh:mm:ss): 00:07:00 Song 1: title1 Length (hh:mm:ss): 00:02:30 Song 2: title2 Length (hh:mm:ss): 00:02:15 Song 3: title3 Length (hh:mm:ss): 00:02:15 ===== <album> <general> <title>My Album</title> <year>2005</year> </general> <content> <song> <songTitle>title1</songTitle> <songLengthInSeconds>150</songLengthInSeconds> </song> <song> <...

Generating XML from Excel
Hello, I have a question about how to use the XML export functionality in Excel 2003. I have a schema that I am using to map to colmns in Excel. That works great and I can export in a basic test. The problem comes in when I try to add in columns that should be child nodes of the existing row. I am not sure if I am using all the correct terminology. Here is an example. If you have a spreadsheet as follows: Name ID Hair Color CName VName CName VName Ted 1 Brown Level Mgr Area 12 I need the XML to map to: <user> <name>Ted</nam...

Export PO's in XML format
We have a number of Dynamics GP Standard clients who would like to export their PO's to two of their main suppliers. The XML format is standardized for each supplier and the end users could live wth emailing the xml files. It sounds like econnect will enable it but it also sounds like that program is pretty long on complexity, and short on documentation and support. Sounds easier to juts make a report in Crystal and export in their built in XML. XML formating in report writer would be ideal as we could avoid dealing with another software product installation and updates. Any sugge...

LINQ to XML
This is my XML file: <?xml version="1.0" encoding="utf-8" ?> <Profiles xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.mycompany.com/MyApp/2010/03/MySchema"> <Profile id="0" name="MyProfileName1"> <Entity name="EntityName1" type="EntityTypeName1"> <Shared> <Property name="SharedPropertyName1" type="SharedPropertyType1" /> <Property name="SharedPropertyName2" type="SharedPropert...

RE: LINQ to XML and Amazon Webservices
I am not able to reply to my previous thread wich had the same title, so here goes: I added the namespace which made no difference. There are no prefixes in the XML, which I'm posting below, so I've asumed no need for namespace. Am I wrong? Anyway, this has become very strange. When I use the loop Martin has suggested, it never executed - so ResponseDoc...<Item> is an empty list, or collection. When I do > For Each item As XElement In ResponseDoc...<ASIN> > Console.WriteLine("ASIN: {0}", item.Value) > Next I do ...

XML file width
I'm converting a 1MB bitmap file into base64 encoding..and saving into an xml file. the xml file and everything works perfectly...except when i open the xml file in a viewer I get errors becuase the file is written to just one line with no coluumn width etc? how can I ensure the xml writer in vb.net spits out beautifully formatted xml code like the access 2003 etc..?? with my 1MB <image> tag spread over thousands of lines 80 chars wide instead of just 1 long line that crashes any text editor...? cheers Simon Simon wrote: > I'm converting a 1MB bitmap file into b...