XML is widely used as a data exchange and information transmission format. With the increasingly wide application of Web Services, XML plays an increasingly important role in daily development. This section describes the XML-related processing packages in the go language standard package. This section does not cover content related to XML specifications (for more information, see other documents), but describes how to use the go language to codec XML files. If you are an O & M engineer, you have generated the following xml configuration file for all the servers you manage: <? XML version = "1.0" encoding = "UTF-8"?>
Shanghai_vpn
127.0.0.1
Beijing_vpn
127.0.0.2
// Gotest Project main. gopackage mainimport ("encoding/XML" "FMT" "IO/ioutil" "OS") type recurlyservers struct {xmlname XML. name 'xml: "servers" 'version string' XML: "version, ATTR" 'svs [] server 'xml: "server" 'description string' XML :", innerxml "'} type server struct {xmlname XML. name 'xml: "server" 'servername string' XML: "servername" 'serverip string' XML: "serverip" '} func main () {file, err: = OS. open ("servers . Xml ") if Err! = Nil {FMT. println ("error: & V", err) return} data, err: = ioutil. readall (File) If Err! = Nil {FMT. println ("error & V", err) return} V: = recurlyservers {} err = xml. unmarshal (data, & V) If Err! = Nil {FMT. println ("error & V", err) return} FMT. println (v. xmlname) FMT. println (v. version) FMT. println ("--------------------") FMT. println (v. SVS [0]. servername) FMT. println (v. SVS [0]. serverip) FMT. println ("--------------------") FMT. println (v. SVS [1]. servername) FMT. println (v. SVS [1]. serverip )}