how to get the element name of a deeper lying element in XML with Golang
how to get the element name of a deeper lying element in XML with Golang
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}
}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.