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 --> <XML_TO_C> <bb type="string">XML is the in thing !!</bb> <ex2 type="array" size="6">10,20,30,786,50,80</ex2> </XML_TO_C> Hope this helps, Regards, Pavan. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tyler MacDonald Sent: Friday, April 28, 2006 1:33 PM To: [email protected] 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, 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 _______________________________________________ xml mailing list, project page http://xmlsoft.org/ [email protected] http://mail.gnome.org/mailman/listinfo/xml
