src/xml-label.h
src/xml-label-04.c
src/xml-label-04.h
+src/xml.c
+src/xml.h
src/pixbuf-cache.c
src/pixbuf-cache.h
src/base64.c
xml-label.h \
xml-label-04.c \
xml-label-04.h \
+ xml.c \
+ xml.h \
pixbuf-cache.c \
pixbuf-cache.h \
base64.c \
xml-label.h \
xml-label-04.c \
xml-label-04.h \
+ xml.c \
+ xml.h \
pixbuf-cache.c \
pixbuf-cache.h \
base64.c \
#include "prefs.h"
#include "util.h"
+#include "xml.h"
#include "template.h"
#include "debug.h"
template->page_size = "US Letter";
}
if (g_strcasecmp (template->page_size, "Other") == 0) {
- template->page_width =
- g_strtod (xmlGetProp (sheet_node, "width"), NULL);
- template->page_height =
- g_strtod (xmlGetProp (sheet_node, "height"), NULL);
+
+ template->page_width = gl_xml_get_prop_double (sheet_node, "width", 0);
+ template->page_height = gl_xml_get_prop_double (sheet_node, "height", 0);
+
} else {
paper = gnome_print_paper_get_by_name (template->page_size);
if (paper != NULL) {
{
xmlNodePtr node;
gchar *style;
- gchar *string;
gl_debug (DEBUG_TEMPLATE, "START");
g_free (style);
switch (template->label.style) {
+
case GL_TEMPLATE_STYLE_RECT:
- template->label.rect.w =
- g_strtod (xmlGetProp (label_node, "width"), NULL);
- template->label.rect.h =
- g_strtod (xmlGetProp (label_node, "height"), NULL);
- template->label.rect.r =
- g_strtod (xmlGetProp (label_node, "round"), NULL);
+ template->label.rect.w = gl_xml_get_prop_double (label_node, "width", 0);
+ template->label.rect.h = gl_xml_get_prop_double (label_node, "height", 0);
+ template->label.rect.r = gl_xml_get_prop_double (label_node, "round", 0);
break;
+
case GL_TEMPLATE_STYLE_ROUND:
- template->label.round.r =
- g_strtod (xmlGetProp (label_node, "radius"), NULL);
+ template->label.round.r = gl_xml_get_prop_double (label_node, "radius", 0);
break;
+
case GL_TEMPLATE_STYLE_CD:
- template->label.cd.r1 =
- g_strtod (xmlGetProp (label_node, "radius"), NULL);
- template->label.cd.r2 =
- g_strtod (xmlGetProp (label_node, "hole"), NULL);
- string = xmlGetProp (label_node, "width");
- if (string != NULL) {
- template->label.cd.w = g_strtod (string, NULL);
- g_free (string);
- } else {
- template->label.cd.w = 0.0;
- }
- string = xmlGetProp (label_node, "height");
- if (string != NULL) {
- template->label.cd.h = g_strtod (string, NULL);
- g_free (string);
- } else {
- template->label.cd.h = 0.0;
- }
+ template->label.cd.r1 = gl_xml_get_prop_double (label_node, "radius", 0);
+ template->label.cd.r2 = gl_xml_get_prop_double (label_node, "hole", 0);
+ template->label.cd.w = gl_xml_get_prop_double (label_node, "width", 0);
+ template->label.cd.h = gl_xml_get_prop_double (label_node, "height", 0);
break;
+
default:
break;
+
}
for (node = label_node->xmlChildrenNode; node != NULL;
xml_parse_layout (xmlNodePtr layout_node,
glTemplate *template)
{
- gint nx, ny;
- gdouble x0, y0, dx, dy;
- xmlNodePtr node;
+ gint nx, ny;
+ gdouble x0, y0, dx, dy;
+ xmlNodePtr node;
gl_debug (DEBUG_TEMPLATE, "START");
- sscanf (xmlGetProp (layout_node, "nx"), "%d", &nx);
- sscanf (xmlGetProp (layout_node, "ny"), "%d", &ny);
- x0 = g_strtod (xmlGetProp (layout_node, "x0"), NULL);
- y0 = g_strtod (xmlGetProp (layout_node, "y0"), NULL);
- dx = g_strtod (xmlGetProp (layout_node, "dx"), NULL);
- dy = g_strtod (xmlGetProp (layout_node, "dy"), NULL);
+ nx = gl_xml_get_prop_int (layout_node, "nx", 1);
+ ny = gl_xml_get_prop_int (layout_node, "ny", 1);
+
+ x0 = gl_xml_get_prop_double (layout_node, "x0", 0);
+ y0 = gl_xml_get_prop_double (layout_node, "y0", 0);
+
+ dx = gl_xml_get_prop_double (layout_node, "dx", 0);
+ dy = gl_xml_get_prop_double (layout_node, "dy", 0);
for (node = layout_node->xmlChildrenNode; node != NULL;
node = node->next) {
type = xmlGetProp (markup_node, "type");
if (g_strcasecmp (type, "margin") == 0) {
- size = g_strtod (xmlGetProp (markup_node, "size"), NULL);
+
+ size = gl_xml_get_prop_double (markup_node, "size", 0);
+
template->label.any.markups =
g_list_append (template->label.any.markups,
markup_margin_new (size));
+
} else if (g_strcasecmp (type, "line") == 0) {
- x1 = g_strtod (xmlGetProp (markup_node, "x1"), NULL);
- y1 = g_strtod (xmlGetProp (markup_node, "y1"), NULL);
- x2 = g_strtod (xmlGetProp (markup_node, "x2"), NULL);
- y2 = g_strtod (xmlGetProp (markup_node, "y2"), NULL);
+
+ x1 = gl_xml_get_prop_double (markup_node, "x1", 0);
+ y1 = gl_xml_get_prop_double (markup_node, "y1", 0);
+ x2 = gl_xml_get_prop_double (markup_node, "x2", 0);
+ y2 = gl_xml_get_prop_double (markup_node, "y2", 0);
+
template->label.any.markups =
g_list_append (template->label.any.markups,
markup_line_new (x1, y1, x2, y2));
}
+ g_free (type);
for (node = markup_node->xmlChildrenNode; node != NULL;
node = node->next) {
#include "label-ellipse.h"
#include "label-image.h"
#include "label-barcode.h"
+#include "xml.h"
#include "debug.h"
label = GL_LABEL (gl_label_new ());
- rotate_flag =
- !(g_strcasecmp (xmlGetProp (root, "rotate"), "false") == 0);
+ rotate_flag = gl_xml_get_prop_boolean (root, "rotate", FALSE);
gl_label_set_rotate_flag (label, rotate_flag);
for (node = root->xmlChildrenNode; node != NULL; node = node->next) {
gl_debug (DEBUG_XML, "START");
- x = g_strtod (xmlGetProp (object_node, "x"), NULL);
- y = g_strtod (xmlGetProp (object_node, "y"), NULL);
+ x = gl_xml_get_prop_double (object_node, "x", 0);
+ y = gl_xml_get_prop_double (object_node, "y", 0);
gl_label_object_set_position (object, x, y);
glTextNode *node_text;
GList *nodes, *lines;
gdouble w, h, x, y;
+ gchar *string;
gl_debug (DEBUG_XML, "START");
font_family = xmlGetProp (object_node, "font_family");
- font_size = g_strtod (xmlGetProp (object_node, "font_size"), NULL);
- font_weight =
- gl_util_string_to_weight (xmlGetProp (object_node, "font_weight"));
- font_italic_flag =
- !(g_strcasecmp (xmlGetProp (object_node, "font_italic"), "false") ==
- 0);
+ font_size = gl_xml_get_prop_double (object_node, "font_size", 0);
+ string = xmlGetProp (object_node, "font_weight");
+ font_weight = gl_util_string_to_weight (string);
+ g_free (string);
+ font_italic_flag = gl_xml_get_prop_boolean (object_node, "font_italic", FALSE);
- just = gl_util_string_to_just (xmlGetProp (object_node, "justify"));
+ string = xmlGetProp (object_node, "justify");
+ just = gl_util_string_to_just (string);
+ g_free (string);
- sscanf (xmlGetProp (object_node, "color"), "%x", &color);
+ color = gl_xml_get_prop_uint_hex (object_node, "color", 0);
gl_label_text_set_props (object,
font_family,
gl_debug (DEBUG_XML, "START");
- w = g_strtod (xmlGetProp (node, "w"), NULL);
- h = g_strtod (xmlGetProp (node, "h"), NULL);
+ w = gl_xml_get_prop_double (node, "w", 0);
+ h = gl_xml_get_prop_double (node, "h", 0);
- line_width = g_strtod (xmlGetProp (node, "line_width"), NULL);
+ line_width = gl_xml_get_prop_double (node, "line_width", 0);
- sscanf (xmlGetProp (node, "line_color"), "%x", &line_color);
- sscanf (xmlGetProp (node, "fill_color"), "%x", &fill_color);
+ line_color = gl_xml_get_prop_uint_hex (node, "line_color", 0);
+ fill_color = gl_xml_get_prop_uint_hex (node, "fill_color", 0);
gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
gl_label_box_set_line_width (object, line_width);
gl_debug (DEBUG_XML, "START");
- w = g_strtod (xmlGetProp (node, "dx"), NULL);
- h = g_strtod (xmlGetProp (node, "dy"), NULL);
+ w = gl_xml_get_prop_double (node, "dx", 0);
+ h = gl_xml_get_prop_double (node, "dy", 0);
- line_width = g_strtod (xmlGetProp (node, "line_width"), NULL);
+ line_width = gl_xml_get_prop_double (node, "line_width", 0);
- sscanf (xmlGetProp (node, "line_color"), "%x", &line_color);
+ line_color = gl_xml_get_prop_uint_hex (node, "line_color", 0);
gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
gl_label_line_set_line_width (object, line_width);
gl_debug (DEBUG_XML, "START");
- w = g_strtod (xmlGetProp (node, "w"), NULL);
- h = g_strtod (xmlGetProp (node, "h"), NULL);
+ w = gl_xml_get_prop_double (node, "w", 0);
+ h = gl_xml_get_prop_double (node, "h", 0);
- line_width = g_strtod (xmlGetProp (node, "line_width"), NULL);
+ line_width = gl_xml_get_prop_double (node, "line_width", 0);
- sscanf (xmlGetProp (node, "line_color"), "%x", &line_color);
- sscanf (xmlGetProp (node, "fill_color"), "%x", &fill_color);
+ line_color = gl_xml_get_prop_uint_hex (node, "line_color", 0);
+ fill_color = gl_xml_get_prop_uint_hex (node, "fill_color", 0);
gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
gl_label_ellipse_set_line_width (object, line_width);
gl_debug (DEBUG_XML, "START");
- w = g_strtod (xmlGetProp (node, "w"), NULL);
- h = g_strtod (xmlGetProp (node, "h"), NULL);
+ w = gl_xml_get_prop_double (node, "w", 0);
+ h = gl_xml_get_prop_double (node, "h", 0);
gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
filename = g_new0 (glTextNode, 1);
gdouble scale;
xmlNodePtr child;
glTextNode *text_node;
+ gchar *string;
gl_debug (DEBUG_XML, "START");
- sscanf (xmlGetProp (node, "color"), "%x", &color);
- style = gl_barcode_text_to_style (xmlGetProp (node, "style"));
- text_flag = !(g_strcasecmp (xmlGetProp (node, "text"), "false") == 0);
- scale = g_strtod (xmlGetProp (node, "scale"), NULL);
+ color = gl_xml_get_prop_uint_hex (node, "color", 0);
+
+ string = xmlGetProp (node, "style");
+ style = gl_barcode_text_to_style (string);
+ g_free (string);
+
+ text_flag = gl_xml_get_prop_boolean (node, "text", FALSE);
+ scale = gl_xml_get_prop_double (node, "scale", 1.0);
if (scale == 0.0) {
scale = 0.5; /* Set to a valid value */
}
{
glMerge *merge;
xmlNodePtr child;
+ gchar *string;
gl_debug (DEBUG_XML, "START");
- merge = gl_merge_new (xmlGetProp (node, "type"));
- gl_merge_set_src (merge, xmlGetProp (node, "src"));
+ string = xmlGetProp (node, "type");
+ merge = gl_merge_new (string);
+ g_free (string);
+
+ string = xmlGetProp (node, "src");
+ gl_merge_set_src (merge, string);
+ g_free (string);
gl_label_set_merge (label, merge);
#include "base64.h"
#include "xml-label.h"
#include "xml-label-04.h"
+#include "xml.h"
#include "util.h"
#include "debug.h"
xml_parse_objects (xmlNodePtr objects_node,
glLabel *label)
{
- gboolean rotate_flag;
- xmlNodePtr node;
+ gboolean rotate_flag;
+ xmlNodePtr node;
gl_debug (DEBUG_XML, "START");
- rotate_flag =
- !(g_strcasecmp (xmlGetProp (objects_node, "rotate"), "false") == 0);
+ rotate_flag = gl_xml_get_prop_boolean (objects_node, "rotate", FALSE);
gl_label_set_rotate_flag (label, rotate_flag);
for (node = objects_node->xmlChildrenNode; node != NULL; node = node->next) {
{
glLabelObject *object;
gdouble x, y;
- gchar *type_string;
+ gchar *string;
gdouble affine[6];
gl_debug (DEBUG_XML, "START");
- type_string = xmlGetProp (object_node, "type");
+ string = xmlGetProp (object_node, "type");
- if ( g_strcasecmp (type_string, "text") == 0 ) {
+ if ( g_strcasecmp (string, "text") == 0 ) {
object = xml_parse_text_props (object_node, label);
- } else if ( g_strcasecmp (type_string, "box") == 0 ) {
+ } else if ( g_strcasecmp (string, "box") == 0 ) {
object = xml_parse_box_props (object_node, label);
- } else if ( g_strcasecmp (type_string, "line") == 0 ) {
+ } else if ( g_strcasecmp (string, "line") == 0 ) {
object = xml_parse_line_props (object_node, label);
- } else if ( g_strcasecmp (type_string, "ellipse") == 0 ) {
+ } else if ( g_strcasecmp (string, "ellipse") == 0 ) {
object = xml_parse_ellipse_props (object_node, label);
- } else if ( g_strcasecmp (type_string, "image") == 0 ) {
+ } else if ( g_strcasecmp (string, "image") == 0 ) {
object = xml_parse_image_props (object_node, label);
- } else if ( g_strcasecmp (type_string, "barcode") == 0 ) {
+ } else if ( g_strcasecmp (string, "barcode") == 0 ) {
object = xml_parse_barcode_props (object_node, label);
} else {
- g_warning ("Unknown label object type \"%s\"", type_string);
+ g_warning ("Unknown label object type \"%s\"", string);
+ g_free (string);
return;
}
+ g_free (string);
- x = g_strtod (xmlGetProp (object_node, "x"), NULL);
- y = g_strtod (xmlGetProp (object_node, "y"), NULL);
+
+ x = gl_xml_get_prop_double (object_node, "x", 0.0);
+ y = gl_xml_get_prop_double (object_node, "y", 0.0);
gl_label_object_set_position (object, x, y);
- affine[0] = g_strtod (xmlGetProp (object_node, "a0"), NULL);
- affine[1] = g_strtod (xmlGetProp (object_node, "a1"), NULL);
- affine[2] = g_strtod (xmlGetProp (object_node, "a2"), NULL);
- affine[3] = g_strtod (xmlGetProp (object_node, "a3"), NULL);
- affine[4] = g_strtod (xmlGetProp (object_node, "a4"), NULL);
- affine[5] = g_strtod (xmlGetProp (object_node, "a5"), NULL);
+
+ affine[0] = gl_xml_get_prop_double (object_node, "a0", 0.0);
+ affine[1] = gl_xml_get_prop_double (object_node, "a1", 0.0);
+ affine[2] = gl_xml_get_prop_double (object_node, "a2", 0.0);
+ affine[3] = gl_xml_get_prop_double (object_node, "a3", 0.0);
+ affine[4] = gl_xml_get_prop_double (object_node, "a4", 0.0);
+ affine[5] = gl_xml_get_prop_double (object_node, "a5", 0.0);
gl_label_object_set_affine (object, affine);
+
gl_debug (DEBUG_XML, "END");
}
xmlNodePtr line_node, text_node;
glTextNode *node_text;
GList *nodes;
+ gchar *string;
gl_debug (DEBUG_XML, "START");
object = gl_label_text_new (label);
font_family = xmlGetProp (object_node, "font_family");
- font_size = g_strtod (xmlGetProp (object_node, "font_size"), NULL);
- font_weight = gl_util_string_to_weight (xmlGetProp (object_node,
- "font_weight"));
- font_italic_flag =
- !(g_strcasecmp (xmlGetProp (object_node, "font_italic"), "false") ==
- 0);
- just = gl_util_string_to_just (xmlGetProp (object_node, "justify"));
+ font_size = gl_xml_get_prop_double (object_node, "font_size", 0.0);
+
+ string = xmlGetProp (object_node, "font_weight");
+ font_weight = gl_util_string_to_weight (string);
+ g_free (string);
+
+ font_italic_flag = gl_xml_get_prop_boolean (object_node, "font_italic", FALSE);
+
+ string = xmlGetProp (object_node, "justify");
+ just = gl_util_string_to_just (string);
+ g_free (string);
- sscanf (xmlGetProp (object_node, "color"), "%x", &color);
+ color = gl_xml_get_prop_uint_hex (object_node, "color", 0);
lines = NULL;
for (line_node = object_node->xmlChildrenNode;
if (g_strcasecmp (text_node->name, "Field") == 0) {
node_text = g_new0 (glTextNode, 1);
node_text->field_flag = TRUE;
- node_text->data =
- xmlGetProp (text_node, "name");
- nodes =
- g_list_append (nodes, node_text);
+ node_text->data = xmlGetProp (text_node, "name");
+ nodes = g_list_append (nodes, node_text);
} else if (g_strcasecmp (text_node->name, "Literal") == 0) {
node_text = g_new0 (glTextNode, 1);
node_text->field_flag = FALSE;
object = gl_label_box_new (label);
- w = g_strtod (xmlGetProp (node, "w"), NULL);
- h = g_strtod (xmlGetProp (node, "h"), NULL);
+ w = gl_xml_get_prop_double (node, "w", 0);
+ h = gl_xml_get_prop_double (node, "h", 0);
- line_width = g_strtod (xmlGetProp (node, "line_width"), NULL);
+ line_width = gl_xml_get_prop_double (node, "line_width", 1.0);
- sscanf (xmlGetProp (node, "line_color"), "%x", &line_color);
- sscanf (xmlGetProp (node, "fill_color"), "%x", &fill_color);
+ line_color = gl_xml_get_prop_uint_hex (node, "line_color", 0);
+ fill_color = gl_xml_get_prop_uint_hex (node, "fill_color", 0);
gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
gl_label_box_set_line_width (GL_LABEL_BOX(object), line_width);
object = gl_label_line_new (label);
- w = g_strtod (xmlGetProp (node, "dx"), NULL);
- h = g_strtod (xmlGetProp (node, "dy"), NULL);
+ w = gl_xml_get_prop_double (node, "dx", 0);
+ h = gl_xml_get_prop_double (node, "dy", 0);
- line_width = g_strtod (xmlGetProp (node, "line_width"), NULL);
+ line_width = gl_xml_get_prop_double (node, "line_width", 1.0);
- sscanf (xmlGetProp (node, "line_color"), "%x", &line_color);
+ line_color = gl_xml_get_prop_uint_hex (node, "line_color", 0);
gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
gl_label_line_set_line_width (GL_LABEL_LINE(object), line_width);
object = gl_label_ellipse_new (label);
- w = g_strtod (xmlGetProp (node, "w"), NULL);
- h = g_strtod (xmlGetProp (node, "h"), NULL);
+ w = gl_xml_get_prop_double (node, "w", 0);
+ h = gl_xml_get_prop_double (node, "h", 0);
- line_width = g_strtod (xmlGetProp (node, "line_width"), NULL);
+ line_width = gl_xml_get_prop_double (node, "line_width", 1.0);
- sscanf (xmlGetProp (node, "line_color"), "%x", &line_color);
- sscanf (xmlGetProp (node, "fill_color"), "%x", &fill_color);
+ line_color = gl_xml_get_prop_uint_hex (node, "line_color", 0);
+ fill_color = gl_xml_get_prop_uint_hex (node, "fill_color", 0);
gl_label_object_set_size (GL_LABEL_OBJECT(object), w, h);
gl_label_ellipse_set_line_width (GL_LABEL_ELLIPSE(object), line_width);
object = gl_label_image_new (label);
- w = g_strtod (xmlGetProp (node, "w"), NULL);
- h = g_strtod (xmlGetProp (node, "h"), NULL);
+ w = gl_xml_get_prop_double (node, "w", 0);
+ h = gl_xml_get_prop_double (node, "h", 0);
filename = g_new0 (glTextNode, 1);
for (child = node->xmlChildrenNode; child != NULL; child = child->next) {
{
GObject *object;
xmlNodePtr child;
+ gchar *string;
glTextNode *text_node;
glBarcodeStyle style;
gboolean text_flag;
object = gl_label_barcode_new (label);
- sscanf (xmlGetProp (node, "color"), "%x", &color);
+ color = gl_xml_get_prop_uint_hex (node, "color", 0);
+
+ string = xmlGetProp (node, "style");
+ style = gl_barcode_text_to_style (string);
+ g_free (string);
- style = gl_barcode_text_to_style (xmlGetProp (node, "style"));
- text_flag = !(g_strcasecmp (xmlGetProp (node, "text"), "false") == 0);
- scale = g_strtod (xmlGetProp (node, "scale"), NULL);
+ text_flag = gl_xml_get_prop_boolean (node, "text", FALSE);
+
+ scale = gl_xml_get_prop_double (node, "scale", 1.0);
text_node = g_new0 (glTextNode, 1);
for (child = node->xmlChildrenNode; child != NULL; child = child->next) {
glLabel *label)
{
xmlNodePtr child;
+ gchar *string;
glMerge *merge;
- gchar *src;
gl_debug (DEBUG_XML, "START");
- merge = gl_merge_new (xmlGetProp (node, "type"));
- src = xmlGetProp (node, "src");
- gl_merge_set_src (merge, src);
+ string = xmlGetProp (node, "type");
+ merge = gl_merge_new (string);
+ g_free (string);
+
+ string = xmlGetProp (node, "src");
+ gl_merge_set_src (merge, string);
+ g_free (string);
gl_label_set_merge (label, merge);
--- /dev/null
+/*
+ * (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ * xml.c: GLabels xml utilities module
+ *
+ * Copyright (C) 2003 Jim Evins <evins@snaught.com>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <config.h>
+
+#include "xml.h"
+
+/*========================================================*/
+/* Private macros and constants. */
+/*========================================================*/
+
+/*========================================================*/
+/* Private types. */
+/*========================================================*/
+
+/*========================================================*/
+/* Private globals. */
+/*========================================================*/
+
+/*========================================================*/
+/* Private function prototypes. */
+/*========================================================*/
+
+\f
+/****************************************************************************/
+/* Return value of property as a double. */
+/****************************************************************************/
+gdouble
+gl_xml_get_prop_double (xmlNodePtr node,
+ const gchar *property,
+ gdouble default_val)
+{
+ gdouble val;
+ gchar *string;
+
+ string = xmlGetProp (node, property);
+ if ( string != NULL ) {
+ val = g_strtod (string, NULL);
+ g_free (string);
+ return val;
+ }
+
+ return default_val;
+}
+
+/****************************************************************************/
+/* Return value of property as a boolean. */
+/****************************************************************************/
+gboolean
+gl_xml_get_prop_boolean (xmlNodePtr node,
+ const gchar *property,
+ gboolean default_val)
+{
+ gboolean val;
+ gchar *string;
+
+ string = xmlGetProp (node, property);
+ if ( string != NULL ) {
+ val = !(g_strcasecmp (string, "false") == 0);
+ g_free (string);
+ return val;
+ }
+
+ return default_val;
+}
+
+
+/****************************************************************************/
+/* Return value of property as an int. . */
+/****************************************************************************/
+gint
+gl_xml_get_prop_int (xmlNodePtr node,
+ const gchar *property,
+ gint default_val)
+{
+ gint val;
+ gchar *string;
+
+ string = xmlGetProp (node, property);
+ if ( string != NULL ) {
+ sscanf (string, "%d", &val);
+ g_free (string);
+ return val;
+ }
+
+ return default_val;
+}
+
+
+/****************************************************************************/
+/* Return value of hex property as an unsigned int. */
+/****************************************************************************/
+guint
+gl_xml_get_prop_uint_hex (xmlNodePtr node,
+ const gchar *property,
+ guint default_val)
+{
+ guint val;
+ gchar *string;
+
+ string = xmlGetProp (node, property);
+ if ( string != NULL ) {
+ sscanf (string, "%x", &val);
+ g_free (string);
+ return val;
+ }
+
+ return default_val;
+}
+
+
--- /dev/null
+/*
+ * (GLABELS) Label and Business Card Creation program for GNOME
+ *
+ * xml.h: GLabels xml utilities header file
+ *
+ * Copyright (C) 2003 Jim Evins <evins@snaught.com>.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef __XML_H__
+#define __XML_H__
+
+#include <glib.h>
+#include <libxml/tree.h>
+
+G_BEGIN_DECLS
+
+gdouble gl_xml_get_prop_double (xmlNodePtr node,
+ const gchar *property,
+ gdouble default_val);
+
+gboolean gl_xml_get_prop_boolean (xmlNodePtr node,
+ const gchar *property,
+ gboolean default_val);
+
+gint gl_xml_get_prop_int (xmlNodePtr node,
+ const gchar *property,
+ gint default_val);
+
+guint gl_xml_get_prop_uint_hex (xmlNodePtr node,
+ const gchar *property,
+ guint default_val);
+
+G_END_DECLS
+
+
+#endif /* __XML_H__ */