How to map an xml sequence of mixed elements to a go struct?



'm trying to load an XML file that contains an unbounded sequence of mixed elements (a choice in a sequence in the XSD) The file looks like that :



<RootNode>
<ElementB>...</ElementB>
<ElementA>...</ElementA>
<ElementA>...</ElementA>
<ElementC>...</ElementC>
<ElementB>...</ElementB>
<ElementA>...</ElementA>
<ElementB>...</ElementB>
</RootNode>


I use xml.Unmarshal to initialize and fill these structs :



type RootNode struct {
ElementA []ElementA
ElementB []ElementB
ElementC []ElementC
}

type ElementA struct {
}

type ElementB struct {
}

type ElementC struct {
}


I have working exemple here http://ift.tt/1Avrvjy. The problem is that i need to know the index of the elements in the original sequence. And with that description, this info is lost.


Is there a way to to load elements of type ElementA, ElementB or ElementC in the same array ? More generally, what is the best way to map a list of mixed elements to a go struct ?


No comments:

Post a Comment