Roshawn wrote:
@Martin,
Thanks for the reply. Here is a sample of the xml I'm working with:
<ItemSearchResponse
xmlns="http://webservices.amazon.com/AWSECommerceService/2005-10-05">
<OperationRequest>
<HTTPHeaders>
<Header Name="UserAgent" Value="IE">
</Header>
</HTTPHeaders>
</OperationRequest>
<Items>
<Item>
<ASIN>B000VFN934</ASIN>
<SmallImage>
<URL>http://ecx.images-amazon.com/images/I/419iznuXv1L._SL75_.jpg</URL>
<Height Units="pixels">75</Height>
<Width Units="pixels">75</Width>
</SmallImage>
<ItemAttributes>
<ListPrice>
<Amount>21800</Amount>
<CurrencyCode>USD</CurrencyCode>
<FormattedPrice>$218.00</FormattedPrice>
</ListPrice>
<Title>Arturo Italian Leather Triple Compartment Tote</Title>
</ItemAttributes>
</Item>
<Item>
<ASIN>B001534CZA</ASIN>
<SmallImage>
<URL>http://ecx.images-amazon.com/images/I/51Nw9o2xGGL._SL75_.jpg</URL>
<Height Units="pixels">41</Height>
<Width Units="pixels">75</Width>
</SmallImage>
<ItemAttributes>
<ListPrice>
<Amount>3600</Amount>
<CurrencyCode>USD</CurrencyCode>
<FormattedPrice>$36.00</FormattedPrice>
</ListPrice>
<Title>La Regale Satin Beaded Shoulder Clutch</Title>
</ItemAttributes>
</Item>
<Item>
<ASIN>B000VFS7UY</ASIN>
<SmallImage>
<URL>http://ecx.images-amazon.com/images/I/41B2pi7FRgL._SL75_.jpg</URL>
<Height Units="pixels">75</Height>
<Width Units="pixels">75</Width>
</SmallImage>
<ItemAttributes>
<ListPrice>
<Amount>3200</Amount>
<CurrencyCode>USD</CurrencyCode>
<FormattedPrice>$32.00</FormattedPrice>
</ListPrice>
<Title>La Regale Beaded Satin Flap Clutch</Title>
</ItemAttributes>
</Item>
<Item>
<ASIN>B000090LU3</ASIN>
<SmallImage>
<URL>http://ecx.images-amazon.com/images/I/31BN7EGXaLL._SL75_.jpg</URL>
<Height Units="pixels">75</Height>
<Width Units="pixels">75</Width>
</SmallImage>
<ItemAttributes>
<Title>Fontanelli Heart Shape Italian Polished Leather
Handbag</Title>
</ItemAttributes>
<OfferSummary>
<LowestNewPrice>
<Amount>21300</Amount>
<CurrencyCode>USD</CurrencyCode>
<FormattedPrice>$213.00</FormattedPrice>
</LowestNewPrice>
<TotalNew>1</TotalNew>
<TotalUsed>0</TotalUsed>
<TotalCollectible>0</TotalCollectible>
<TotalRefurbished>0</TotalRefurbished>
</OfferSummary>
<Offers>
<Offer>
<OfferListing>
<Price>
<Amount>21300</Amount>
<CurrencyCode>USD</CurrencyCode>
<FormattedPrice>$213.00</FormattedPrice>
</Price>
</OfferListing>
</Offer>
</Offers>
</Item>
</Items>
</ItemSearchResponse>
Here is a query that works with your sample:
Dim responseDoc As XDocument = XDocument.Load("..\..\XMLFile1.xml")
Dim query = _
From nd In responseDoc...<Item_
Let listPrice = nd.<ItemAttributes>.<ListPrice>(0) _
Let offers = nd.<Offers>(0) _
Select New With { _
.ASIN = nd.<ASIN>.Value, _
.Image = nd.<SmallImage>.<URL>.Value, _
.Title = nd.<ItemAttributes>.<Title>.Value, _
.ListPrice = TestPrice(listPrice), _
.OurPrice = TestOffers(offers)}
For Each item In query
Console.WriteLine("ASIN: {0}, Image: {1}, Title: {2},
ListPrice: {3}, OurPrice: {4}", item.ASIN, item.Image, item.Title,
item.ListPrice, item.OurPrice)
Next
The functions TestPrice and TestOffers look as follows:
Private Function TestPrice(ByVal element As XElement) As String
If element IsNot Nothing Then
Return element.<FormattedPrice>.Value
Else
Return "no data"
End If
End Function
Private Function TestOffers(ByVal element As XElement) As String
If element IsNot Nothing Then
Return
element.<Offer>.<OfferListing>.<Price>.<FormattedP rice>.Value
Else
Return "no data"
End If
End Function
End Module
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/