'smart qotes' now will replace '<', '>' and '&' inside 'pre' and 'code' tags
[k8lowj.git] / src / jam_xml.c
blob9b72a278f93e4b62ad3dae1f20a942ca9a0e86cd
1 /* logjam - a GTK client for LiveJournal.
2 * Copyright (C) 2000-2003 Evan Martin <evan@livejournal.com>
4 * vim: tabstop=4 shiftwidth=4 noexpandtab :
5 */
7 #include <libxml/tree.h>
9 #include "jam_xml.h"
11 char*
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);
17 xmlFree(str);
18 return ret;
21 guint32
22 jam_xmlGetUInt32(xmlDocPtr doc, xmlNodePtr node) {
23 guint32 ret = 0;
24 xmlChar *value = xmlNodeListGetString(doc, node->xmlChildrenNode, TRUE);
25 if (value) {
26 ret = atol((char*)value);
27 xmlFree(value);
29 return ret;
32 gboolean
33 jam_xmlGetInt(xmlDocPtr doc, xmlNodePtr node, int *ret) {
34 xmlChar *value = xmlNodeListGetString(doc, node->xmlChildrenNode, TRUE);
35 if (value) {
36 *ret = atoi((char*)value);
37 xmlFree(value);
38 return TRUE;
40 return FALSE;
43 xmlNodePtr
44 jam_xmlAddInt(xmlNodePtr node, char *name, int val) {
45 char buf[20];
46 sprintf(buf, "%d", val);
47 return xmlNewTextChild(node, NULL, BAD_CAST name, BAD_CAST buf);
50 void
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);
57 void
58 jam_xmlSetIntProp(xmlNodePtr node, const char *name, int value) {
59 char buf[20];
60 g_snprintf(buf, 20, "%d", value);
61 xmlSetProp(node, BAD_CAST name, BAD_CAST buf);
64 gboolean
65 jam_xmlGetIntProp(xmlNodePtr node, const char *name, int *value) {
66 xmlChar *prop;
67 prop = xmlGetProp(node, BAD_CAST name);
68 if (prop) {
69 *value = atoi((char*)prop);
70 xmlFree(prop);
71 return TRUE;
73 return FALSE;