Mercurial > pidgin.yaz
annotate src/xmlnode.h @ 12547:a25bdcad6b21
[gaim-migrate @ 14865]
La la la la laaaaaaa, little birdies
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 18 Dec 2005 15:22:58 +0000 |
parents | 02833a0ae716 |
children | 4229503f1cd9 |
rev | line source |
---|---|
7131 | 1 /** |
2 * @file xmlnode.h XML DOM functions | |
10327 | 3 * @ingroup core |
7131 | 4 * |
5 * gaim | |
6 * | |
8046 | 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. | |
7131 | 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 | |
10327 | 28 /** |
29 * The valid types for an xmlnode | |
30 */ | |
8135 | 31 typedef enum _XMLNodeType |
7131 | 32 { |
10327 | 33 XMLNODE_TYPE_TAG, /**< Just a tag */ |
34 XMLNODE_TYPE_ATTRIB, /**< Has attributes */ | |
35 XMLNODE_TYPE_DATA /**< Has data */ | |
8135 | 36 } XMLNodeType; |
7131 | 37 |
10327 | 38 /** |
39 * An xmlnode. | |
40 */ | |
7131 | 41 typedef struct _xmlnode |
42 { | |
10327 | 43 char *name; /**< The name of the node. */ |
44 XMLNodeType type; /**< The type of the node. */ | |
45 char *data; /**< The data for the node. */ | |
46 size_t data_sz; /**< The size of the data. */ | |
47 struct _xmlnode *parent; /**< The parent node or @c NULL.*/ | |
48 struct _xmlnode *child; /**< The child node or @c NULL.*/ | |
12233
02833a0ae716
[gaim-migrate @ 14535]
Richard Laager <rlaager@wiktel.com>
parents:
11707
diff
changeset
|
49 struct _xmlnode *lastchild; /**< The last child node or @c NULL.*/ |
10327 | 50 struct _xmlnode *next; /**< The next node or @c NULL. */ |
7131 | 51 } xmlnode; |
52 | |
10327 | 53 /** |
54 * Creates a new xmlnode. | |
55 * | |
56 * @param name The name of the node. | |
57 * | |
58 * @return The new node. | |
59 */ | |
7131 | 60 xmlnode *xmlnode_new(const char *name); |
10327 | 61 |
62 /** | |
63 * Creates a new xmlnode child. | |
64 * | |
65 * @param parent The parent node. | |
66 * @param name The name of the child node. | |
67 * | |
68 * @return The new child node. | |
69 */ | |
7131 | 70 xmlnode *xmlnode_new_child(xmlnode *parent, const char *name); |
10327 | 71 |
72 /** | |
73 * Inserts a node into a node as a child. | |
74 * | |
75 * @param parent The parent node to insert child into. | |
76 * @param child The child node to insert into parent. | |
77 */ | |
7131 | 78 void xmlnode_insert_child(xmlnode *parent, xmlnode *child); |
10327 | 79 |
80 /** | |
81 * Gets a child node named name. | |
82 * | |
83 * @param parent The parent node. | |
84 * @param name The child's name. | |
85 * | |
86 * @return The child or NULL. | |
87 */ | |
10736 | 88 xmlnode *xmlnode_get_child(const xmlnode *parent, const char *name); |
10327 | 89 |
90 /** | |
91 * Gets a child node named name in a namespace. | |
92 * | |
93 * @param parent The parent node. | |
94 * @param name The child's name. | |
95 * @param xmlns The namespace. | |
96 * | |
97 * @return The child or NULL. | |
98 */ | |
10736 | 99 xmlnode *xmlnode_get_child_with_namespace(const xmlnode *parent, const char *name, const char *xmlns); |
10327 | 100 |
101 /** | |
102 * Gets the next node with the same name as node. | |
103 * | |
104 * @param node The node of a twin to find. | |
105 * | |
106 * @return The twin of node or NULL. | |
107 */ | |
8135 | 108 xmlnode *xmlnode_get_next_twin(xmlnode *node); |
10327 | 109 |
110 /** | |
111 * Inserts data into a node. | |
112 * | |
10415 | 113 * @param node The node to insert data into. |
10327 | 114 * @param data The data to insert. |
10415 | 115 * @param size The size of the data to insert. If data is |
116 * null-terminated you can pass in -1. | |
10327 | 117 */ |
10848 | 118 void xmlnode_insert_data(xmlnode *node, const char *data, gssize size); |
10327 | 119 |
120 /** | |
121 * Gets data from a node. | |
122 * | |
123 * @param node The node to get data from. | |
124 * | |
125 * @return The data from the node. | |
126 */ | |
7131 | 127 char *xmlnode_get_data(xmlnode *node); |
10327 | 128 |
129 /** | |
130 * Sets an attribute for a node. | |
131 * | |
132 * @param node The node to set an attribute for. | |
133 * @param attr The name of the attribute. | |
134 * @param value The value of the attribute. | |
135 */ | |
7131 | 136 void xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value); |
10327 | 137 |
138 /** | |
139 * Gets an attribute from a node. | |
140 * | |
141 * @param node The node to get an attribute from. | |
142 * @param attr The attribute to get. | |
143 * | |
144 * @return The value of the attribute. | |
145 */ | |
7131 | 146 const char *xmlnode_get_attrib(xmlnode *node, const char *attr); |
10327 | 147 |
148 /** | |
149 * Removes an attribute from a node. | |
150 * | |
151 * @param node The node to remove an attribute from. | |
152 * @param attr The attribute to remove. | |
153 */ | |
7131 | 154 void xmlnode_remove_attrib(xmlnode *node, const char *attr); |
10327 | 155 |
156 /** | |
157 * Returns the node in a string of xml. | |
158 * | |
159 * @param node The starting node to output. | |
160 * @param len Address for the size of the string. | |
161 * | |
10415 | 162 * @return The node repersented as a string. You must |
163 * g_free this string when finished using it. | |
10327 | 164 */ |
10425 | 165 char *xmlnode_to_str(xmlnode *node, int *len); |
10327 | 166 |
167 /** | |
168 * Returns the node in a string of human readable xml. | |
169 * | |
170 * @param node The starting node to output. | |
171 * @param len Address for the size of the string. | |
172 * | |
173 * @return The node as human readable string including | |
10415 | 174 * tab and new line characters. You must |
175 * g_free this string when finished using it. | |
10327 | 176 */ |
10425 | 177 char *xmlnode_to_formatted_str(xmlnode *node, int *len); |
10327 | 178 |
179 /** | |
10337 | 180 * Creates a node from a string of XML. Calling this on the |
181 * root node of an XML document will parse the entire document | |
182 * into a tree of nodes, and return the xmlnode of the root. | |
10327 | 183 * |
184 * @param str The string of xml. | |
11707
b7af9100af6c
[gaim-migrate @ 13998]
Richard Laager <rlaager@wiktel.com>
parents:
10848
diff
changeset
|
185 * @param size The size of the string, or -1 if @a str is |
b7af9100af6c
[gaim-migrate @ 13998]
Richard Laager <rlaager@wiktel.com>
parents:
10848
diff
changeset
|
186 * NUL-terminated. |
10327 | 187 * |
188 * @return The new node. | |
189 */ | |
10848 | 190 xmlnode *xmlnode_from_str(const char *str, gssize size); |
10327 | 191 |
192 /** | |
193 * Creates a new node from the source node. | |
194 * | |
195 * @param src The node to copy. | |
196 * | |
197 * @return A new copy of the src node. | |
198 */ | |
8167 | 199 xmlnode *xmlnode_copy(xmlnode *src); |
7131 | 200 |
10327 | 201 /** |
202 * Frees a node and all of it's children. | |
203 * | |
204 * @param node The node to free. | |
205 */ | |
7131 | 206 void xmlnode_free(xmlnode *node); |
207 | |
208 #endif /* _GAIM_XMLNODE_H_ */ |