2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * xml.c: GLabels xml utilities module
6 * Copyright (C) 2003 Jim Evins <evins@snaught.com>.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 /*========================================================*/
27 /* Private macros and constants. */
28 /*========================================================*/
30 /*========================================================*/
32 /*========================================================*/
34 /*========================================================*/
35 /* Private globals. */
36 /*========================================================*/
38 /*========================================================*/
39 /* Private function prototypes. */
40 /*========================================================*/
43 /****************************************************************************/
44 /* Return value of property as a double. */
45 /****************************************************************************/
47 gl_xml_get_prop_double (xmlNodePtr node,
48 const gchar *property,
54 string = xmlGetProp (node, property);
55 if ( string != NULL ) {
56 val = g_strtod (string, NULL);
64 /****************************************************************************/
65 /* Return value of property as a boolean. */
66 /****************************************************************************/
68 gl_xml_get_prop_boolean (xmlNodePtr node,
69 const gchar *property,
75 string = xmlGetProp (node, property);
76 if ( string != NULL ) {
77 val = !(g_strcasecmp (string, "false") == 0);
86 /****************************************************************************/
87 /* Return value of property as an int. . */
88 /****************************************************************************/
90 gl_xml_get_prop_int (xmlNodePtr node,
91 const gchar *property,
97 string = xmlGetProp (node, property);
98 if ( string != NULL ) {
99 sscanf (string, "%d", &val);
108 /****************************************************************************/
109 /* Return value of hex property as an unsigned int. */
110 /****************************************************************************/
112 gl_xml_get_prop_uint_hex (xmlNodePtr node,
113 const gchar *property,
119 string = xmlGetProp (node, property);
120 if ( string != NULL ) {
121 sscanf (string, "%x", &val);
130 /****************************************************************************/
131 /* Set property from double. */
132 /****************************************************************************/
134 gl_xml_set_prop_double (xmlNodePtr node,
135 const gchar *property,
140 string = g_strdup_printf ("%g", val);
141 xmlSetProp (node, property, string);
145 /****************************************************************************/
146 /* Set property from boolean. */
147 /****************************************************************************/
149 gl_xml_set_prop_boolean (xmlNodePtr node,
150 const gchar *property,
153 xmlSetProp (node, property, (val ? "True" : "False"));
156 /****************************************************************************/
157 /* Set property from int. */
158 /****************************************************************************/
160 gl_xml_set_prop_int (xmlNodePtr node,
161 const gchar *property,
166 string = g_strdup_printf ("%d", val);
167 xmlSetProp (node, property, string);
171 /****************************************************************************/
172 /* Set property from uint in hex. */
173 /****************************************************************************/
175 gl_xml_set_prop_uint_hex (xmlNodePtr node,
176 const gchar *property,
181 string = g_strdup_printf ("0x%08x", val);
182 xmlSetProp (node, property, string);