Unable to parse xml in GO with : in tags -


i find if tags in xml file have : in them unmarshal code in go not seem work. insights ?

for example, in xml file below, summary works not cevent.

<summary>...air quality alert </summary> <cap:event>air quality alert</cap:event> 
type entry struct{     summary    string   `xml:"summary"`     cevent     string   `xml:"cap:event"` } 

cap namespace identifier, not part of tag name. here shorthand urn:oasis:names:tc:emergency:cap:1.1

(this answer looks may have condensed explanation of namespaces: what "xmlns" in xml mean?)

the go "encoding/xml" package not handle namespaces well, if there no conflicting tags, can elide namespace altogether

type entry struct {     summary string `xml:"summary"`     event   string `xml:"event"` } 

the proper way specify event, in case of identical tags in different namespaces, full namespace like:

type entry struct {     summary string `xml:"summary"`     event   string `xml:"urn:oasis:names:tc:emergency:cap:1.1 event"` } 

here's working example: https://play.golang.org/p/ry55f2pwky


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -