根据下面的链接,我们可以使用>或其他结构从嵌套的xml中获取数据。
但是,在不使用这种结束标记的情况下,它不起作用。
码:
package main
import (
"fmt"
"encoding/xml"
)
func main() {
container := Parent{}
err := xml.Unmarshal([]byte(xml_data), &container)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(container)
}
}
var xml_data = `<Parent>
<Val>Hello</Val>
<Child Val="Hello"/>
<Child Val="Hello"/>
<Child Val="Hello"/>
</Parent>`
type Parent struct {
Val string
Children Children
}
type Children struct {
Child []Child
}
type Child struct {
Val string
}
Run Code Online (Sandbox Code Playgroud)
结果:
{Hello {[]}}
Run Code Online (Sandbox Code Playgroud)
有什么办法吗?