package main
import (
"encoding/xml"
"fmt"
)
func main() {
type Email struct {
Where string `xml:",attr"`
Addr string
}
type Result struct {
Email []Email `xml:"email"`
}
v := Result{}
data := `
<person>
<email where="home">
<Addr>gre@example.com</Addr>
</email>
<email where='work'>
<Addr>gre@work.com</Addr>
</email>
</person>
`
err := xml.Unmarshal([]byte(data), &v)
if err != nil {
fmt.Printf("error: %v", err)
return
}
fmt.Printf("v: %#v\n", v)
}
No comments:
Post a Comment