我是golang的初学者,我正在尝试将xml解析到结构体当中。面对如下这种相同的父标签下有不同的标签的xml我应该如何设置结构体呢?
```
<profile>
<subsystem xmlns="urn:jboss:domain:logging:1.1">
<root-logger>
<level name="INFO"/>
<handlers>
<handler name="CONSOLE"/>
<handler name="FILE"/>
</handlers>
</root-logger>
</subsystem>
<subsystem xmlns="urn:jboss:domain:configadmin:1.0"/>
<subsystem xmlns="urn:jboss:domain:deployment-scanner:1.1">
<deployment-scanner path="deployments" relative-to="jboss.server.base.dir" scan-interval="5000"/>
</subsystem>
</profile>
```
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