RE: [xml] Best way to do C Struct <-> XML Node tree?

Hi Tyler,

I implemented something similar to what you are doing, this is what I
do, "read the contents of an XML file directly to a C Struct, and also
write back to the XML file with the values from the C struct", I have an
XML file which is similar to the one below,

<?xml version="1.0" encoding="UTF-8" ?> 
 <!--  Sample template of the XML file to be used --> 
  <bb type="string">XML is the in thing !!</bb> 
  <ex2 type="array" size="6">10,20,30,786,50,80</ex2> 

Hope this helps,



-----Original Message-----
From: xml-bounces gnome org [mailto:xml-bounces gnome org] On Behalf Of
Tyler MacDonald
Sent: Friday, April 28, 2006 1:33 PM
To: xml gnome org
Subject: [xml] Best way to do C Struct <-> XML Node tree?

I think I've *almost* got this. 

I define a structure that maps elements in a struct to an XML node name
and sprintf formatting code, like this:

bt_xml_node infohash_nodes[] =
 { "Filename", "%s", (int)(&new_bt_infohash.filename) -
(int)(&new_bt_infohash) },  { "Filesize", "%llu",
(int)(&new_bt_infohash.filesize) - (int)(&new_bt_infohash) },  { NULL,

Then I use some functions (attached) to use these structures to iterate
through a CStruct and create an XML node tree. Ideally, I'm going to use
the same structures to load the information from XML back into CStructs.

Is there a better / more standard way to do this? I'm happy with this
approach, except right now it seems like I need bunch of crappy
if/else's to translate all the sprintf() formatting codes to data types
(example attached).


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]