I would like to be able to tag my struct without it needing to know what level it will be nested into an XML document. In other words, I want to be able to write:
type Elem struct {
Datum string `xml:"datum"`
}
And have it work for both
<elem>
<datum>Hello</datum>
</elem>
And
<list>
<elem>
<datum>Hello</datum>
</elem>
</list>
However, in order for the latter example to work (when attempting to decode into a []Elem
), I need to use the tag xml:"elem>datum"
, which decodes incorrectly for the first example. Is there a way for me to define an XML tag without knowing how the struct will be embedded? See here for a simple example: