what's the easiest way to generate xml in c++?

前端 未结 6 1136
遥遥无期
遥遥无期 2020-12-01 02:11

I\'ve used boost serialization but this doesn\'t appear to allow me to generate xml that conforms to a particular schema -- it seems it\'s purpose was to just to persist a c

6条回答
  •  -上瘾入骨i
    2020-12-01 02:52

    Some may declare me an XML heretic - but one effective way is to just generate it with your favorite string output tools (print, output streams, etc) - this can go to a buffer or a file.

    Once saved - you really should then validate with a schema before committing it our shipping it off.

    For one of our projects we have a very simple set of templates for managing begin/end tags and attributes. These each have a stream output operator. This makes it very easy to generate the source XML and debug. This makes the structure of the XML generation code look very much like the XML itself.

    One advantage of this is that you can generate large amounts of XML efficiently if streaming to a file. You will pay the validation costs later (presumably at a better time for an expensive operation).

    The downside of this technique is that it is essentially output only. It is not suitable for creating then consuming XML dynamically.

提交回复
热议问题