1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 obt/xml.h for the Openbox window manager
4 Copyright (c) 2003-2007 Dana Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
22 #include <libxml/parser.h>
27 typedef struct _ObtXmlInst ObtXmlInst;
29 typedef void (*ObtXmlCallback)(xmlNodePtr node, gpointer data);
31 ObtXmlInst* obt_xml_instance_new(void);
32 void obt_xml_instance_ref(ObtXmlInst *inst);
33 void obt_xml_instance_unref(ObtXmlInst *inst);
35 void obt_xml_new_file(ObtXmlInst *inst,
36 const gchar *root_node);
38 gboolean obt_xml_load_file(ObtXmlInst *inst,
40 const gchar *root_node);
41 gboolean obt_xml_load_cache_file(ObtXmlInst *inst,
43 const gchar *filename,
44 const gchar *root_node);
45 gboolean obt_xml_load_config_file(ObtXmlInst *inst,
47 const gchar *filename,
48 const gchar *root_node);
49 gboolean obt_xml_load_data_file(ObtXmlInst *inst,
51 const gchar *filename,
52 const gchar *root_node);
53 gboolean obt_xml_load_theme_file(ObtXmlInst *inst,
56 const gchar *filename,
57 const gchar *root_node);
58 gboolean obt_xml_load_mem(ObtXmlInst *inst,
59 gpointer data, guint len, const gchar *root_node);
61 gboolean obt_xml_save_file(ObtXmlInst *inst,
64 gboolean obt_xml_save_cache_file(ObtXmlInst *inst,
66 const gchar *filename,
69 xmlDocPtr obt_xml_doc(ObtXmlInst *inst);
70 xmlNodePtr obt_xml_root(ObtXmlInst *inst);
72 void obt_xml_close(ObtXmlInst *inst);
74 void obt_xml_register(ObtXmlInst *inst, const gchar *tag,
75 ObtXmlCallback func, gpointer data);
76 void obt_xml_unregister(ObtXmlInst *inst, const gchar *tag);
77 void obt_xml_tree(ObtXmlInst *i, xmlNodePtr node);
78 void obt_xml_tree_from_root(ObtXmlInst *i);
83 xmlNodePtr obt_xml_find_sibling(xmlNodePtr node, const gchar *name);
85 gboolean obt_xml_node_contains (xmlNodePtr node, const gchar *val);
86 gchar *obt_xml_node_string (xmlNodePtr node);
87 gint obt_xml_node_int (xmlNodePtr node);
88 gboolean obt_xml_node_bool (xmlNodePtr node);
90 void obt_xml_node_set_string(xmlNodePtr node, const gchar *s);
91 void obt_xml_node_set_int(xmlNodePtr node, gint i);
92 void obt_xml_node_set_bool(xmlNodePtr node, gboolean b);
94 gboolean obt_xml_attr_contains (xmlNodePtr node, const gchar *name,
96 gboolean obt_xml_attr_string (xmlNodePtr node, const gchar *name,
98 gboolean obt_xml_attr_int (xmlNodePtr node, const gchar *name,
100 gboolean obt_xml_attr_bool (xmlNodePtr node, const gchar *name,
103 /* path based operations */
105 /*! Returns the node in the given @subtree, at the given @path. If the node is
106 not found, it is created, along with any parents.
108 The path has a structure follows.
109 - <name> - specifies a child of the current position in the subtree
110 - :foo=bar - specifies an attribute and its value. this can be appended to
111 a <name> or to another attribute
112 - / - specifies to move one level deeper in the tree
115 - theme/font:place=ActiveWindow/size refers to the size node at this
117 - <theme><font place="ActiveWindow"><size /></font></theme>
119 @subtree The root of the search.
120 @path A string specifying the search path.
121 @default_value If the node is not found, it is created with this value
124 xmlNodePtr obt_xml_path_get_node(xmlNodePtr subtree, const gchar *path,
125 const gchar *default_value);
126 /*! Similar to obt_xml_path_get_node(), but returns a list of nodes that
127 match the given path.
128 Given xml as <a><b>1</b><b>2</b><b>3</b></a>, the path "a/b" would return
129 the list of all nodes named b.
131 GList* obt_xml_path_get_list(xmlNodePtr subtree, const gchar *path);
132 /*! Removes a specified node from the tree. */
133 void obt_xml_path_delete_node(xmlNodePtr subtree, const gchar *path);
135 gchar* obt_xml_path_string(xmlNodePtr subtree, const gchar *path,
136 const gchar *default_value);
137 int obt_xml_path_int(xmlNodePtr subtree, const gchar *path,
138 const gchar *default_value);
139 gboolean obt_xml_path_bool(xmlNodePtr subtree, const gchar *path,
140 const gchar *default_value);
142 void obt_xml_path_set_string(xmlNodePtr subtree, const gchar *path,
144 void obt_xml_path_set_int(xmlNodePtr subtree, const gchar *path,
146 void obt_xml_path_set_bool(xmlNodePtr subtree, const gchar *path,