How to create a CDATA node of xml with go?

前端 未结 6 1115
自闭症患者
自闭症患者 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

    CDATA with ",cdata" notation. It is handy to create struct with "Cdata" and use along with your xml object

    package main
    
    import (
        "encoding/xml"
        "fmt"
    )
    
    type Person struct {
        Name    string `xml:"Name"`
        Age     int    `xml:"AGE"`
        Address Cdata  `xml:"ADDRESS"`
    }
    
    type Cdata struct {
        Value string `xml:",cdata"`
    }
    
    func main() {
    
        var address Cdata
        address.Value = "John's House, : 10,Universe  PIN: 00000 

提交回复
热议问题