3 * Copyright (C) 2003-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-vendor.h"
25 #include <glib/gi18n.h>
30 #include "libglabels-private.h"
34 /*===========================================*/
36 /*===========================================*/
38 /*===========================================*/
40 /*===========================================*/
42 /*===========================================*/
43 /* Local function prototypes */
44 /*===========================================*/
48 * lgl_xml_vendor_read_vendors_from_file:
49 * @utf8_filename: Filename of vendors file (name encoded as UTF-8)
51 * Read vendor definitions from a file.
53 * Returns: a list of #lglVendor structures.
57 lgl_xml_vendor_read_vendors_from_file (gchar *utf8_filename)
61 xmlDocPtr vendors_doc;
65 filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL);
68 g_message ("Utf8 filename conversion error");
72 vendors_doc = xmlParseFile (filename);
75 g_message ("\"%s\" is not a glabels vendor file (not XML)",
80 vendors = lgl_xml_vendor_parse_vendors_doc (vendors_doc);
83 xmlFreeDoc (vendors_doc);
90 * lgl_xml_vendor_parse_vendors_doc:
91 * @vendors_doc: libxml #xmlDocPtr tree, representing a vendors definition file.
93 * Read vendor definitions from a libxml #xmlDocPtr tree.
95 * Returns: a list of #lglVendor structures.
99 lgl_xml_vendor_parse_vendors_doc (xmlDocPtr vendors_doc)
101 GList *vendors = NULL;
102 xmlNodePtr root, node;
107 root = xmlDocGetRootElement (vendors_doc);
108 if (!root || !root->name)
110 g_message ("\"%s\" is not a glabels vendor file (no root node)",
112 xmlFreeDoc (vendors_doc);
115 if (!lgl_xml_is_node (root, "Glabels-vendors"))
117 g_message ("\"%s\" is not a glabels vendor file (wrong root node)",
119 xmlFreeDoc (vendors_doc);
123 for (node = root->xmlChildrenNode; node != NULL; node = node->next)
125 if (lgl_xml_is_node (node, "Vendor"))
127 vendor = lgl_xml_vendor_parse_vendor_node (node);
128 vendors = g_list_append (vendors, vendor);
132 if ( !xmlNodeIsText(node) )
134 if (!lgl_xml_is_node (node, "comment"))
136 g_message ("bad node = \"%s\"",node->name);
147 * lgl_xml_vendor_parse_vendor_node:
148 * @vendor_node: libxml #xmlNodePtr vendor node from a #xmlDocPtr tree.
150 * Read a single vendor definition from a libxml #xmlNodePtr node.
152 * Returns: a pointer to a newly created #lglVendor structure.
156 lgl_xml_vendor_parse_vendor_node (xmlNodePtr vendor_node)
163 name = lgl_xml_get_prop_i18n_string (vendor_node, "name", NULL);
165 vendor = lgl_vendor_new (name);
167 vendor->url = lgl_xml_get_prop_i18n_string (vendor_node, "url", NULL);
177 * Local Variables: -- emacs
179 * c-basic-offset: 8 -- emacs
180 * tab-width: 8 -- emacs
181 * indent-tabs-mode: nil -- emacs