3 * Copyright (C) 2006-2010 Jim Evins <evins@snaught.com>.
5 * This file is part of libglabels.
7 * libglabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * libglabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with libglabels. If not, see <http://www.gnu.org/licenses/>.
23 #include "lgl-xml-category.h"
25 #include <glib/gi18n.h>
30 #include "libglabels-private.h"
34 /*===========================================*/
36 /*===========================================*/
38 /*===========================================*/
40 /*===========================================*/
42 /*===========================================*/
43 /* Local function prototypes */
44 /*===========================================*/
48 * lgl_xml_category_read_categories_from_file:
49 * @utf8_filename: Filename of categories file (name encoded as UTF-8)
51 * Read category definitions from a file.
53 * Returns: a list of #lglCategory structures.
57 lgl_xml_category_read_categories_from_file (gchar *utf8_filename)
61 xmlDocPtr categories_doc;
65 filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
68 g_message ("Utf8 filename conversion error");
72 categories_doc = xmlParseFile (filename);
75 g_message ("\"%s\" is not a glabels category file (not XML)",
80 categories = lgl_xml_category_parse_categories_doc (categories_doc);
83 xmlFreeDoc (categories_doc);
90 * lgl_xml_category_parse_categories_doc:
91 * @categories_doc: libxml #xmlDocPtr tree, representing a categories
94 * Read category definitions from a libxml #xmlDocPtr tree.
96 * Returns: a list of #lglCategory structures.
100 lgl_xml_category_parse_categories_doc (xmlDocPtr categories_doc)
102 GList *categories = NULL;
103 xmlNodePtr root, node;
104 lglCategory *category;
108 root = xmlDocGetRootElement (categories_doc);
109 if (!root || !root->name)
111 g_message ("\"%s\" is not a glabels category file (no root node)",
112 categories_doc->name);
113 xmlFreeDoc (categories_doc);
116 if (!lgl_xml_is_node (root, "Glabels-categories"))
118 g_message ("\"%s\" is not a glabels category file (wrong root node)",
119 categories_doc->name);
120 xmlFreeDoc (categories_doc);
124 for (node = root->xmlChildrenNode; node != NULL; node = node->next)
127 if (lgl_xml_is_node (node, "Category"))
129 category = lgl_xml_category_parse_category_node (node);
130 categories = g_list_append (categories, category);
134 if ( !xmlNodeIsText(node) )
136 if (!lgl_xml_is_node (node, "comment"))
138 g_message ("bad node = \"%s\"",node->name);
149 * lgl_xml_category_parse_category_node:
150 * @category_node: libxml #xmlNodePtr category node from a #xmlDocPtr tree.
152 * Read a single category definition from a libxml #xmlNodePtr node.
154 * Returns: a pointer to a newly created #lglCategory structure.
158 lgl_xml_category_parse_category_node (xmlNodePtr category_node)
160 lglCategory *category;
165 id = lgl_xml_get_prop_string (category_node, "id", NULL);
166 name = lgl_xml_get_prop_i18n_string (category_node, "name", NULL);
168 category = lgl_category_new (id, name);
179 * Local Variables: -- emacs
181 * c-basic-offset: 8 -- emacs
182 * tab-width: 8 -- emacs
183 * indent-tabs-mode: nil -- emacs