Add functions to set the value of an xml node
authorDana Jansens <danakj@orodu.net>
Mon, 8 Aug 2011 21:44:06 +0000 (17:44 -0400)
committerDana Jansens <danakj@orodu.net>
Sun, 16 Oct 2011 22:56:02 +0000 (18:56 -0400)
obt/xml.c
obt/xml.h

index 0d5420ed4a0f30db25749416cb5c2502f5f8e29e..8ba61a62143d9119459f28ec8aabffd9b4b64e2c 100644 (file)
--- a/obt/xml.c
+++ b/obt/xml.c
@@ -429,6 +429,23 @@ xmlNodePtr obt_xml_find_sibling(xmlNodePtr node, const gchar *tag)
     return NULL;
 }
 
+void obt_xml_node_set_string(xmlNodePtr node, const gchar *s)
+{
+    xmlNodeSetContent(node, (const xmlChar*)s);
+}
+
+void obt_xml_node_set_int(xmlNodePtr node, gint i)
+{
+    gchar *s = g_strdup_printf("%d", i);
+    obt_xml_node_set_string(node, s);
+    g_free(s);
+}
+
+void obt_xml_node_set_bool(xmlNodePtr node, gboolean b)
+{
+    obt_xml_node_set_string(node, b ? "yes" : "no");
+}
+
 gboolean obt_xml_attr_bool(xmlNodePtr node, const gchar *name,
                            gboolean *value)
 {
@@ -655,3 +672,23 @@ gboolean obt_xml_path_bool(xmlNodePtr subtree, const gchar *path,
     return n ? obt_xml_node_bool(n) : FALSE;
 }
 
+void obt_xml_path_set_string(xmlNodePtr subtree, const gchar *path,
+                             const gchar *value)
+{
+    xmlNodePtr n = obt_xml_path_get_node(subtree, path, "");
+    obt_xml_node_set_string(n, value);
+}
+
+void obt_xml_path_set_int(xmlNodePtr subtree, const gchar *path,
+                          gint value)
+{
+    xmlNodePtr n = obt_xml_path_get_node(subtree, path, "");
+    obt_xml_node_set_int(n, value);
+}
+
+void obt_xml_path_set_bool(xmlNodePtr subtree, const gchar *path,
+                           gboolean value)
+{
+    xmlNodePtr n = obt_xml_path_get_node(subtree, path, "");
+    obt_xml_node_set_bool(n, value);
+}
index cee36fc000da0d9a6156bd5a51bcc1e918100773..19b5860eefce2130ccdeda796bd608bd090aebfb 100644 (file)
--- a/obt/xml.h
+++ b/obt/xml.h
@@ -87,6 +87,10 @@ gchar   *obt_xml_node_string   (xmlNodePtr node);
 gint     obt_xml_node_int      (xmlNodePtr node);
 gboolean obt_xml_node_bool     (xmlNodePtr node);
 
+void obt_xml_node_set_string(xmlNodePtr node, const gchar *s);
+void obt_xml_node_set_int(xmlNodePtr node, gint i);
+void obt_xml_node_set_bool(xmlNodePtr node, gboolean b);
+
 gboolean obt_xml_attr_contains (xmlNodePtr node, const gchar *name,
                                 const gchar *val);
 gboolean obt_xml_attr_string   (xmlNodePtr node, const gchar *name,
@@ -135,6 +139,12 @@ int obt_xml_path_int(xmlNodePtr subtree, const gchar *path,
 gboolean obt_xml_path_bool(xmlNodePtr subtree, const gchar *path,
                            const gchar *default_value);
 
+void obt_xml_path_set_string(xmlNodePtr subtree, const gchar *path,
+                             const gchar *value);
+void obt_xml_path_set_int(xmlNodePtr subtree, const gchar *path,
+                          gint value);
+void obt_xml_path_set_bool(xmlNodePtr subtree, const gchar *path,
+                           gboolean value);
 
 G_END_DECLS