Go解析XML出错,求指点?

packagemain
import(
"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)
}
vardNames
xml.Unmarshal(XMLdata,&d)
fmt.Println(d.Domains)
}
XMLFile:
namecheap.domains.check
PHX01SBAPI01
--4:00
1.668
Output:
[{{DomainCheckResult}}{{DomainCheckResult}}]
慕森王
浏览 397回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript