在c ++中生成xml的最简单的方法是什么? [英] what's the easiest way to generate xml in c++?

查看:147
本文介绍了在c ++中生成xml的最简单的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了boost序列化,但这似乎不允许我生成符合一个特定的模式的XML - 它似乎它的目的只是为了持久化一个类的状态。

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 class's state.

平台:linux

你们用什么来生成NOT parse xml?

What do you guys use to generate NOT parse xml?

到目前为止,我要走Foredecker的路线,只是自己生成 - 它不是一个大文件,但我真的不应该有这么麻烦找到一个体面的库来生成它正确。

So far I'm going down Foredecker's route of just generating it myself -- it's not a large document but I really shouldn't be having this much trouble finding a decent library to generate it correctly.

对于boost,我想要做的事情是设置节点名称,设置属性在我的节点,并摆脱所有额外的垃圾与它,因为我不'

As for boost, the things that I would like to be able to do is set the node names, set attributes in my nodes, and get rid of all the extra crap that comes with it as I don't really care about having to put my document back into that class.

推荐答案

有人可能会声明一个XML异常 - 但一个有效的方法是使用您最喜欢的字符串输出工具(打印,输出流等)生成它 - 这可以去缓冲区或文件。

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.

我们的一个项目,我们有一个非常简单的模板集管理开始/结束标签和属性。这些都有一个流输出操作符。这使得生成源XML和调试非常容易。这使得XML生成代码的结构看起来非常像XML本身。

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.

这样做的一个优点是,如果流式传输到文件,您可以有效地生成大量的XML。您将在以后支付验证成本(可能是在更好的时间进行昂贵的操作)。

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).

这种技术的缺点是它基本上只是输出。它不适合动态创建然后使用XML。

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

这篇关于在c ++中生成xml的最简单的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆