Skip to content

Instantly share code, notes, and snippets.

@kalbasit
Created Mar 30, 2015
Embed
What would you like to do?
package main
import (
"encoding/xml"
"fmt"
)
const data = `
<?xml version="1.0" encoding="UTF-8"?>
<liverailapi requested="/order/line/list" api_version="4.11.1">
<lines>
<line>
<order_id>123</order_id>
</line>
<line>
<order_id>456</order_id>
</line>
</lines>
</liverailapi>
`
type OrderLinesResponse struct {
XMLName xml.Name `xml:"liverailapi"`
OrderLines []OrderLine `xml:"lines>line"`
}
type OrderLine struct {
OrderId int `xml:"order_id"`
}
func main() {
var v OrderLinesResponse
if err := xml.Unmarshal([]byte(data), &v); err != nil {
panic(err)
}
for _, o := range v.OrderLines {
fmt.Printf("%p: %#v\n", &o, o)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment