From c5216a46a6d0adfed2dcb554315b6cd2976a2089 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Sat, 15 Oct 2011 13:43:07 -0400 Subject: [PATCH] Add obt_xml_file_path() and obt_xml_node_string_raw() and don't return text in child nodes. --- obt/xml.c | 32 ++++++++++++++++++++++++++++---- obt/xml.h | 9 ++++++++- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/obt/xml.c b/obt/xml.c index 8ba61a62..f1ab98a3 100644 --- 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); diff --git a/obt/xml.h b/obt/xml.h index 19b5860e..1430073a 100644 --- 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); -- 2.39.2