X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=obt%2Fxml.c;h=5b7e77b5cb95c8b2ce94b5efca40cffed2593faa;hb=dff52764822f68596134c2548966eb78777b6d2a;hp=69810d77ee9374a1b3c46b20aa3ff038f84d70df;hpb=4f8503c2c5aa4210c923269626b67c5919326c46;p=chaz%2Fopenbox diff --git a/obt/xml.c b/obt/xml.c index 69810d77..5b7e77b5 100644 --- a/obt/xml.c +++ b/obt/xml.c @@ -19,6 +19,7 @@ #include "obt/xml.h" #include "obt/paths.h" +#include #include #ifdef HAVE_STDLIB_H @@ -111,6 +112,11 @@ void obt_xml_register(ObtXmlInst *i, const gchar *tag, g_hash_table_insert(i->callbacks, c->tag, c); } +void obt_xml_unregister(ObtXmlInst *i, const gchar *tag) +{ + g_hash_table_remove(i->callbacks, tag); +} + static gboolean load_file(ObtXmlInst *i, const gchar *domain, const gchar *filename, @@ -135,8 +141,9 @@ static gboolean load_file(ObtXmlInst *i, /* XML_PARSE_BLANKS is needed apparently, or the tree can end up with extra nodes in it. */ i->doc = xmlReadFile(path, NULL, (XML_PARSE_NOBLANKS | - XML_PARSE_RECOVER | - XML_PARSE_XINCLUDE)); + XML_PARSE_RECOVER)); + xmlXIncludeProcessFlags(i->doc, (XML_PARSE_NOBLANKS | + XML_PARSE_RECOVER)); if (i->doc) { i->root = xmlDocGetRootElement(i->doc); if (!i->root) { @@ -314,16 +321,22 @@ void obt_xml_tree_from_root(ObtXmlInst *i) obt_xml_tree(i, i->root->children); } -gchar *obt_xml_node_string(xmlNodePtr node) +gchar *obt_xml_node_string_unstripped(xmlNodePtr node) { xmlChar *c = xmlNodeGetContent(node); gchar *s; - if (c) g_strstrip((char*)c); /* strip leading/trailing whitespace */ s = g_strdup(c ? (gchar*)c : ""); xmlFree(c); return s; } +gchar *obt_xml_node_string(xmlNodePtr node) +{ + gchar* result = obt_xml_node_string_unstripped(node); + g_strstrip(result); /* strip leading/trailing whitespace */ + return result; +} + gint obt_xml_node_int(xmlNodePtr node) { xmlChar *c = xmlNodeGetContent(node); @@ -406,13 +419,12 @@ gboolean obt_xml_attr_int(xmlNodePtr node, const gchar *name, gint *value) return r; } -gboolean obt_xml_attr_string(xmlNodePtr node, const gchar *name, - gchar **value) +gboolean obt_xml_attr_string_unstripped(xmlNodePtr node, const gchar *name, + gchar **value) { xmlChar *c = xmlGetProp(node, (const xmlChar*) name); gboolean r = FALSE; if (c) { - g_strstrip((char*)c); /* strip leading/trailing whitespace */ *value = g_strdup((gchar*)c); r = TRUE; } @@ -420,6 +432,15 @@ gboolean obt_xml_attr_string(xmlNodePtr node, const gchar *name, return r; } +gboolean obt_xml_attr_string(xmlNodePtr node, const gchar *name, + gchar **value) +{ + gboolean result = obt_xml_attr_string_unstripped(node, name, value); + if (result) + g_strstrip(*value); /* strip leading/trailing whitespace */ + return result; +} + gboolean obt_xml_attr_contains(xmlNodePtr node, const gchar *name, const gchar *val) {