1

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.