I need to get XML string with ordered elements from structs with unordered fields.
There is main struct:
type Person struct {
Name string
Age int
OtherData interface{}
}
And there are also a great many other structs, such as:
type SomeStruct1 struct {
Job string
Hobby string
}
type SomeStruct2 struct {
SkillName string
SkillValue int
*SomeStruct3
}
These structs can have other embedded structs.
I get structs like this:
sample := &Person{}
sample.Name = "Vasya"
sample.Age = 35
sample.OtherData = SomeStruct1{"programmer", "driving"}
Then I need to get XML with elements ordered by their names:
<Person>
<Age>35</Age>
<Name>Vasya</Name>
<OtherData>
<Hobby>driving</Hobby>
<Job>programmer</Job>
</OtherData>
</Person>