Thanks for the response. I was hoping it would be possible with just 
xml.Unmarshal.

I now have this implementation - any comments on that? (I'm okay with 
returning the error inline, it's just for logging purposes):

Playground: https://play.golang.org/p/6J8XndWdlv_N

func id2(axl []byte) string {
dec := xml.NewDecoder(bytes.NewReader(axl))
for {
tok, err := dec.Token()
if err != nil {
if err == io.EOF {
return "token not found"
}
return fmt.Sprintf("error decoding XML: %v", err)

}
if tok, ok := tok.(xml.StartElement); ok {
if tok.Name.Local == "return" {
var id string
err := dec.DecodeElement(&id, &tok)
if err != nil {
return fmt.Sprintf("error decoding return element: %v", err)
}
return id
}
}
}
}



Am Samstag, 23. Februar 2019 20:53:07 UTC+1 schrieb Tamás Gulácsi:
>
> Walk over it usin xml.Decoder.Token, and UnmarshalElement when found a 
> StartToken with a proper Name.Local.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to