douxian7808 2017-06-13 22: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 23: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"`
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Simulink仿真报错,请问如何解决
  • ¥20 宝塔面板无法添加Node项目,一直处于正在添加脚本页面
  • ¥50 Dkeil5 CT107D单片机的程序编写
  • ¥30 Ubuntu20.04中PVN3D复现过程交叉编译问题
  • ¥15 模拟电路求复阻抗和传递函数,请各位拍照写一下解答过程
  • ¥60 不懂得怎么运行下载来的代码
  • ¥15 CST导出3D模型图为什么和软件显示不一样?
  • ¥15 加热反应炉PLC控制系统设计(相关搜索:梯形图)
  • ¥15 python 用Dorc包报错,我的写法和网上教的是一样的但是它显示无效参数,是什么问题
  • ¥15 经过滑动平均后的一维信号还原用什么结构好呢?