dpmfur2635 2016-05-12 11:07
浏览 209
已采纳

您可以在GO中动态生成XML吗?

Can you generate XML dynamically in GO? Instead of using a struct and then doing .Encode on it?

So something like you can do in Python by using lxml. As in building one Element after another manually and dynamically as needed.

This way I can add only the fields/elements I need based on custom logic.

  • 写回答

1条回答 默认 最新

  • doujiazong0322 2016-05-12 14:14
    关注

    You can add dynamic attributes to a type that contains a map, and define a custom marshalling action on this type. There's an example here: Marshall map to XML in Go

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件