what#39;s the easiest way to generate xml in c++?(在 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 解析 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.
至于提升,我希望能够做的事情是设置节点名称,在我的节点中设置属性,并摆脱它带来的所有额外废话,因为我并不真正关心不得不把我的文档放回那个班级.
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 的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C++ 中生成 xml 的最简单方法是什么?
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 近似搜索的工作原理 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- C++ 协变模板 2021-01-01