【发布时间】:2019-04-27 19:07:49
【问题描述】:
我是 Go 新手,我正在尝试验证 XML,但我做不到。以下是我尝试过的,但它不起作用。有什么办法吗。
func ParseXml(xml_path string) {
xmlFile, err := os.Open(xml_path)
if err != nil {
panic(err)
}
// defer the closing of our xmlFile so that we can parse it later on
defer xmlFile.Close()
// read our opened xmlFile1 as a byte array. here I am checking if the file is valid or not
byteValue, err := ioutil.ReadAll(xmlFile)
if err != nil {
panic(fmt.Sprintf("%s file reading failed \n",xml_path))
}
}
虽然我传递了一个无效的 XML 文件,但之后我并没有感到恐慌
byteValue, err := ioutil.ReadAll(xmlFile)
【问题讨论】:
-
请包括所有相关的错误信息。如果您没有收到错误,您期望的输出是什么,您会看到什么?
标签: xml validation go xml-parsing