将XML解组为struct

I have this xml file and i it seems i cant unmarshal any data into a struct. Someone can help me out here. Its just i never used xml before, always prefered json before xml. Just edited this post with my code and it still gives me empty struct values

<Envelope>
<Data>
        <Order>
            <DeliveryData>
                <del_country>BELGIQUE/BELGIE</del_country>
                <del_country_code>BE</del_country_code>
                <del_company>False</del_company>
                <del_name>ADAM</del_name>
                <del_contact></del_contact>
                <del_firstName></del_firstName>
                <del_addressLine1>Durasweg 33</del_addressLine1>
                <del_addressLine2></del_addressLine2>
                <del_areaCode>1000</del_areaCode>
                <del_city>BRUXELLES</del_city>
                <del_country>BE</del_country>
                <del_language>FR</del_language>
                <del_modeCode>71</del_modeCode>
                <phone1>0032872180808</phone1> 
                <email></email>
                <inv_third>438802</inv_third>
                <OrderID>15787978</OrderID>
                <ParcelID>NE1578797801</ParcelID>
                <OrderDate>16/09/2014 14:22:54</OrderDate>
                <Shipping_date>16/09/2014 14:26:55</Shipping_date>
            </DeliveryData>
    </Order>
  </Data>

 type DeliveryData struct {
    XMLName xml.Name `xml:"DeliveryData"`
    Country string   `xml:"del_country"`
}

type Envelope struct {
    XMLName xml.Name `xml:"Envelope"`
    Data    Data     `xml:"Data"`
}

type Data struct {
    XMLName xml.Name `xml:Data`
    Orders  []Order  `xml:Order`
}

type Order struct {
    XMLName      xml.Name     `xml:"Order"`
    DeliveryData DeliveryData `xml:"DeliveryData"`
}

There are two reasons:

  1. Your XML is malformed - you should add a closing </Envelope>.
  2. Your struct tags in Data are malformed – they don't quote the name of the attribute - this means the the XML deserializer looks for an 'Order' field, instead of the Orders field.

For good measure: you can find a fully working example on http://play.golang.org/p/6-odOcSOnF

The relevant part is my

type Data struct {
    XMLName xml.Name `xml:"Data"`
    Orders  []Order  `xml:"Order"`
}

versus your original

type Data struct {
    XMLName xml.Name `xml:Data`
    Orders  []Order  `xml:Order`
}

Adding to @publysher's answer, you don't actually need to have so many structs, you just need 2:

type Data struct {
    XMLName xml.Name       `xml:"Envelope"`
    Data  []Fields `xml:"Data>Order>DeliveryData"`
}

type Fields struct {
    Country string   `xml:"del_country"`
    OrderID uint64
}

then you can unmarshal your xml (after you fix it of course like @publysher pointed out):

var data Data
err := xml.Unmarshal([]byte(serialized), &data)
if err != nil {
    fmt.Println(err)
    return
}