From: Tony G. <Ton...@Su...> - 2006-04-11 19:29:58
|
I am looking at modifying FoXmlDoc (in libfo/fo-xml-doc.[ch]) so it's also possible to create an FoXmlDoc from a string. The question then becomes how to change it. The present process for creating an FoXmlDoc from a filename is long-winded: xml_doc = fo_xml_doc_new (); fo_xml_doc_set_filename (xml_doc, xml_file); fo_xml_doc_parse (xml_doc, libfo_context, &error); if (error != NULL) { g_critical ("%s:: %s", g_quark_to_string (error->domain), error->message); g_error_free (error); exit (1); } That's partly because in the GObject world, everything has a _new() function, so the filename is set after the FoXmlDoc is created. Creating an FoXmlDoc from a buffer would really be a wrapper on xmlReadMemory: xmlDocPtr xmlReadMemory (const char * buffer, int size, const char * URL, const char * encoding, int options) Where 'options' would be extracted from settings in an FoLibfoContext and the rest would be set explicitly. The short form of my question is, is it better to: - Make separate 'constructors': fo_xml_doc_new_from_filename (...) fo_xml_doc_new_from_memory (...) - Make separate subtypes: fo_xml_doc_memory_new () fo_xml_doc_file_new () that each have their own _set() functions for their disparate parameters - Parse on 'construction', such that the fo_xml_doc_parse() function is no longer required - Do something completely different? Regards, Tony. |