I want to parse the attribute of an Xml file.
It works for any "normal" attributes like for instance <application name="AppName">
But I can't manage to retrieve the value of the attribute if it has a ":" in it., like <application name:test="AppName">
Here is the code that I am using to parse this :
package main
import "fmt"
import "encoding/xml"
type Application struct {
Event Event `xml:"application"`
Package string `xml:"package,attr"`
}
type Event struct {
IsValid string `xml:"test:isValid,attr"`
}
var doc = []byte(`<?xml version="1.0" encoding="utf-8" standalone="no"?>
<application package="leNomDuPackage">
<event test:isValid="true">
</application>
</manifest>`)
func main() {
application := Application{}
xml.Unmarshal(doc, &application)
fmt.Println("Application: ", application)
fmt.Println("isValid:", application.Event)
}
You can find it on the Golang playground as well : [https://play.golang.org/p/R6H80xPezhm
I want to retrieve the value of the isValid
attribute.
At the moment, I have that error message and I can't manage to solve it.
struct field tag
xml:"test\:isValid,attr
not compatible with reflect.StructTag.Get: bad syntax for struct tag value
I tried as well with the following value of
type Event struct {
IsValid string `xml:"test isValid,attr`
}
and
type Event struct {
IsValid string `xml:"test\:isValid,attr`
}
But it is not working as well.