映射的C结构到XML元素 [英] Mapping C structure to an XML element

查看:165
本文介绍了映射的C结构到XML元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假如我有C或C ++的结构,如:

Suppose I have a structure in C or C++, such as:

struct ConfigurableElement {
   int ID;
   char* strName;
   long prop1;
   long prop2;
   ...
};

我想加载/保存到/从以下XML元素:

I would like to load/save it to/from the following XML element:

 <ConfigurableElement ID="1" strName="namedElem" prop1="2" prop2="3" ... />

这样的映射可以在Java / C#或任何其他语言与用于物质运行时反射来平凡完成。它可以在任何非单调乏味的方式来完成的C ++与宏/模板弄虚作假?

Such a mapping can be trivially done in Java/C# or any other language with run-time reflection for the matter. Can it be done in any non-tedious way in C++ with macros/template trickery?

积分为处理嵌套结构/联合。

Bonus points for handling nested structures/unions.

推荐答案

你想要的技术被称为序列化。您可能需要阅读这些文章:

The technique you want is called serialization. You may want to read these articles:

HTTP://www.$c$cproject.com/KB/ CPP / xmlserialization.aspx

的http://www.$c$csynthesis.com/products/xsd/ &LT;!===非常接近你想要什么

http://www.codesynthesis.com/products/xsd/ <=== Very close to what you want!

http://www.artima.com/cppsource/xml_data_binding.html

http://www.ibm.com/developerworks/xml/库/ X-serial.html

http://www.firstobject.com/xml-serialization-in- C ++。HTM

有是你的另一个选择:由Ultimatepp提供Xmlize:

There is another option for you: Xmlize provided by Ultimatepp:

http://www.ultimatepp.org/reference$Xmlize.html

http://www.ultimatepp.org/reference$Xmlize$en- us.html

http://www.ultimatepp.org/reference$XmlizeCustomValue$en- us.html

http://www.ultimatepp.org/reference$Xmlize_std$en- us.html

http://www.ultimatepp.org/reference$XML$en- us.html

这篇关于映射的C结构到XML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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