How to create a CDATA node of xml with go?

前端 未结 6 1117
自闭症患者
自闭症患者 2021-02-19 09:03

I have the following struct:

type XMLProduct struct {
    XMLName          xml.Name `xml:\"row\"`
    ProductId        string   `xml:\"product_id\"`
    ProductN         


        
6条回答
  •  鱼传尺愫
    2021-02-19 09:27

    If you use Go version 1.6 or later, just adding 'cdata' tag will work fine.

    type XMLProduct struct {
        XMLName          xml.Name `xml:"row"`
        ProductId        string   `xml:"product_id"`
        ProductName      string   `xml:"product_name,cdata"`
        OriginalPrice    string   `xml:"original_price"`
        BargainPrice     string   `xml:"bargain_price"`
        TotalReviewCount int      `xml:"total_review_count"`
        AverageScore     float64  `xml:"average_score"`
    }
    

提交回复
热议问题