[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, NULL, 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).

Thanks,
        Tyler

Attachment: bt_xml.c
Description: Text Data

Attachment: bt_xml.h
Description: Text Data



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