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

Hanggeen · · 1089 次点击
(lll¬ω¬),怎么格式化来着
#4
更多评论
试一试 ``` 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