I got an xml response that contains multiple entries in the <Rights></Rights>
block. It has several <Name></Name>
and <Access></Access>
fields.
<?xml version="1.0" encoding="UTF-8"?>
<SessionInfo>
<SID>000000000000</SID>
<Challenge>1337</Challenge>
<BlockTime>0</BlockTime>
<Rights>
<Name>Dial</Name>
<Access>2</Access>
<Name>App</Name>
<Access>2</Access>
<Name>HomeAuto</Name>
<Access>2</Access>
<Name>BoxAdmin</Name>
<Access>2</Access>
<Name>Phone</Name>
<Access>2</Access>
<Name>NAS</Name>
<Access>2</Access>
</Rights>
</SessionInfo>
I would like to have this converted into a rights struct.
type sessionInfo struct {
XMLName xml.Name `xml:"SessionInfo"`
SID string `xml:"SID"`
Challenge string `xml:"Challenge"`
BlockTime uint `xml:"BlockTime"`
Rights []rights `xml:"Rights"`
}
type rights struct {
Name string `xml:"Name"`
Access int `xml:"Access"`
}
Unfortunatelly it does only write the last Element into the array. Is it somehow possible to do this in Go without the need to write an own decoder?
<SessionInfo>
<SID>000000000000</SID>
<Challenge>1337</Challenge>
<BlockTime>0</BlockTime>
<Rights>
<Name>NAS</Name>
<Access>2</Access>
</Rights>
</SessionInfo>
You can test this here: https://play.golang.org/p/29I2GPttOz