I got the following XML structure
XML-structure:
<assay>
<step id="1">
<command>
<bar>
<ab>structure 1</ab>
</bar>
<duration>5</duration>
</command>
</step>
<step id="2">
<command>
<bar>
<cd>structure 2</cd>
</bar>
<duration>5</duration>
</command>
</step>
<step id="3">
<command>
<bar>
<de>structure 3</de>
</bar>
<duration>5</duration>
</command>
</step>
<step id="4">
<command>
<bar>
<ab>structure 1</ab>
</bar>
<duration>5</duration>
</command>
</step>
</assay>
and created the following struct in golang
type Assay struct {
Steps []struct {
ID int `xml:"id"`
Duration int `xml:"duration"`
Instruction string `xml:"command>bar"`
Command Command `xml:"command"`
} `xml:"step"`
}
type Command struct {
Bar struct {
Ab *Ab struct {} `xml:"ab"`
Cd *Cd struct {} `xml:"cd"`
De *De struct {} `xml:"de"`
} `xml:bar`
}
Is it possible to write in the Instruction field the element name from the elements in the bar element (ab, cd, de)? I get the element name with xml.Name but i got this only inside the ab, cd, ef struct.
The other question: is it possible tha inside the Bar struct only the struct from the XML is shown?
At the moment it looks like:
Bar {
Ab: {...some Informations}
Cd: {nil}
De:{nil}
}
Bar {
Ab: {nil}
Cd: {...some Informations}
De:{nil}
}
It should be:
Bar {
Ab: {...some Informations}
}
Bar {
Cd: {...some Informations}
}
I receive the XMl as a string and unmarshal it with the following code:
func ExtractAssay(stringXML string) (structXML requests.Assay) {
stringByte := []byte(stringXML)
err := xml.Unmarshal(stringByte, &structXML)
if nil != err {
fmt.Println("Error unmarshalling from XML", err)
return
}
return structXML
}