Add obt_xml_file_path() and obt_xml_node_string_raw() and don't return text in child...
authorDana Jansens <danakj@orodu.net>
Sat, 15 Oct 2011 17:43:07 +0000 (13:43 -0400)
committerDana Jansens <danakj@orodu.net>
Sun, 16 Oct 2011 22:58:03 +0000 (18:58 -0400)
obt/xml.c
obt/xml.h

index 8ba61a62143d9119459f28ec8aabffd9b4b64e2c..f1ab98a323e8d342794213485106d73fda0491a9 100644 (file)
--- a/obt/xml.c
+++ b/obt/xml.c
@@ -345,6 +345,11 @@ gboolean obt_xml_save_cache_file(ObtXmlInst *inst,
     return ok;
 }
 
+const gchar* obt_xml_file_path(ObtXmlInst *inst)
+{
+    return inst->path;
+}
+
 void obt_xml_close(ObtXmlInst *i)
 {
     if (i && i->doc) {
@@ -374,20 +379,37 @@ void obt_xml_tree_from_root(ObtXmlInst *i)
     obt_xml_tree(i, i->root->children);
 }
 
+guint obt_xml_node_line(xmlNodePtr node)
+{
+    return XML_GET_LINE(node);
+}
+
 gchar *obt_xml_node_string(xmlNodePtr node)
 {
-    xmlChar *c = xmlNodeGetContent(node);
+    xmlChar *c;
     gchar *s;
+    c = xmlNodeIsText(node->children) ? xmlNodeGetContent(node) : NULL;
     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_raw(xmlNodePtr node)
+{
+    xmlChar *c;
+    gchar *s;
+    c = xmlNodeIsText(node->children) ? xmlNodeGetContent(node) : NULL;
+    s = g_strdup(c ? (gchar*)c : "");
+    xmlFree(c);
+    return s;
+}
+
 gint obt_xml_node_int(xmlNodePtr node)
 {
-    xmlChar *c = xmlNodeGetContent(node);
+    xmlChar *c;
     gint i;
+    c = xmlNodeIsText(node->children) ? xmlNodeGetContent(node) : NULL;
     if (c) g_strstrip((char*)c); /* strip leading/trailing whitespace */
     i = c ? atoi((gchar*)c) : 0;
     xmlFree(c);
@@ -396,8 +418,9 @@ gint obt_xml_node_int(xmlNodePtr node)
 
 gboolean obt_xml_node_bool(xmlNodePtr node)
 {
-    xmlChar *c = xmlNodeGetContent(node);
+    xmlChar *c;
     gboolean b = FALSE;
+    c = xmlNodeIsText(node->children) ? xmlNodeGetContent(node) : NULL;
     if (c) g_strstrip((char*)c); /* strip leading/trailing whitespace */
     if (c && !xmlStrcasecmp(c, (const xmlChar*) "true"))
         b = TRUE;
@@ -411,8 +434,9 @@ gboolean obt_xml_node_bool(xmlNodePtr node)
 
 gboolean obt_xml_node_contains(xmlNodePtr node, const gchar *val)
 {
-    xmlChar *c = xmlNodeGetContent(node);
+    xmlChar *c;
     gboolean r;
+    c = xmlNodeIsText(node->children) ? xmlNodeGetContent(node) : NULL;
     if (c) g_strstrip((char*)c); /* strip leading/trailing whitespace */
     r = !xmlStrcasecmp(c, (const xmlChar*) val);
     xmlFree(c);
index 19b5860eefce2130ccdeda796bd608bd090aebfb..1430073a9825c426f3e9a3cdbc8936b8ec42dbfe 100644 (file)
--- a/obt/xml.h
+++ b/obt/xml.h
@@ -69,6 +69,11 @@ gboolean obt_xml_save_cache_file(ObtXmlInst *inst,
 xmlDocPtr obt_xml_doc(ObtXmlInst *inst);
 xmlNodePtr obt_xml_root(ObtXmlInst *inst);
 
+/*! Returns the path to the file loaded by @inst, if one exists, or NULL.
+  The returned string is owned by @inst and will be freed along with it.
+ */
+const gchar* obt_xml_file_path(ObtXmlInst *inst);
+
 void obt_xml_close(ObtXmlInst *inst);
 
 void obt_xml_register(ObtXmlInst *inst, const gchar *tag,
@@ -82,8 +87,10 @@ void obt_xml_tree_from_root(ObtXmlInst *i);
 
 xmlNodePtr obt_xml_find_sibling(xmlNodePtr node, const gchar *name);
 
+guint    obt_xml_node_line     (xmlNodePtr node);
 gboolean obt_xml_node_contains (xmlNodePtr node, const gchar *val);
-gchar   *obt_xml_node_string   (xmlNodePtr node);
+gchar   *obt_xml_node_string   (xmlNodePtr node);  /* strips whitespace */
+gchar   *obt_xml_node_string_raw(xmlNodePtr node); /* unstripped version */
 gint     obt_xml_node_int      (xmlNodePtr node);
 gboolean obt_xml_node_bool     (xmlNodePtr node);