How can I read the actual value of the field (not an attribute)? This is where tsiferki =)

package main import ( "encoding/xml" "fmt" ) var xmlContent = ` <?xml version="1.0" encoding="UTF-8"?> <lists> <paragraph> <list href="href12" listAtr="wwwww">2332</list> <lists href="href13" listAtr="sssss">4554</lists> <lists href="href21" listAtr="fffff">1111</lists> <lists href="href22" listAtr="ggggg">1122</lists> </paragraph> <paragraph> <list href="href12" listAtr="wwwww">2332</list> <lists href="href13" listAtr="sssss">4554</lists> <lists href="href21" listAtr="fffff">1111</lists> <lists href="href22" listAtr="ggggg">1122</lists> </paragraph> </lists> ` type lists struct { XMLName xml.Name `xml:"lists"` Paragraf []paragraph `xml:"paragraph"` } type paragraph struct { //XMLName xml.Name ListTop []List `xml:"list"` ListsDoc []ListsStr `xml:"lists"` } type List struct { HrefList string `xml:"href,attr"` List string `xml:"listAtr,attr"` } type ListsStr struct { HrefLists string `xml:"href,attr"` Lists string `xml:"listAtr,attr"` } func main() { str := lists{} err := xml.Unmarshal([]byte(xmlContent), &str) if err != nil { panic(err) } fmt.Println(str) fmt.Println("\n-------") for inx, _ := range str.Paragraf { fmt.Println("Top: ", str.Paragraf[inx].ListTop) for _, k := range str.Paragraf[inx].ListsDoc { fmt.Println("Doc", k) } fmt.Println("-------\n") } } 

    1 answer 1

    Try adding to the List and ListsStr structures.

    Field with the attribute ", innerxml" or ", chardata", for example

     type ListsStr struct { HrefLists string `xml:"href,attr"` Lists string `xml:"listAtr,attr"` Value string `xml:",chardata"` } 

    https://play.golang.org/p/sIKjkn9pZ0

    https://golang.org/pkg/encoding/xml/#Unmarshal