How can I extract the 'id' attribute out of an element like <vuln:cwe id="CWE-189" />
? This is nested under <entry>
. My initial attempt was something like xml:"entry>cwe,id,attr"
.
Two approaches:
1/ keep getting the Token()
, until the element has for name cwe
.
Then a struct "CweXml" can extract the id attribute:
type CweXml struct {
Id string `xml:"id,attr"`
}
2/ Or start from entry
, but in that case you need a struct for it, which will contain CweXml
struct.
type EntryXml struct {
Cwe CweXml `xml:"cwe"`
}
In that case, you will find id in your entryXml.Cwe.Id
.