急!Golang如何生成以下XML格式

Hanggeen · · 1072 次点击
试一试 ``` go package main import( "fmt" "encoding/xml" ) type A struct { XMLName xml.Name `xml:"a"` Values []interface{} } type B struct { XMLName xml.Name `xml:"b"` } type C struct { XMLName xml.Name `xml:"c"` } func main(){ a := A{} a.Values = []interface{}{B{},C{},B{},C{}} output, _ := xml.MarshalIndent(a, " ", " ") fmt.Println(string(output)) } ```
#1
更多评论
type A struct { XMLName xml.Name `xml:"a"` Bs []B `xml:"b" Cs []C `xml:"c" } type B struct{ XMLName xml.Name `xml:"b"` } type C struct{ XMLName xml.Name `xml:"c"` } ... paramStream, err := xml.Marshal(a) ...
#2
```go type A struct { XMLName xml.Name xml:"a" Bs []B xml:"b" Cs []Cxml:"c" } type B struct{ XMLName xml.Name xml:"b" } type C struct{ XMLName xml.Name xml:"c" } ... paramStream, err := xml.Marshal(a) ... ```
#3