douxian7808 2017-06-13 14:55
浏览 52
已采纳

无法在Go中正确解组/编组动态XML结构

I have am xsd describing an XML schema and I am trying to write the representation of this xsd in go structures so I am able to marshal/unmarshal XML based on this schema.

Here is some go playground code I wrote to reproduce the problem I am having.

https://play.golang.org/p/ktJOsCDyLW

In the schema, the tags video and web are dynamic (as in they can both appear under media more than once and have different content inside).

I attempted writing a dynamic struct along with the Unmarshaller/Marshaller interface as the example shows and I seem to be able to perform the parsing but it unmarshals/marshals the internal content incorrect ignoring the Name and URL lists, only taking one element of each.

I am uncertain what the issue is here.

Any help on the matter is appreciated

  • 写回答

1条回答 默认 最新

  • dongzhuan1185 2017-06-13 15:09
    关注

    I have modified your sample here https://play.golang.org/p/rbcoL0ayeb. Change your definition to following:

    Series:

    type Series struct {
       Name []Name `xml:"name"`
    }
    

    Website:

    type Website struct {
       Url []Url `xml:"url"`
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部