xml.Unmarshal error: "expected element type <Item> but have <Items>"

go

Solution

This works for me (note the `Items>Item`):

type Result struct {
XMLName       xml.Name `xml:"ItemSearchResponse"`
Products      []Product `xml:"Items>Item"`
}

type Product struct {
    ASIN   string `xml:"ASIN"`
}

Problem

I'm trying to unmarshal the following XML, but am receiving an error. ``` <ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"> <Items> <Item> <ASIN>B005XSS8VC</ASIN> </Item> </Items> ``` Here are my structs: ``` type Product struct { XMLName xml.Name `xml:"Item"` ASIN string } type Result struct { XMLName xml.Name `xml:"ItemSearchResponse"` Products []Product `xml:"Items"` } ``` The text of the error is "expected element type `<Item>` but have `<Items>`," but I can't see where I'm going wrong. Any help is appreciated. ``` v := &Result{Products: nil} err = xml.Unmarshal(xmlBody, v) ```

Original source