I want to check if an submitted xml file is a valid xml or not so I check if it can be parsed. I do it like that:
const EmptyXml = `<?xml xmlns="http://www.w3.org/1999/xhtml"?>`
func CanParse(xmlData string) (bool, error) {
if strings.TrimSpace(xmlData) == "" {
return false, nil
}
type Tag struct {
XMLName xml.Name
Content string `xml:",innerxml"`
}
type Object struct {
Items []Tag `xml:",any"`
}
var o *Object
err := xml.Unmarshal([]byte(xmlData), &o)
if err != nil {
return false, err
} else {
return true, nil
}
}
Sadly I end up with an error: unexpected EOF. Why is this?
Actually the method did work a month ago, and golang has not been updated since then so I´m still about to figure out what broke the method