対Result
は別に定義Address
への参照が含まれていることを、これらの構造体をは直接移動<a href="https://golang.org/pkg/encoding/xml/#Unmarshal" rel="nofollow noreferrer">documentation for xml:Unmarshal</a>で間接的にネストされた構造体
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
}
注意を使用して、このXML
<Person>
<FullName>Grace R. Emlin</FullName>
<Company>Example Inc.</Company>
<Email where="home">
<Addr>[email protected]</Addr>
</Email>
<Email where='work'>
<Addr>[email protected]</Addr>
</Email>
<Group>
<Value>Friends</Value>
<Value>Squash</Value>
</Group>
<City>Hanga Roa</City>
<State>Easter Island</State>
</Person>
をアンマーシャルの例があります。明らかに、このコードは動作します。私はこれらの構造体
type D struct {
E string
F int
}
type C struct { // Compiles OK but result empty.
D
}
を使用して、このXML
<C>
<D>
<E>Fred</E>
<F>42</F>
</D>
</C>
を非整列化しようとすると
は、私は空の結果{{ 0}}
を取得します。ただし、以下の構造体を参照してくださいPlayground example{{Fred 42}}
type C struct { // This works.
D struct {
E string
F int
}
}
を生産OK動作します。
構造体に関する微妙な点がありませんか?