This is a creation in Article, where the information may have evolved or changed.
Studygolang.xml
<?xml version= "1.0" encoding= "Utf-8"?>
<persons>
<person name= "polaris" age= ">"
<career> Bum </career>
<interests>
<interest> Programming </interest>
<interest> Chess </interest>
</interests>
</person>
</persons>
Package Main
Import (
"Encoding/xml"
"Io/ioutil"
"Log"
)
Type Result struct {
person []person ' xml: ' person ' '
}
Type person struct {
Name string ' xml: ' name,attr '
Age int ' xml: "Age,attr" '
Career string ' xml: ' career '
Interests Interests ' XML: "Interests"
}
Type interests struct {
Interest []string ' xml: "Interest" '
}
Func (Person *person) Chkis18 () (flag bool) {
If person. Age > 18 {
Flag = True
}
Return flag
}
Type Checker Interface {
CHKIS18 () (flag bool)
}
Func Main () {
Content, Err: = Ioutil. ReadFile ("Studygolang.xml")
If err! = Nil {
Log. Fatal (ERR)
}
var result result
Err = XML. Unmarshal (content, &result)
If err! = Nil {
Log. Fatal (ERR)
}
A: = "AAAA"
Log. Println (result. person)
}