Hi, I have a trouble with XML Marshaling/Unmarshaling.
I want to convert between following XML and my struct.
Figure.1
<People>
<Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Student">
<ID>2222</ID>
<Name>Alice</Name>
</Person>
<Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Student">
<ID>3333</ID>
<Name>Bob</Name>
</Person>
</People>
Figure.2
type Person struct {
Xmlns_xsi string `xml:"xmlns xsi,attr,omitempty"`
Xsi_type string `xml:"http://www.w3.org/2001/XMLSchema-instance type,attr,omitempty"`
ID string `xml:",omitempty"`
Name string `xml:",omitempty"`
}
type People struct {
Person []Person `xml:"Person,omitempty"`
}
I could unmarshal perfectly. All values I wanted are in my Person struct.
But marshal didn't output format that I wanted to. I wanted xml like Figure.1
In Figure.3, many unintended attributes on Person element. ("_xmlns" ?)
Figure.3
What do I need to do to marsha/unmarshal such a XML?
Thanks.