This is a creation in Article, where the information may have evolved or changed.
Package Mainimport ("OS" "IO" "FMT" "Encoding/xml" "StrConv") type Config Map[string]map[string]stringvar C Onfig = Make (Config) type Class struct {xmlname XML. Name ' xml: ' class ' '//xml element name Id int ' xml: ' id,attr ' '///Pers []persion ' xml: ' persion ' '// Desc string ' xml: ', InnerXml '//}type persion struct {xmlname XML. Name ' xml: ' persion ' ' Id int ' xml: ' id,attr ' ' name string ' xml: ' name ' ' Age int ' xml: ' Age "'}func (self *config) loadxmlfile (filename, node string) error{fd, err: = OS. Open (filename) If err! = nil{return err} defer FD. Close () return self. Load (FD, node)}func (self *config) load (r io. Reader, node String) error {Mynode: = False If _, OK: = (*self) [node];!ok {(*self) [node] = make (map[string ]string)} Decoder: = XML. Newdecoder (r) for {token, err: = decoder. Token () if err! = Nil {if Err. Error () = = "EOF" { Break} return Err} switch Value: = token. (type) {Case XML.} Startelement:switch {case value. Name.local = = Node:mynode = True case Mynode = = TRUE:TB , err: = decoder. Token () if err! = Nil {Continue} Switch TV: = TB. (type) {Case XML.} Chardata: (*self) [Node][value. Name.local] = string (TV)}} case XML. Endelement:if value. name.local = = node{Mynode = False}}} return Nil}func main () {var ps = Make ([]persion, 0) for I: = 0; I < 5; i++ {var TP persion TP. Id = i tp. Name = "Persion" + StrConv. Itoa (i) TP. Age = + I PS = AppEnd (PS,TP)} var c = class{id:1, pers:ps} var res, _ = XML. Marshalindent (C, "", "") fmt. Println (c) fmt. Println (String (res)) config. Loadxmlfile ("config +", "global") fmt. Println (config)}