I am trying to parse a piece if XML in Go:
package main
import (
"encoding/xml"
"fmt"
)
type XML struct {
Foo string `xml:"foo"`
}
func main() {
rawXML := []byte(`
<xml>
<foo>A</foo>
<ns:foo>B</ns:foo>
</xml>`)
x := new(XML)
xml.Unmarshal(rawXML, x)
fmt.Printf("foo: %s\n", x.Foo)
}
This outputs:
foo: B
While I expected it to produce:
foo: A
How do I get content of the first foo
tag (i.e. one without namespace)?