There is an example in the Go documentation for xml: Unmarshal that cancels this xml
<Person> <FullName>Grace R. Emlin</FullName> <Company>Example Inc.</Company> <Email where="home"> <Addr> gre@example.com </Addr> </Email> <Email where='work'> <Addr> gre@work.com </Addr> </Email> <Group> <Value>Friends</Value> <Value>Squash</Value> </Group> <City>Hanga Roa</City> <State>Easter Island</State> </Person>
using these structures
type Address struct { City, State string } type Result struct { XMLName xml.Name `xml:"Person"` Name string `xml:"FullName"` Phone string Email []Email Groups []string `xml:"Group>Value"` Address }
Note that Result contains a link to a separately defined Address . Obviously this code works.
When I try to unmount this xml
<C> <D> <E>Fred</E> <F>42</F> </D> </C>
using these structures
type D struct { E string F int } type C struct {
I get empty results {{ 0}} . However, the structure below works fine, producing {{Fred 42}}
type C struct {
See an example of a playground .
Did I miss some subtle points about structures?
source share