14192
|
1 /**
|
|
2 * @file xmlnode.h XML DOM functions
|
|
3 * @ingroup core
|
|
4 *
|
|
5 * gaim
|
|
6 *
|
|
7 * Gaim is the legal property of its developers, whose names are too numerous
|
|
8 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
9 * source distribution.
|
|
10 *
|
|
11 * This program is free software; you can redistribute it and/or modify
|
|
12 * it under the terms of the GNU General Public License as published by
|
|
13 * the Free Software Foundation; either version 2 of the License, or
|
|
14 * (at your option) any later version.
|
|
15 *
|
|
16 * This program is distributed in the hope that it will be useful,
|
|
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 * GNU General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * along with this program; if not, write to the Free Software
|
|
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
24 */
|
|
25 #ifndef _GAIM_XMLNODE_H_
|
|
26 #define _GAIM_XMLNODE_H_
|
|
27
|
|
28 /**
|
|
29 * The valid types for an xmlnode
|
|
30 */
|
|
31 typedef enum _XMLNodeType
|
|
32 {
|
|
33 XMLNODE_TYPE_TAG, /**< Just a tag */
|
|
34 XMLNODE_TYPE_ATTRIB, /**< Has attributes */
|
|
35 XMLNODE_TYPE_DATA /**< Has data */
|
|
36 } XMLNodeType;
|
|
37
|
|
38 /**
|
|
39 * An xmlnode.
|
|
40 */
|
14324
|
41 typedef struct _xmlnode xmlnode;
|
|
42 struct _xmlnode
|
14192
|
43 {
|
|
44 char *name; /**< The name of the node. */
|
|
45 #ifdef HAVE_LIBXML
|
|
46 char *namespace; /**< The namespace of the node */
|
|
47 #endif
|
|
48 XMLNodeType type; /**< The type of the node. */
|
|
49 char *data; /**< The data for the node. */
|
|
50 size_t data_sz; /**< The size of the data. */
|
|
51 struct _xmlnode *parent; /**< The parent node or @c NULL.*/
|
|
52 struct _xmlnode *child; /**< The child node or @c NULL.*/
|
|
53 struct _xmlnode *lastchild; /**< The last child node or @c NULL.*/
|
|
54 struct _xmlnode *next; /**< The next node or @c NULL. */
|
14324
|
55 };
|
14192
|
56
|
|
57 /**
|
|
58 * Creates a new xmlnode.
|
|
59 *
|
|
60 * @param name The name of the node.
|
|
61 *
|
|
62 * @return The new node.
|
|
63 */
|
|
64 xmlnode *xmlnode_new(const char *name);
|
|
65
|
|
66 /**
|
|
67 * Creates a new xmlnode child.
|
|
68 *
|
|
69 * @param parent The parent node.
|
|
70 * @param name The name of the child node.
|
|
71 *
|
|
72 * @return The new child node.
|
|
73 */
|
|
74 xmlnode *xmlnode_new_child(xmlnode *parent, const char *name);
|
|
75
|
|
76 /**
|
|
77 * Inserts a node into a node as a child.
|
|
78 *
|
|
79 * @param parent The parent node to insert child into.
|
|
80 * @param child The child node to insert into parent.
|
|
81 */
|
|
82 void xmlnode_insert_child(xmlnode *parent, xmlnode *child);
|
|
83
|
|
84 /**
|
|
85 * Gets a child node named name.
|
|
86 *
|
|
87 * @param parent The parent node.
|
|
88 * @param name The child's name.
|
|
89 *
|
|
90 * @return The child or NULL.
|
|
91 */
|
|
92 xmlnode *xmlnode_get_child(const xmlnode *parent, const char *name);
|
|
93
|
|
94 /**
|
|
95 * Gets a child node named name in a namespace.
|
|
96 *
|
|
97 * @param parent The parent node.
|
|
98 * @param name The child's name.
|
|
99 * @param xmlns The namespace.
|
|
100 *
|
|
101 * @return The child or NULL.
|
|
102 */
|
|
103 xmlnode *xmlnode_get_child_with_namespace(const xmlnode *parent, const char *name, const char *xmlns);
|
|
104
|
|
105 /**
|
|
106 * Gets the next node with the same name as node.
|
|
107 *
|
|
108 * @param node The node of a twin to find.
|
|
109 *
|
|
110 * @return The twin of node or NULL.
|
|
111 */
|
|
112 xmlnode *xmlnode_get_next_twin(xmlnode *node);
|
|
113
|
|
114 /**
|
|
115 * Inserts data into a node.
|
|
116 *
|
|
117 * @param node The node to insert data into.
|
|
118 * @param data The data to insert.
|
|
119 * @param size The size of the data to insert. If data is
|
|
120 * null-terminated you can pass in -1.
|
|
121 */
|
|
122 void xmlnode_insert_data(xmlnode *node, const char *data, gssize size);
|
|
123
|
|
124 /**
|
|
125 * Gets data from a node.
|
|
126 *
|
|
127 * @param node The node to get data from.
|
|
128 *
|
|
129 * @return The data from the node. You must g_free
|
|
130 * this string when finished using it.
|
|
131 */
|
|
132 char *xmlnode_get_data(xmlnode *node);
|
|
133
|
|
134 /**
|
|
135 * Sets an attribute for a node.
|
|
136 *
|
|
137 * @param node The node to set an attribute for.
|
|
138 * @param attr The name of the attribute.
|
|
139 * @param value The value of the attribute.
|
|
140 */
|
|
141 void xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value);
|
|
142
|
|
143 /**
|
|
144 * Gets an attribute from a node.
|
|
145 *
|
|
146 * @param node The node to get an attribute from.
|
|
147 * @param attr The attribute to get.
|
|
148 *
|
|
149 * @return The value of the attribute.
|
|
150 */
|
|
151 const char *xmlnode_get_attrib(xmlnode *node, const char *attr);
|
|
152
|
|
153 /**
|
|
154 * Removes an attribute from a node.
|
|
155 *
|
|
156 * @param node The node to remove an attribute from.
|
|
157 * @param attr The attribute to remove.
|
|
158 */
|
|
159 void xmlnode_remove_attrib(xmlnode *node, const char *attr);
|
|
160
|
|
161 /**
|
|
162 * Sets the namespace of a node
|
|
163 *
|
|
164 * @param node The node to qualify
|
|
165 * @param xmlns The namespace of the node
|
|
166 */
|
|
167 void xmlnode_set_namespace(xmlnode *node, const char *xmlns);
|
|
168
|
|
169 /**
|
|
170 * Returns the namespace of a node
|
|
171 *
|
|
172 * @param node The node to get the namepsace from
|
|
173 * @return The namespace of this node
|
|
174 */
|
|
175 const char *xmlnode_get_namespace(xmlnode *node);
|
|
176
|
|
177 /**
|
|
178 * Returns the node in a string of xml.
|
|
179 *
|
|
180 * @param node The starting node to output.
|
|
181 * @param len Address for the size of the string.
|
|
182 *
|
|
183 * @return The node represented as a string. You must
|
|
184 * g_free this string when finished using it.
|
|
185 */
|
|
186 char *xmlnode_to_str(xmlnode *node, int *len);
|
|
187
|
|
188 /**
|
|
189 * Returns the node in a string of human readable xml.
|
|
190 *
|
|
191 * @param node The starting node to output.
|
|
192 * @param len Address for the size of the string.
|
|
193 *
|
|
194 * @return The node as human readable string including
|
|
195 * tab and new line characters. You must
|
|
196 * g_free this string when finished using it.
|
|
197 */
|
|
198 char *xmlnode_to_formatted_str(xmlnode *node, int *len);
|
|
199
|
|
200 /**
|
|
201 * Creates a node from a string of XML. Calling this on the
|
|
202 * root node of an XML document will parse the entire document
|
|
203 * into a tree of nodes, and return the xmlnode of the root.
|
|
204 *
|
|
205 * @param str The string of xml.
|
|
206 * @param size The size of the string, or -1 if @a str is
|
|
207 * NUL-terminated.
|
|
208 *
|
|
209 * @return The new node.
|
|
210 */
|
|
211 xmlnode *xmlnode_from_str(const char *str, gssize size);
|
|
212
|
|
213 /**
|
|
214 * Creates a new node from the source node.
|
|
215 *
|
|
216 * @param src The node to copy.
|
|
217 *
|
|
218 * @return A new copy of the src node.
|
|
219 */
|
|
220 xmlnode *xmlnode_copy(xmlnode *src);
|
|
221
|
|
222 /**
|
|
223 * Frees a node and all of it's children.
|
|
224 *
|
|
225 * @param node The node to free.
|
|
226 */
|
|
227 void xmlnode_free(xmlnode *node);
|
|
228
|
|
229 #endif /* _GAIM_XMLNODE_H_ */
|