I'm trying to Unmarshal multiple XML files that have differing top level 
elements but the rest of the document is identical.

<espFlowCodeEvent active="true" start="f75c9a3c-db56-43c7-a2e3-2229bd5011fa"
>
...
</espFlowCodeEvent>


<espAROperation active="true" start="e56eacc8-ace1-43a3-b831-73a930245aa6">
...
</espAROperation>


I have tried adding multiple tags in the struct but it only ever uses the 
first one.


type EspFlowCodeOperation struct {
        XMLName     xml.Name `xml:"espFlowCodeOperation" 
xml:"espBPMOperation" xml:"espFlowCodeEvent" xml:"espAROperation"`
        ...
}

This only picks up the first element espFlowCodeOperation, I get this error.

expected element type <espFlowCodeOperation> but have <espBPMOperation>


I was forced to create an individual struct for each and then try 
Unmarshaling it 4 times for each type checking the errors and falling 
through if it matches one of the xml documents I want as there are lots of 
other xml files mixed in that I expect to fail to parse.

flowcode := EspFlowCodeOperation{}
err = xml.Unmarshal([]byte(b), &flowcode)
        if err != nil {
                if strings.Contains(err.Error(), "espFlowCodeEvent") || 
strings.Contains(err.Error(), "espBPMOperation") || strings.Contains(err.
Error(), "espAROperation") || strings.Contains(err.Error(), 
"espFlowCodeOperation") {
                } else {
                        fmt.Println(err)
                }


        } else {
                      .....
}


There has to be a better way to do this, any suggestions ?

-- 
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