packagemainimport("encoding/xml""fmt""io/ioutil""os")typeNamestruct{XMLNamexml.Name`xml:"DomainCheckResult"`Domainstring`xml:"Domain"`Availablestring`xml:"Available"`ErrorNostring`xml:"ErrorNo"`}typeNamesstruct{XMLNamexml.Name`xml:"CommandResponse"`Domains[]Name`xml:"DomainCheckResult"`}funcmain(){xmlFile,err:=os.Open("data.xml")iferr!=nil{fmt.Println(err)os.Exit(1)}deferxmlFile.Close()XMLdata,_:=ioutil.ReadAll(xmlFile)iferr!=nil{fmt.Println(err)os.Exit(1)}vardNamesxml.Unmarshal(XMLdata,&d)fmt.Println(d.Domains)}XMLFile:namecheap.domains.check PHX01SBAPI01 --4:00 1.668 Output:[{{DomainCheckResult}}{{DomainCheckResult}}]
相关分类