这是我的XML数据:
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/generic.qcow2'/>
<backingStore/>
<target dev='hda' bus='ide'/>
<alias name='ide0-0-0'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>我的结构是:
// struct for get device details from xml
type DiskXmlInfo struct {
Devices []Disk `xml:"devices>disk"`
}
type Disk struct {
Type string `xml:"device,attr"`
// Name string `xml:"target>dev,attr"`
Name string `xml:"target>dev,attr"`
}我无法获取目标属性名称。如何获取目标属性名称?
提前谢谢。
发布于 2016-06-02 17:30:03
你不能用路径来读取属性,比如"target> dev,attr“。一种选择是对target使用单独的类型,就像您已经对disk使用的那样
type Target struct {
Dev string `xml:"dev,attr"`
Bus string `xml:"bus,attr"`
}
type Disk struct {
...
Target Target `xml:"target"`
}另一种选择是使用自定义解组程序。
https://stackoverflow.com/questions/37585597
复制相似问题