我有以下 xml 我試圖解析。package mainimport "fmt"import "encoding/xml"type ResultSlice struct { MyText []Result `xml:"results>result"`}type Result struct { MyResult string `xml:"text"`}func main() { s := `<myroot> <results> <result><text><strong>This has style</strong>Then some not-style</text></result> <result><text>No style here</text></result> <result><text>Again, no style</text></result> </results> </myroot>` r := &ResultSlice{} if err := xml.Unmarshal([]byte(s), r); err == nil { fmt.Println(r) } else { fmt.Println(err) }}這只會打印出純文本,而 html 標(biāo)簽中的任何內(nèi)容都會被忽略。<strong>This has style</strong>被忽略。我如何也包括在內(nèi)?
解析xml時如何保留html標(biāo)簽?
慕運維8079593
2021-09-09 13:56:45