Golang XML解析

This is my XML data:

<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>

and my struct is:

// 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"`
}

I cannot get the target attribute name. How to get the target attribute name?

Thanks in advance.

You can't read attributes with path, like "target> dev,attr". One option is to use separate type for the target, as you already use for the disk:

type Target struct {
  Dev string `xml:"dev,attr"`
  Bus string `xml:"bus,attr"`
}

type Disk struct {
  ...
  Target Target `xml:"target"`
}

Another option is to use custom unmarshaller.