Mapping C structure to an XML element

Posted by EFraim on Stack Overflow See other posts from Stack Overflow or by EFraim
Published on 2010-04-21T17:56:11Z Indexed on 2010/04/21 18:03 UTC
Read the original article Hit count: 139

Filed under:
|
|
|
|

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

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

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

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

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.

© Stack Overflow or respective owner

Related posts about c

    Related posts about c++