Golang XML parse

后端 未结 1 568
半阙折子戏
半阙折子戏 2021-02-06 06:28

My XML data:


    
        POST
        

        
1条回答
  •  臣服心动
    2021-02-06 07:17

    If you want a field to hold the contents of the current element, you can use the tag xml:",chardata". The way you've tagged your structure, it is instead looking for a sub-element.

    So one set of structures you could decode into is:

    type Dictionary struct {
        XMLName   xml.Name   `xml:"dictionary"`
        Grammemes []Grammeme `xml:"grammemes>grammeme"`
    }
    
    type Grammeme struct {
        Name   string `xml:",chardata"`
        Parent string `xml:"parent,attr"`
    }
    

    You can test out this example here: http://play.golang.org/p/7lQnQOCh0I

    0 讨论(0)
提交回复
热议问题