From b3ea4571c7c1334cec251a9a3899f99ec6099d65 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 8 Aug 2011 17:44:06 -0400 Subject: [PATCH] Add functions to set the value of an xml node --- obt/xml.c | 37 +++++++++++++++++++++++++++++++++++++ obt/xml.h | 10 ++++++++++ 2 files changed, 47 insertions(+) diff --git a/obt/xml.c b/obt/xml.c index 0d5420ed..8ba61a62 100644 --- 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); +} diff --git a/obt/xml.h b/obt/xml.h index cee36fc0..19b5860e 100644 --- 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 -- 2.39.2