2 * Copyright 2008 Codethink Ltd.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #include <libxml/parser.h>
24 #include <libxml/tree.h>
28 #define ACCESSIBLE_NODE ((const xmlChar *) "accessible")
29 #define INTERFACE_NODE ((const xmlChar *) "interface")
31 #define NAME_ATTR ((const xmlChar *) "name")
32 #define DESC_ATTR ((const xmlChar *) "description")
33 #define ROLE_ATTR ((const xmlChar *) "role")
36 create_atk_object_from_element(xmlNode *element)
40 MyAtkObject *obj = NULL;
41 MyAtkObject *child_obj;
48 name = xmlGetProp(element, NAME_ATTR);
49 description = xmlGetProp(element, DESC_ATTR);
50 role_text = xmlGetProp(element, ROLE_ATTR);
51 role = atoi(role_text);
53 obj = MY_ATK_OBJECT(g_object_new(MY_TYPE_ATK_OBJECT,
54 "accessible-name", name,
55 "accessible-description", description,
56 "accessible-role", role,
59 child_node = element->xmlChildrenNode;
60 while (child_node != NULL)
62 if (!xmlStrcmp(child_node->name, ACCESSIBLE_NODE))
64 child_obj = create_atk_object_from_element(child_node);
65 my_atk_object_add_child(obj, child_obj);
67 child_node = child_node->next;
73 * Reads the XML from filename and uses it
74 * to create a tree of MyAtkObjects.
76 * returns: The root object of the tree.
79 atk_object_xml_parse(gchar *filename)
82 xmlNode *root_element;
83 MyAtkObject *new_atk_object = NULL;
85 doc = xmlReadFile(filename, NULL, 0);
86 g_assert(doc != NULL);
88 root_element = xmlDocGetRootElement(doc);
90 if (!xmlStrcmp(root_element->name, ACCESSIBLE_NODE))
91 new_atk_object = create_atk_object_from_element(root_element);
94 return new_atk_object;