1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
4 #include <libxml/tree.h>
9 char *jam_xmlGetString (xmlDocPtr doc
, xmlNodePtr node
) {
10 /* we can't guarantee that xmlFree and g_free do the same thing,
11 * so we must copy this string into a glib-allocated string. */
12 xmlChar
*str
= xmlNodeListGetString(doc
, node
->xmlChildrenNode
, TRUE
);
13 char *ret
= g_strdup((char *)str
);
19 guint32
jam_xmlGetUInt32 (xmlDocPtr doc
, xmlNodePtr node
) {
21 xmlChar
*value
= xmlNodeListGetString(doc
, node
->xmlChildrenNode
, TRUE
);
23 ret
= atol((char *)value
);
30 gboolean
jam_xmlGetInt (xmlDocPtr doc
, xmlNodePtr node
, int *ret
) {
31 xmlChar
*value
= xmlNodeListGetString(doc
, node
->xmlChildrenNode
, TRUE
);
33 *ret
= atoi((char *)value
);
41 xmlNodePtr
jam_xmlAddInt (xmlNodePtr node
, char *name
, int val
) {
43 sprintf(buf
, "%d", val
);
44 return xmlNewTextChild(node
, NULL
, BAD_CAST name
, BAD_CAST buf
);
48 void jam_xmlNewDoc (xmlDocPtr
*doc
, xmlNodePtr
*node
, char *name
) {
49 *doc
= xmlNewDoc(BAD_CAST
"1.0");
50 *node
= xmlNewDocNode(*doc
, NULL
, BAD_CAST name
, NULL
);
51 xmlDocSetRootElement(*doc
, *node
);
55 void jam_xmlSetIntProp (xmlNodePtr node
, const char *name
, int value
) {
57 g_snprintf(buf
, 20, "%d", value
);
58 xmlSetProp(node
, BAD_CAST name
, BAD_CAST buf
);
62 gboolean
jam_xmlGetIntProp (xmlNodePtr node
, const char *name
, int *value
) {
64 prop
= xmlGetProp(node
, BAD_CAST name
);
66 *value
= atoi((char *)prop
);