1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
4 * vim: tabstop=4 shiftwidth=4 noexpandtab :
7 #include <libxml/tree.h>
12 jam_xmlGetString(xmlDocPtr doc
, xmlNodePtr node
) {
13 /* we can't guarantee that xmlFree and g_free do the same thing,
14 * so we must copy this string into a glib-allocated string. */
15 xmlChar
*str
= xmlNodeListGetString(doc
, node
->xmlChildrenNode
, TRUE
);
16 char *ret
= g_strdup((char*)str
);
22 jam_xmlGetUInt32(xmlDocPtr doc
, xmlNodePtr node
) {
24 xmlChar
*value
= xmlNodeListGetString(doc
, node
->xmlChildrenNode
, TRUE
);
26 ret
= atol((char*)value
);
33 jam_xmlGetInt(xmlDocPtr doc
, xmlNodePtr node
, int *ret
) {
34 xmlChar
*value
= xmlNodeListGetString(doc
, node
->xmlChildrenNode
, TRUE
);
36 *ret
= atoi((char*)value
);
44 jam_xmlAddInt(xmlNodePtr node
, char *name
, int val
) {
46 sprintf(buf
, "%d", val
);
47 return xmlNewTextChild(node
, NULL
, BAD_CAST name
, BAD_CAST buf
);
51 jam_xmlNewDoc(xmlDocPtr
*doc
, xmlNodePtr
*node
, char *name
) {
52 *doc
= xmlNewDoc(BAD_CAST
"1.0");
53 *node
= xmlNewDocNode(*doc
, NULL
, BAD_CAST name
, NULL
);
54 xmlDocSetRootElement(*doc
, *node
);
58 jam_xmlSetIntProp(xmlNodePtr node
, const char *name
, int value
) {
60 g_snprintf(buf
, 20, "%d", value
);
61 xmlSetProp(node
, BAD_CAST name
, BAD_CAST buf
);
65 jam_xmlGetIntProp(xmlNodePtr node
, const char *name
, int *value
) {
67 prop
= xmlGetProp(node
, BAD_CAST name
);
69 *value
= atoi((char*)prop
);