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

Parsing XML of the different tag under same parent tags in Go

我是 Go 的新手,我正在尝试解析 XML 文件。我不知道如何将下面的 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>     

使用切片可以轻松解决我的问题。 下面的代码就是对应的结构体

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