I have the following code:
package main
import (
"encoding/xml"
"fmt"
)
func main() {
xr := &xmlResponse{}
if err := xml.Unmarshal([]byte(x), &xr); err != nil {
panic(err)
}
fmt.Printf("%+v", xr)
}
type xmlResponse struct {
//Title string `xml:"title,omitempty"`
Title struct {
BoldWords []struct {
Bold string `xml:",chardata"`
} `xml:"bold,omitempty"`
Title string `xml:",chardata" `
} `xml:"title,omitempty"`
}
var x = `<?xml version="1.0" encoding="utf-8"?>
<mytag version="1.0">
<title><bold>Go</bold> is a programming language. I repeat: <bold>Go</bold> is a programming language.</title>
</mytag>`
This outputs:
&{Title:{BoldWords:[{Bold:Go} {Bold:Go}] Title: is a programming language. I repeat: is a programming language.}}
How do I get:
<bold>Go</bold> is a programming language. I repeat: <bold>Go</bold> is a programming language.
In other words, I need not only the tags but also keep them in the proper place and not just a slice of bolded items. Trying to get it just as a string (e.g. uncommenting the first "Title" in xmlResponse struct) leaves out the bolded items entirely.