I am trying to extract some data from XML. The XML tag has an attribute and a value. I'm only interested in the value not attribute. Here's what I'm trying:
package main
import (
"encoding/xml"
"fmt"
)
type Data struct {
Info Information `xml:"Reference"`
}
type Information struct {
Uid string `xml:"uid,attr"`
Name string `xml:",chardata"`
}
func main() {
str := `<?xml version="1.0" encoding="utf-8"?>
<Reference uid="123">TestName</Reference>`
var testData Data
_ = xml.Unmarshal([]byte(str), &testData)
fmt.Println("Name is ", testData.Info.Name)
fmt.Println("uid is ", testData.Info.Uid)
return
}