Wed, 08 Dec 2004 00:20:38 +0000
[gaim-migrate @ 11534]
Doxumentation from Gary. Thanks mon ami!
committer: Mark Doliner <markdoliner@pidgin.im>
| 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.*/ | |
| 49 | struct _xmlnode *next; /**< The next node or @c NULL. */ | |
| 7131 | 50 | } xmlnode; |
| 51 | ||
| 10327 | 52 | /** |
| 53 | * Creates a new xmlnode. | |
| 54 | * | |
| 55 | * @param name The name of the node. | |
| 56 | * | |
| 57 | * @return The new node. | |
| 58 | */ | |
| 7131 | 59 | xmlnode *xmlnode_new(const char *name); |
| 10327 | 60 | |
| 61 | /** | |
| 62 | * Creates a new xmlnode child. | |
| 63 | * | |
| 64 | * @param parent The parent node. | |
| 65 | * @param name The name of the child node. | |
| 66 | * | |
| 67 | * @return The new child node. | |
| 68 | */ | |
| 7131 | 69 | xmlnode *xmlnode_new_child(xmlnode *parent, const char *name); |
| 10327 | 70 | |
| 71 | /** | |
| 72 | * Inserts a node into a node as a child. | |
| 73 | * | |
| 74 | * @param parent The parent node to insert child into. | |
| 75 | * @param child The child node to insert into parent. | |
| 76 | */ | |
| 7131 | 77 | void xmlnode_insert_child(xmlnode *parent, xmlnode *child); |
| 10327 | 78 | |
| 79 | /** | |
| 80 | * Gets a child node named name. | |
| 81 | * | |
| 82 | * @param parent The parent node. | |
| 83 | * @param name The child's name. | |
| 84 | * | |
| 85 | * @return The child or NULL. | |
| 86 | */ | |
| 7131 | 87 | xmlnode *xmlnode_get_child(xmlnode *parent, const char *name); |
| 10327 | 88 | |
| 89 | /** | |
| 90 | * Gets a child node named name in a namespace. | |
| 91 | * | |
| 92 | * @param parent The parent node. | |
| 93 | * @param name The child's name. | |
| 94 | * @param xmlns The namespace. | |
| 95 | * | |
| 96 | * @return The child or NULL. | |
| 97 | */ | |
| 8262 | 98 | xmlnode *xmlnode_get_child_with_namespace(xmlnode *parent, const char *name, const char *xmlns); |
| 10327 | 99 | |
| 100 | /** | |
| 101 | * Gets the next node with the same name as node. | |
| 102 | * | |
| 103 | * @param node The node of a twin to find. | |
| 104 | * | |
| 105 | * @return The twin of node or NULL. | |
| 106 | */ | |
| 8135 | 107 | xmlnode *xmlnode_get_next_twin(xmlnode *node); |
| 10327 | 108 | |
| 109 | /** | |
| 110 | * Inserts data into a node. | |
| 111 | * | |
| 112 | * @param parent The node to insert data into. | |
| 113 | * @param data The data to insert. | |
| 114 | * @param size The size of the data to insert. | |
| 115 | */ | |
| 7131 | 116 | void xmlnode_insert_data(xmlnode *parent, const char *data, size_t size); |
| 10327 | 117 | |
| 118 | /** | |
| 119 | * Gets data from a node. | |
| 120 | * | |
| 121 | * @param node The node to get data from. | |
| 122 | * | |
| 123 | * @return The data from the node. | |
| 124 | */ | |
| 7131 | 125 | char *xmlnode_get_data(xmlnode *node); |
| 10327 | 126 | |
| 127 | /** | |
| 128 | * Sets an attribute for a node. | |
| 129 | * | |
| 130 | * @param node The node to set an attribute for. | |
| 131 | * @param attr The name of the attribute. | |
| 132 | * @param value The value of the attribute. | |
| 133 | */ | |
| 7131 | 134 | void xmlnode_set_attrib(xmlnode *node, const char *attr, const char *value); |
| 10327 | 135 | |
| 136 | /** | |
| 137 | * Gets an attribute from a node. | |
| 138 | * | |
| 139 | * @param node The node to get an attribute from. | |
| 140 | * @param attr The attribute to get. | |
| 141 | * | |
| 142 | * @return The value of the attribute. | |
| 143 | */ | |
| 7131 | 144 | const char *xmlnode_get_attrib(xmlnode *node, const char *attr); |
| 10327 | 145 | |
| 146 | /** | |
| 147 | * Removes an attribute from a node. | |
| 148 | * | |
| 149 | * @param node The node to remove an attribute from. | |
| 150 | * @param attr The attribute to remove. | |
| 151 | */ | |
| 7131 | 152 | void xmlnode_remove_attrib(xmlnode *node, const char *attr); |
| 10327 | 153 | |
| 154 | /** | |
| 155 | * Returns the node in a string of xml. | |
| 156 | * | |
| 157 | * @param node The starting node to output. | |
| 158 | * @param len Address for the size of the string. | |
| 159 | * | |
| 160 | * @return The node repersented as a string. | |
| 161 | */ | |
| 7642 | 162 | char *xmlnode_to_str(xmlnode *node, int *len); |
| 10327 | 163 | |
| 164 | /** | |
| 165 | * Returns the node in a string of human readable xml. | |
| 166 | * | |
| 167 | * @param node The starting node to output. | |
| 168 | * @param len Address for the size of the string. | |
| 169 | * | |
| 170 | * @return The node as human readable string including | |
| 171 | * tab and new line characters. | |
| 172 | */ | |
| 9837 | 173 | char *xmlnode_to_formatted_str(xmlnode *node, int *len); |
| 10327 | 174 | |
| 175 | /** | |
| 176 | * Creates a node from a string of xml. | |
| 177 | * | |
| 178 | * @param str The string of xml. | |
| 179 | * @param size The size of the string. | |
| 180 | * | |
| 181 | * @return The new node. | |
| 182 | */ | |
| 7131 | 183 | xmlnode *xmlnode_from_str(const char *str, size_t size); |
| 10327 | 184 | |
| 185 | /** | |
| 186 | * Creates a new node from the source node. | |
| 187 | * | |
| 188 | * @param src The node to copy. | |
| 189 | * | |
| 190 | * @return A new copy of the src node. | |
| 191 | */ | |
| 8167 | 192 | xmlnode *xmlnode_copy(xmlnode *src); |
| 7131 | 193 | |
| 10327 | 194 | /** |
| 195 | * Frees a node and all of it's children. | |
| 196 | * | |
| 197 | * @param node The node to free. | |
| 198 | */ | |
| 7131 | 199 | void xmlnode_free(xmlnode *node); |
| 200 | ||
| 201 | #endif /* _GAIM_XMLNODE_H_ */ |