在Go中解析相同父标签下不同标签的XML

newbe3three · · 1332 次点击
My problem can be easily solved by using slices. The following code is the corresponding structure. ``` type Level struct { Name string `xml:"name,attr"` } type Handler struct { Name string `xml:"name,attr"` } type Handlers struct { Handler []Handler `xml:"handler"` } type RootLogger struct { Level Level `xml:"level"` Handler Handlers `xml:"handlers"` } type DeploymentScanner struct { Path string `xml:"path,attr"` RelativeTo string `xml:"relative-to,attr"` ScanInterval string `xml:"scan-interval,attr"` } type Subsystem struct { XMLName xml.Name RootLogger []RootLogger `xml:"root-logger"` DeploymentScanner []DeploymentScanner `xml:"deployment-scanner"` } type Profile struct { Subsystem []Subsystem `xml:"subsystem"` } ``` [Go Playground][1] [1]: https://go.dev/play/p/usSst47Bm17
#1