<GetCompetitivePricingForASINResult ASIN="0547569653" status="Success">
<Product xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd"
xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>ATVPDKIKX0DER</MarketplaceId>
<ASIN>0547569653</ASIN>
</MarketplaceASIN>
</Identifiers>
<CompetitivePricing>
<CompetitivePrices>
<CompetitivePrice belongsToRequester="false" condition="Used" subcondition="Good">
<CompetitivePriceId>2</CompetitivePriceId>
<Price>
<LandedPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>9.95</Amount>
</LandedPrice>
<ListingPrice>
<CurrencyCode>USD</CurrencyCode>
<Amount>9.95</Amount>
</ListingPrice>
<Shipping>
<CurrencyCode>USD</CurrencyCode>
<Amount>0.00</Amount>
</Shipping>
</Price>
</CompetitivePrice>
</CompetitivePrices>
<NumberOfOfferListings>
<OfferListingCount condition="Any">113</OfferListingCount>
<OfferListingCount condition="Used">72</OfferListingCount>
<OfferListingCount condition="New">41</OfferListingCount>
</NumberOfOfferListings>
</CompetitivePricing>
<SalesRankings>
<SalesRank>
<ProductCategoryId>book_display_on_website</ProductCategoryId>
<Rank>48661</Rank>
</SalesRank>
<SalesRank>
<ProductCategoryId>4209</ProductCategoryId>
<Rank>31</Rank>
</SalesRank>
<SalesRank>
<ProductCategoryId>6511974011</ProductCategoryId>
<Rank>65</Rank>
</SalesRank>
<SalesRank>
<ProductCategoryId>16587</ProductCategoryId>
<Rank>93</Rank>
</SalesRank>
</SalesRankings>
</Product>
</GetCompetitivePricingForASINResult>
I am trying to retrieve the "Rank" field only when the ProductCategoryId is equal to "book_display_on_website", however, in my current attempt it appears to set it Rank to the last SalesRank Entry (93) (it should be (48661)). Can someone point me in the right direction?
Is this even possible using this Unmarshal method? or is something like go-pkg-xmlx or gokogiri required? (I am coming from php and usually use simple_xml_parser on php for this type of stuff.)
type Data struct {
XMLName xml.Name `xml:"GetCompetitivePricingForASINResponse"`
Item []Item `xml:"GetCompetitivePricingForASINResult"`
}
type Item struct {
Pcat string `xml:"Product>SalesRankings>SalesRank>ProductCategoryId"`
ASIN string `xml:"ASIN,attr"`
Rank string `xml:"Product>SalesRankings>SalesRank>Rank"`
}
result, err := api.GetCompetitivePricingForASIN(asins)
if (err != nil) {
fmt.Println(err)
}
data := &Data{}
xml.Unmarshal([]byte(result), data)
if err != nil {
log.Fatal(err)
}
for i := 0; i < len(data.Item); i++ {
fmt.Printf("%s
", data.Item[i])
}