小编典典

在解组此xml时遇到麻烦

go

试图了解如何在Go中解组XML。通读多个示例和stackoverflow问题。我想要的是一个切片,其中包含系统上安装的所有修补程序。我什至无法解开补丁,没有错误,只是一片空白。可能所做的事情基本上是错误的,在此先感谢您的任何建议。

<probe version="1.3" date="2012-03-26:17:10">
     <properties>
     </properties>
     <patches group="server">
        <file name="5002012-02-09CR00000server.jar"/>
        <file name="5002012-02-17CR00001server.jar"/>
     </patches>
     <patches group="client">
        <file name="5002012-02-09CR00000client.jar"/>
        <file name="5002012-02-17CR00001client.jar"/>
     </patches>
</probe>



type Patch struct {
    group string `xml:"group,attr"`
}

type Probe struct {
    XMLName xml.Name `xml"probe"`
    Patches []Patch `xml:"patches"`
}

阅读 233

收藏
2020-07-02

共1个答案

小编典典

我认为您遇到的问题是xml程序包未填充未导出的字段。xml文档说:

因为Unmarshal使用了反射包,所以它只能分配给导出的(大写)字段。

您要做的就是更改groupGroup

type Patch struct { Group string `xml:"group,attr"` }

您在这里有一个工作示例:http :
//play.golang.org/p/koSzZr-Bdn

2020-07-02