XML and libxml 3 GSF Library XML and libxml Synopsis #define GSF_XML_IN_NS (id, uri) enum GsfXMLContent; GsfXMLIn; int gsf_xmlDocFormatDump (GsfOutput *output, xmlDoc *cur, char const *encoding, gboolean format); void gsf_xml_in_doc_free (GsfXMLInDoc *doc); GsfXMLBlob; GsfXMLOut; GsfXMLInDoc; GsfXMLInNS; #define GSF_XML_IN_NODE_FULL (parent_id, id, ns, name, has_content, \ deprecated_unused_allow_unknown, check_ns, start, end, user) #define GSF_XML_IN_NODE (parent_id, id, ns, name, has_content, start, end) GsfXMLInNode; gboolean (*GsfXMLInUnknownFunc) (GsfXMLIn *state, xmlChar const *elem, xmlChar const **attrs); xmlParserCtxt* gsf_xml_parser_context (GsfInput *input); GsfXMLInDoc* gsf_xml_in_doc_new (GsfXMLInNode *root, GsfXMLInNS *ns); gboolean gsf_xml_in_namecmp (GsfXMLIn const *state, char const *str, unsigned int ns_id, char const *name); gboolean gsf_xml_in_parse (GsfXMLIn *state, GsfInput *input); charconst * gsf_xml_in_check_ns (GsfXMLIn const *state, char const *str, unsigned int ns_id); void gsf_xml_in_doc_extend (GsfXMLInDoc *doc, GsfXMLInNode *nodes); void gsf_xml_in_doc_set_unknown_handler (GsfXMLInDoc *doc, GsfXMLInUnknownFunc handler); GsfXMLOut* gsf_xml_out_new (GsfOutput *output); void gsf_xml_out_set_doc_type (GsfXMLOut *xml, char const *type); void gsf_xml_out_start_element (GsfXMLOut *xml, char const *id); charconst * gsf_xml_out_end_element (GsfXMLOut *xml); void gsf_xml_out_add_cstr (GsfXMLOut *xml, char const *id, char const *val_utf8); void gsf_xml_out_add_cstr_unchecked (GsfXMLOut *xml, char const *id, char const *val_utf8); void gsf_xml_out_add_bool (GsfXMLOut *xml, char const *id, gboolean val); void gsf_xml_out_add_int (GsfXMLOut *xml, char const *id, int val); void gsf_xml_out_add_uint (GsfXMLOut *xml, char const *id, unsigned int val); void gsf_xml_out_add_float (GsfXMLOut *xml, char const *id, double val, int precision); void gsf_xml_out_add_enum (GsfXMLOut *xml, char const *id, GType etype, gint val); void gsf_xml_out_add_color (GsfXMLOut *xml, char const *id, unsigned int r, unsigned int g, unsigned int b); void gsf_xml_out_add_base64 (GsfXMLOut *xml, char const *id, guint8 const *data, unsigned int len); void gsf_xml_out_simple_element (GsfXMLOut *xml, char const *id, char const *content); void gsf_xml_out_simple_float_element (GsfXMLOut *xml, char const *id, double val, int precision); void gsf_xml_out_simple_int_element (GsfXMLOut *xml, char const *id, int val); Object Hierarchy GObject +----GsfXMLOut Description Details <anchor id="GSF-XML-IN-NS:CAPS"/>GSF_XML_IN_NS() GSF_XML_IN_NS#define GSF_XML_IN_NS(id, uri) id : uri : <anchor id="GsfXMLContent"/>enum GsfXMLContent GsfXMLContenttypedef enum { GSF_XML_NO_CONTENT, GSF_XML_CONTENT, GSF_XML_SHARED_CONTENT } GsfXMLContent; <anchor id="GsfXMLIn"/>GsfXMLIn GsfXMLIntypedef struct { GsfXMLInDoc const *doc; /* init before parsing */ /* look but do not change */ GsfXMLInNode const *node; /* current node */ GSList *state_stack; GsfXMLInNS const *default_ns; /* optionally NULL */ GSList *ns_stack; GString *content; gint unknown_depth; /* handle recursive unknown tags */ GHashTable *ns_prefixes; /* current ns prefixes */ GPtrArray *ns_by_id; /* indexed by id */ } GsfXMLIn; <anchor id="gsf-xmlDocFormatDump"/>gsf_xmlDocFormatDump () gsf_xmlDocFormatDumpint gsf_xmlDocFormatDump (GsfOutput *output, xmlDoc *cur, char const *encoding, gboolean format); output : cur : encoding : format : Returns : <anchor id="gsf-xml-in-doc-free"/>gsf_xml_in_doc_free () gsf_xml_in_doc_freevoid gsf_xml_in_doc_free (GsfXMLInDoc *doc); Free up resources doc : <anchor id="GsfXMLBlob"/>GsfXMLBlob GsfXMLBlobtypedef struct _GsfXMLBlob GsfXMLBlob; <anchor id="GsfXMLOut-struct"/>GsfXMLOut GsfXMLOuttypedef struct _GsfXMLOut GsfXMLOut; <anchor id="GsfXMLInDoc"/>GsfXMLInDoc GsfXMLInDoctypedef struct _GsfXMLInDoc GsfXMLInDoc; <anchor id="GsfXMLInNS"/>GsfXMLInNS GsfXMLInNStypedef struct { char const *uri; unsigned ns_id; } GsfXMLInNS; <anchor id="GSF-XML-IN-NODE-FULL:CAPS"/>GSF_XML_IN_NODE_FULL() GSF_XML_IN_NODE_FULL#define GSF_XML_IN_NODE_FULL(parent_id, id, ns, name, has_content, \ deprecated_unused_allow_unknown, check_ns, start, end, user) parent_id : id : ns : name : has_content : @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: @\ deprecated_unused_allow_unknown: check_ns : start : end : user : <anchor id="GSF-XML-IN-NODE:CAPS"/>GSF_XML_IN_NODE() GSF_XML_IN_NODE#define GSF_XML_IN_NODE(parent_id, id, ns, name, has_content, start, end) parent_id : id : ns : name : has_content : start : end : <anchor id="GsfXMLInNode"/>GsfXMLInNode GsfXMLInNodetypedef struct { char const *id; int ns_id; char const *name; char const *parent_id; gboolean parent_initialized; GSList *groups; unsigned has_content; gboolean deprecated_unused_allow_unknown; /* remains here for binary compat */ gboolean check_children_for_ns; void (*start) (GsfXMLIn *state, xmlChar const **attrs); void (*end) (GsfXMLIn *state, GsfXMLBlob *unknown); union { int v_int; gboolean v_bool; gpointer v_blob; char const *v_str; } user_data; } GsfXMLInNode; <anchor id="GsfXMLInUnknownFunc"/>GsfXMLInUnknownFunc () GsfXMLInUnknownFuncgboolean (*GsfXMLInUnknownFunc) (GsfXMLIn *state, xmlChar const *elem, xmlChar const **attrs); state : elem : attrs : Returns : <anchor id="gsf-xml-parser-context"/>gsf_xml_parser_context () gsf_xml_parser_contextxmlParserCtxt* gsf_xml_parser_context (GsfInput *input); Create a libxml2 pull style parser context wrapper around a gsf input. This signature will probably change to supply a SAX structure. NOTE : adds a reference to input NOTE : a simple wrapper around a cleaner implementation that will fold in when we add other api changes. Its not worth bumping just for this input : Returns :: A parser context or NULL <anchor id="gsf-xml-in-doc-new"/>gsf_xml_in_doc_new () gsf_xml_in_doc_newGsfXMLInDoc* gsf_xml_in_doc_new (GsfXMLInNode *root, GsfXMLInNS *ns); Put the nodes in the NULL terminated array starting at root and the name spaces in the NULL terminated array starting at ns together. Link them up and prepare the static data structures necessary to validate a doument based on that description. root : an array of node descriptors ns : an array of namespace identifiers Returns :NULL on error <anchor id="gsf-xml-in-namecmp"/>gsf_xml_in_namecmp () gsf_xml_in_namecmpgboolean gsf_xml_in_namecmp (GsfXMLIn const *state, char const *str, unsigned int ns_id, char const *name); state : The GsfXMLIn we are reading from. str : The potentially namespace qualified node name. ns_id : The name space id to check name : The target node name Returns :TRUE if str == ns_id:name according to state. <anchor id="gsf-xml-in-parse"/>gsf_xml_in_parse () gsf_xml_in_parsegboolean gsf_xml_in_parse (GsfXMLIn *state, GsfInput *input); Read an xml document from input and parse based on the the descriptor in state::doc state : input : Returns :FALSE on error <anchor id="gsf-xml-in-check-ns"/>gsf_xml_in_check_ns () gsf_xml_in_check_nscharconst * gsf_xml_in_check_ns (GsfXMLIn const *state, char const *str, unsigned int ns_id); According to state is str in the namespace ns_id ? state : str : ns_id : Returns :a pointer to str after the namespace if successful, otherwise NULL. <anchor id="gsf-xml-in-doc-extend"/>gsf_xml_in_doc_extend () gsf_xml_in_doc_extendvoid gsf_xml_in_doc_extend (GsfXMLInDoc *doc, GsfXMLInNode *nodes); doc : nodes : <anchor id="gsf-xml-in-doc-set-unknown-handler"/>gsf_xml_in_doc_set_unknown_handler () gsf_xml_in_doc_set_unknown_handlervoid gsf_xml_in_doc_set_unknown_handler (GsfXMLInDoc *doc, GsfXMLInUnknownFunc handler); Call the function handler when an unexpected child node is found doc : GsfXMLInDoc handler : The function to call <anchor id="gsf-xml-out-new"/>gsf_xml_out_new () gsf_xml_out_newGsfXMLOut* gsf_xml_out_new (GsfOutput *output); output : Returns : <anchor id="gsf-xml-out-set-doc-type"/>gsf_xml_out_set_doc_type () gsf_xml_out_set_doc_typevoid gsf_xml_out_set_doc_type (GsfXMLOut *xml, char const *type); Store some optional some <!DOCTYPE .. > content xml : GsfXMLOut type : <anchor id="gsf-xml-out-start-element"/>gsf_xml_out_start_element () gsf_xml_out_start_elementvoid gsf_xml_out_start_element (GsfXMLOut *xml, char const *id); xml : id : <anchor id="gsf-xml-out-end-element"/>gsf_xml_out_end_element () gsf_xml_out_end_elementcharconst * gsf_xml_out_end_element (GsfXMLOut *xml); xml : Returns : <anchor id="gsf-xml-out-add-cstr"/>gsf_xml_out_add_cstr () gsf_xml_out_add_cstrvoid gsf_xml_out_add_cstr (GsfXMLOut *xml, char const *id, char const *val_utf8); dump val_utf8 to an attribute named id or as the nodes content escaping characters as necessary. If val_utf8 is NULL do nothing (no warning, no output) xml : id : optionally NULL for content val_utf8 : a utf8 encoded string <anchor id="gsf-xml-out-add-cstr-unchecked"/>gsf_xml_out_add_cstr_unchecked () gsf_xml_out_add_cstr_uncheckedvoid gsf_xml_out_add_cstr_unchecked (GsfXMLOut *xml, char const *id, char const *val_utf8); dump val_utf8 to an attribute named id without checking to see if the content needs escaping. A useful performance enhancement when the application knows that structure of the content well. If val_utf8 is NULL do nothing (no warning, no output) xml : id : optionally NULL for content val_utf8 : a utf8 encoded string to export <anchor id="gsf-xml-out-add-bool"/>gsf_xml_out_add_bool () gsf_xml_out_add_boolvoid gsf_xml_out_add_bool (GsfXMLOut *xml, char const *id, gboolean val); dump boolean value val to an attribute named id or as the nodes content Use '1' or '0' to simplify import xml : id : optionally NULL for content val : a boolean <anchor id="gsf-xml-out-add-int"/>gsf_xml_out_add_int () gsf_xml_out_add_intvoid gsf_xml_out_add_int (GsfXMLOut *xml, char const *id, int val); dump integer value val to an attribute named id or as the nodes content xml : id : optionally NULL for content val : the value <anchor id="gsf-xml-out-add-uint"/>gsf_xml_out_add_uint () gsf_xml_out_add_uintvoid gsf_xml_out_add_uint (GsfXMLOut *xml, char const *id, unsigned int val); dump unsigned integer value val to an attribute named id or as the nodes content xml : id : optionally NULL for content val : the value <anchor id="gsf-xml-out-add-float"/>gsf_xml_out_add_float () gsf_xml_out_add_floatvoid gsf_xml_out_add_float (GsfXMLOut *xml, char const *id, double val, int precision); dump float value val to an attribute named id or as the nodes content with precision precision. The number will be formattted according to the "C" locale. xml : id : optionally NULL for content val : the value precision : the number of significant digits to use, -1 meaning "enough". <anchor id="gsf-xml-out-add-enum"/>gsf_xml_out_add_enum () gsf_xml_out_add_enumvoid gsf_xml_out_add_enum (GsfXMLOut *xml, char const *id, GType etype, gint val); xml : id : etype : val : <anchor id="gsf-xml-out-add-color"/>gsf_xml_out_add_color () gsf_xml_out_add_colorvoid gsf_xml_out_add_color (GsfXMLOut *xml, char const *id, unsigned int r, unsigned int g, unsigned int b); dump Color r.g.b to an attribute named id or as the nodes content xml : id : optionally NULL for content r : g : b : <anchor id="gsf-xml-out-add-base64"/>gsf_xml_out_add_base64 () gsf_xml_out_add_base64void gsf_xml_out_add_base64 (GsfXMLOut *xml, char const *id, guint8 const *data, unsigned int len); dump len bytes in data into the content of node id using base64 xml : id : optionally NULL for content data : len : <anchor id="gsf-xml-out-simple-element"/>gsf_xml_out_simple_element () gsf_xml_out_simple_elementvoid gsf_xml_out_simple_element (GsfXMLOut *xml, char const *id, char const *content); A convenience routine xml : id : content : <anchor id="gsf-xml-out-simple-float-element"/>gsf_xml_out_simple_float_element () gsf_xml_out_simple_float_elementvoid gsf_xml_out_simple_float_element (GsfXMLOut *xml, char const *id, double val, int precision); A convenience routine xml : id : val : precision : <anchor id="gsf-xml-out-simple-int-element"/>gsf_xml_out_simple_int_element () gsf_xml_out_simple_int_elementvoid gsf_xml_out_simple_int_element (GsfXMLOut *xml, char const *id, int val); A convenience routine xml : id : val :