Just get it like every other attribute:
type App struct {
XS string `xml:"xs,attr"`
}
Playground: http://play.golang.org/p/2IOmkX1Jov.
It gets trickier if you also have an actual xs
attribute, sans xmlns
. Even if you add the namespace URI to XS
's tag, you will probably get an error.
EDIT: If you want to get all declared namespaces, you can define a custom UnmarshalXML
on your element and scan it's attributes:
type App struct {
Namespaces map[string]string
Foo int `xml:"foo"`
}
func (a *App) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
a.Namespaces = map[string]string{}
for _, attr := range start.Attr {
if attr.Name.Space == "xmlns" {
a.Namespaces[attr.Name.Local] = attr.Value
}
}
// Go on with unmarshalling.
type app App
aa := (*app)(a)
return d.DecodeElement(aa, &start)
}
Playground: http://play.golang.org/p/u4RJBG3_jW.