Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * tree.c : implemetation of access function for an XML tree. |
| 3 | * |
| 4 | * See Copyright for the status of this software. |
| 5 | * |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 6 | * Daniel.Veillard@w3.org |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 9 | #ifdef WIN32 |
| 10 | #define HAVE_FCNTL_H |
| 11 | #include <io.h> |
| 12 | #else |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 13 | #include "config.h" |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 14 | #endif |
| 15 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 16 | #include <stdio.h> |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 17 | #include <string.h> /* for memset() only ! */ |
| 18 | |
Daniel Veillard | 7f7d111 | 1999-09-22 09:46:25 +0000 | [diff] [blame] | 19 | #ifdef HAVE_CTYPE_H |
| 20 | #include <ctype.h> |
| 21 | #endif |
| 22 | #ifdef HAVE_STDLIB_H |
| 23 | #include <stdlib.h> |
| 24 | #endif |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 25 | #ifdef HAVE_ZLIB_H |
| 26 | #include <zlib.h> |
| 27 | #endif |
| 28 | |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 29 | #include "xmlmemory.h" |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 30 | #include "tree.h" |
| 31 | #include "entities.h" |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 32 | #include "valid.h" |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 33 | |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 34 | static xmlChar xmlStringText[] = { 't', 'e', 'x', 't', 0 }; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 35 | int oldXMLWDcompatibility = 0; |
| 36 | int xmlIndentTreeOutput = 1; |
| 37 | |
Daniel Veillard | 15a8df4 | 1998-09-24 19:15:06 +0000 | [diff] [blame] | 38 | static int xmlCompressMode = 0; |
| 39 | |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 40 | #define UPDATE_LAST_CHILD(n) if ((n) != NULL) { \ |
| 41 | xmlNodePtr ulccur = (n)->childs; \ |
| 42 | if (ulccur == NULL) { \ |
| 43 | (n)->last = NULL; \ |
| 44 | } else { \ |
| 45 | while (ulccur->next != NULL) ulccur = ulccur->next; \ |
| 46 | (n)->last = ulccur; \ |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 47 | }} |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 48 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 49 | /************************************************************************ |
| 50 | * * |
| 51 | * Allocation and deallocation of basic structures * |
| 52 | * * |
| 53 | ************************************************************************/ |
| 54 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 55 | /** |
| 56 | * xmlUpgradeOldNs: |
| 57 | * @doc: a document pointer |
| 58 | * |
| 59 | * Upgrade old style Namespaces (PI) and move them to the root of the document. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 60 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 61 | void |
| 62 | xmlUpgradeOldNs(xmlDocPtr doc) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 63 | xmlNsPtr cur; |
| 64 | |
| 65 | if ((doc == NULL) || (doc->oldNs == NULL)) return; |
| 66 | if (doc->root == NULL) { |
| 67 | fprintf(stderr, "xmlUpgradeOldNs: failed no root !\n"); |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | cur = doc->oldNs; |
| 72 | while (cur->next != NULL) { |
| 73 | cur->type = XML_LOCAL_NAMESPACE; |
| 74 | cur = cur->next; |
| 75 | } |
| 76 | cur->type = XML_LOCAL_NAMESPACE; |
| 77 | cur->next = doc->root->nsDef; |
| 78 | doc->root->nsDef = doc->oldNs; |
| 79 | doc->oldNs = NULL; |
| 80 | } |
| 81 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 82 | /** |
| 83 | * xmlNewNs: |
| 84 | * @node: the element carrying the namespace |
| 85 | * @href: the URI associated |
| 86 | * @prefix: the prefix for the namespace |
| 87 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 88 | * Creation of a new Namespace. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 89 | * Returns returns a new namespace pointer |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 90 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 91 | xmlNsPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 92 | xmlNewNs(xmlNodePtr node, const xmlChar *href, const xmlChar *prefix) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 93 | xmlNsPtr cur; |
| 94 | |
| 95 | if (href == NULL) { |
| 96 | fprintf(stderr, "xmlNewNs: href == NULL !\n"); |
| 97 | return(NULL); |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * Allocate a new DTD and fill the fields. |
| 102 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 103 | cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 104 | if (cur == NULL) { |
| 105 | fprintf(stderr, "xmlNewNs : malloc failed\n"); |
| 106 | return(NULL); |
| 107 | } |
| 108 | |
| 109 | cur->type = XML_LOCAL_NAMESPACE; |
| 110 | if (href != NULL) |
| 111 | cur->href = xmlStrdup(href); |
| 112 | else |
| 113 | cur->href = NULL; |
| 114 | if (prefix != NULL) |
| 115 | cur->prefix = xmlStrdup(prefix); |
| 116 | else |
| 117 | cur->prefix = NULL; |
| 118 | |
| 119 | /* |
| 120 | * Add it at the end to preserve parsing order ... |
| 121 | */ |
| 122 | cur->next = NULL; |
| 123 | if (node != NULL) { |
| 124 | if (node->nsDef == NULL) { |
| 125 | node->nsDef = cur; |
| 126 | } else { |
| 127 | xmlNsPtr prev = node->nsDef; |
| 128 | |
| 129 | while (prev->next != NULL) prev = prev->next; |
| 130 | prev->next = cur; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | return(cur); |
| 135 | } |
| 136 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 137 | /** |
| 138 | * xmlNewGlobalNs: |
| 139 | * @doc: the document carrying the namespace |
| 140 | * @href: the URI associated |
| 141 | * @prefix: the prefix for the namespace |
| 142 | * |
| 143 | * Creation of a Namespace, the old way using PI and without scoping, to AVOID. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 144 | * Returns returns a new namespace pointer |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 145 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 146 | xmlNsPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 147 | xmlNewGlobalNs(xmlDocPtr doc, const xmlChar *href, const xmlChar *prefix) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 148 | xmlNsPtr cur; |
| 149 | |
| 150 | /* |
| 151 | * Allocate a new DTD and fill the fields. |
| 152 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 153 | cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 154 | if (cur == NULL) { |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 155 | fprintf(stderr, "xmlNewGlobalNs : malloc failed\n"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 156 | return(NULL); |
| 157 | } |
| 158 | |
| 159 | cur->type = XML_GLOBAL_NAMESPACE; |
| 160 | if (href != NULL) |
| 161 | cur->href = xmlStrdup(href); |
| 162 | else |
| 163 | cur->href = NULL; |
| 164 | if (prefix != NULL) |
| 165 | cur->prefix = xmlStrdup(prefix); |
| 166 | else |
| 167 | cur->prefix = NULL; |
| 168 | |
| 169 | /* |
| 170 | * Add it at the end to preserve parsing order ... |
| 171 | */ |
| 172 | cur->next = NULL; |
| 173 | if (doc != NULL) { |
| 174 | if (doc->oldNs == NULL) { |
| 175 | doc->oldNs = cur; |
| 176 | } else { |
| 177 | xmlNsPtr prev = doc->oldNs; |
| 178 | |
| 179 | while (prev->next != NULL) prev = prev->next; |
| 180 | prev->next = cur; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | return(cur); |
| 185 | } |
| 186 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 187 | /** |
| 188 | * xmlSetNs: |
| 189 | * @node: a node in the document |
| 190 | * @ns: a namespace pointer |
| 191 | * |
| 192 | * Associate a namespace to a node, a posteriori. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 193 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 194 | void |
| 195 | xmlSetNs(xmlNodePtr node, xmlNsPtr ns) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 196 | if (node == NULL) { |
| 197 | fprintf(stderr, "xmlSetNs: node == NULL\n"); |
| 198 | return; |
| 199 | } |
| 200 | node->ns = ns; |
| 201 | } |
| 202 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 203 | /** |
| 204 | * xmlFreeNs: |
| 205 | * @cur: the namespace pointer |
| 206 | * |
| 207 | * Free up the structures associated to a namespace |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 208 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 209 | void |
| 210 | xmlFreeNs(xmlNsPtr cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 211 | if (cur == NULL) { |
| 212 | fprintf(stderr, "xmlFreeNs : ns == NULL\n"); |
| 213 | return; |
| 214 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 215 | if (cur->href != NULL) xmlFree((char *) cur->href); |
| 216 | if (cur->prefix != NULL) xmlFree((char *) cur->prefix); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 217 | memset(cur, -1, sizeof(xmlNs)); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 218 | xmlFree(cur); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 221 | /** |
| 222 | * xmlFreeNsList: |
| 223 | * @cur: the first namespace pointer |
| 224 | * |
| 225 | * Free up all the structures associated to the chained namespaces. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 226 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 227 | void |
| 228 | xmlFreeNsList(xmlNsPtr cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 229 | xmlNsPtr next; |
| 230 | if (cur == NULL) { |
| 231 | fprintf(stderr, "xmlFreeNsList : ns == NULL\n"); |
| 232 | return; |
| 233 | } |
| 234 | while (cur != NULL) { |
| 235 | next = cur->next; |
| 236 | xmlFreeNs(cur); |
| 237 | cur = next; |
| 238 | } |
| 239 | } |
| 240 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 241 | /** |
| 242 | * xmlNewDtd: |
| 243 | * @doc: the document pointer |
| 244 | * @name: the DTD name |
| 245 | * @ExternalID: the external ID |
| 246 | * @SystemID: the system ID |
| 247 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 248 | * Creation of a new DTD. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 249 | * Returns a pointer to the new DTD structure |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 250 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 251 | xmlDtdPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 252 | xmlNewDtd(xmlDocPtr doc, const xmlChar *name, |
| 253 | const xmlChar *ExternalID, const xmlChar *SystemID) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 254 | xmlDtdPtr cur; |
| 255 | |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 256 | if ((doc != NULL) && (doc->extSubset != NULL)) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 257 | fprintf(stderr, "xmlNewDtd(%s): document %s already have a DTD %s\n", |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 258 | /* !!! */ (char *) name, doc->name, |
| 259 | /* !!! */ (char *)doc->extSubset->name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | /* |
| 263 | * Allocate a new DTD and fill the fields. |
| 264 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 265 | cur = (xmlDtdPtr) xmlMalloc(sizeof(xmlDtd)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 266 | if (cur == NULL) { |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 267 | fprintf(stderr, "xmlNewDtd : malloc failed\n"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 268 | return(NULL); |
| 269 | } |
| 270 | |
| 271 | if (name != NULL) |
| 272 | cur->name = xmlStrdup(name); |
| 273 | else |
| 274 | cur->name = NULL; |
| 275 | if (ExternalID != NULL) |
| 276 | cur->ExternalID = xmlStrdup(ExternalID); |
| 277 | else |
| 278 | cur->ExternalID = NULL; |
| 279 | if (SystemID != NULL) |
| 280 | cur->SystemID = xmlStrdup(SystemID); |
| 281 | else |
| 282 | cur->SystemID = NULL; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 283 | cur->notations = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 284 | cur->elements = NULL; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 285 | cur->attributes = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 286 | cur->entities = NULL; |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 287 | if (doc != NULL) |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 288 | doc->extSubset = cur; |
| 289 | |
| 290 | return(cur); |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * xmlCreateIntSubset: |
| 295 | * @doc: the document pointer |
| 296 | * @name: the DTD name |
| 297 | * @ExternalID: the external ID |
| 298 | * @SystemID: the system ID |
| 299 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 300 | * Create the internal subset of a document |
| 301 | * Returns a pointer to the new DTD structure |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 302 | */ |
| 303 | xmlDtdPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 304 | xmlCreateIntSubset(xmlDocPtr doc, const xmlChar *name, |
| 305 | const xmlChar *ExternalID, const xmlChar *SystemID) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 306 | xmlDtdPtr cur; |
| 307 | |
| 308 | if ((doc != NULL) && (doc->intSubset != NULL)) { |
| 309 | fprintf(stderr, |
| 310 | "xmlCreateIntSubset(): document %s already have an internal subset\n", |
| 311 | doc->name); |
| 312 | return(NULL); |
| 313 | } |
| 314 | |
| 315 | /* |
| 316 | * Allocate a new DTD and fill the fields. |
| 317 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 318 | cur = (xmlDtdPtr) xmlMalloc(sizeof(xmlDtd)); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 319 | if (cur == NULL) { |
| 320 | fprintf(stderr, "xmlNewDtd : malloc failed\n"); |
| 321 | return(NULL); |
| 322 | } |
| 323 | |
| 324 | if (name != NULL) |
| 325 | cur->name = xmlStrdup(name); |
| 326 | else |
| 327 | cur->name = NULL; |
| 328 | if (ExternalID != NULL) |
| 329 | cur->ExternalID = xmlStrdup(ExternalID); |
| 330 | else |
| 331 | cur->ExternalID = NULL; |
| 332 | if (SystemID != NULL) |
| 333 | cur->SystemID = xmlStrdup(SystemID); |
| 334 | else |
| 335 | cur->SystemID = NULL; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 336 | cur->notations = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 337 | cur->elements = NULL; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 338 | cur->attributes = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 339 | cur->entities = NULL; |
| 340 | if (doc != NULL) |
| 341 | doc->intSubset = cur; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 342 | |
| 343 | return(cur); |
| 344 | } |
| 345 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 346 | /** |
| 347 | * xmlFreeDtd: |
| 348 | * @cur: the DTD structure to free up |
| 349 | * |
| 350 | * Free a DTD structure. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 351 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 352 | void |
| 353 | xmlFreeDtd(xmlDtdPtr cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 354 | if (cur == NULL) { |
| 355 | fprintf(stderr, "xmlFreeDtd : DTD == NULL\n"); |
| 356 | return; |
| 357 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 358 | if (cur->name != NULL) xmlFree((char *) cur->name); |
| 359 | if (cur->SystemID != NULL) xmlFree((char *) cur->SystemID); |
| 360 | if (cur->ExternalID != NULL) xmlFree((char *) cur->ExternalID); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 361 | if (cur->notations != NULL) |
| 362 | xmlFreeNotationTable((xmlNotationTablePtr) cur->notations); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 363 | if (cur->elements != NULL) |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 364 | xmlFreeElementTable((xmlElementTablePtr) cur->elements); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 365 | if (cur->attributes != NULL) |
| 366 | xmlFreeAttributeTable((xmlAttributeTablePtr) cur->attributes); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 367 | if (cur->entities != NULL) |
| 368 | xmlFreeEntitiesTable((xmlEntitiesTablePtr) cur->entities); |
| 369 | memset(cur, -1, sizeof(xmlDtd)); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 370 | xmlFree(cur); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 373 | /** |
| 374 | * xmlNewDoc: |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 375 | * @version: xmlChar string giving the version of XML "1.0" |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 376 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 377 | * Returns a new document |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 378 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 379 | xmlDocPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 380 | xmlNewDoc(const xmlChar *version) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 381 | xmlDocPtr cur; |
| 382 | |
| 383 | if (version == NULL) { |
| 384 | fprintf(stderr, "xmlNewDoc : version == NULL\n"); |
| 385 | return(NULL); |
| 386 | } |
| 387 | |
| 388 | /* |
| 389 | * Allocate a new document and fill the fields. |
| 390 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 391 | cur = (xmlDocPtr) xmlMalloc(sizeof(xmlDoc)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 392 | if (cur == NULL) { |
| 393 | fprintf(stderr, "xmlNewDoc : malloc failed\n"); |
| 394 | return(NULL); |
| 395 | } |
| 396 | |
Daniel Veillard | 3394284 | 1998-10-18 19:12:41 +0000 | [diff] [blame] | 397 | cur->type = XML_DOCUMENT_NODE; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 398 | cur->version = xmlStrdup(version); |
| 399 | cur->name = NULL; |
| 400 | cur->root = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 401 | cur->intSubset = NULL; |
| 402 | cur->extSubset = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 403 | cur->oldNs = NULL; |
| 404 | cur->encoding = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 405 | cur->standalone = -1; |
Daniel Veillard | 11a48ec | 1999-11-23 10:40:46 +0000 | [diff] [blame] | 406 | cur->compression = -1; /* not initialized */ |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 407 | cur->ids = NULL; |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 408 | cur->refs = NULL; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 409 | #ifndef XML_WITHOUT_CORBA |
Daniel Veillard | 27fb075 | 1998-10-17 06:47:46 +0000 | [diff] [blame] | 410 | cur->_private = NULL; |
| 411 | cur->vepv = NULL; |
| 412 | #endif |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 413 | return(cur); |
| 414 | } |
| 415 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 416 | /** |
| 417 | * xmlFreeDoc: |
| 418 | * @cur: pointer to the document |
| 419 | * @: |
| 420 | * |
| 421 | * Free up all the structures used by a document, tree included. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 422 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 423 | void |
| 424 | xmlFreeDoc(xmlDocPtr cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 425 | if (cur == NULL) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 426 | #ifdef DEBUG_TREE |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 427 | fprintf(stderr, "xmlFreeDoc : document == NULL\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 428 | #endif |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 429 | return; |
| 430 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 431 | if (cur->version != NULL) xmlFree((char *) cur->version); |
| 432 | if (cur->name != NULL) xmlFree((char *) cur->name); |
| 433 | if (cur->encoding != NULL) xmlFree((char *) cur->encoding); |
| 434 | if (cur->root != NULL) xmlFreeNodeList(cur->root); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 435 | if (cur->intSubset != NULL) xmlFreeDtd(cur->intSubset); |
| 436 | if (cur->extSubset != NULL) xmlFreeDtd(cur->extSubset); |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 437 | if (cur->oldNs != NULL) xmlFreeNsList(cur->oldNs); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 438 | if (cur->ids != NULL) xmlFreeIDTable((xmlIDTablePtr) cur->ids); |
Daniel Veillard | c08a2c6 | 1999-09-08 21:35:25 +0000 | [diff] [blame] | 439 | if (cur->refs != NULL) xmlFreeRefTable((xmlRefTablePtr) cur->refs); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 440 | memset(cur, -1, sizeof(xmlDoc)); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 441 | xmlFree(cur); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 444 | /** |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 445 | * xmlStringLenGetNodeList: |
| 446 | * @doc: the document |
| 447 | * @value: the value of the text |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 448 | * @len: the length of the string value |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 449 | * |
| 450 | * Parse the value string and build the node list associated. Should |
| 451 | * produce a flat tree with only TEXTs and ENTITY_REFs. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 452 | * Returns a pointer to the first child |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 453 | */ |
| 454 | xmlNodePtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 455 | xmlStringLenGetNodeList(xmlDocPtr doc, const xmlChar *value, int len) { |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 456 | xmlNodePtr ret = NULL, last = NULL; |
| 457 | xmlNodePtr node; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 458 | xmlChar *val; |
| 459 | const xmlChar *cur = value; |
| 460 | const xmlChar *q; |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 461 | xmlEntityPtr ent; |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 462 | |
| 463 | if (value == NULL) return(NULL); |
| 464 | |
| 465 | q = cur; |
| 466 | while ((*cur != 0) && (cur - value < len)) { |
| 467 | if (*cur == '&') { |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 468 | /* |
| 469 | * Save the current text. |
| 470 | */ |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 471 | if (cur != q) { |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 472 | if ((last != NULL) && (last->type == XML_TEXT_NODE)) { |
| 473 | xmlNodeAddContentLen(last, q, cur - q); |
| 474 | } else { |
| 475 | node = xmlNewDocTextLen(doc, q, cur - q); |
| 476 | if (node == NULL) return(ret); |
| 477 | if (last == NULL) |
| 478 | last = ret = node; |
| 479 | else { |
| 480 | last->next = node; |
| 481 | node->prev = last; |
| 482 | last = node; |
| 483 | } |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 484 | } |
| 485 | } |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 486 | /* |
| 487 | * Read the entity string |
| 488 | */ |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 489 | cur++; |
| 490 | q = cur; |
| 491 | while ((*cur != 0) && (cur - value < len) && (*cur != ';')) cur++; |
| 492 | if ((*cur == 0) || (cur - value >= len)) { |
| 493 | fprintf(stderr, |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 494 | "xmlStringLenGetNodeList: unterminated entity %30s\n", q); |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 495 | return(ret); |
| 496 | } |
| 497 | if (cur != q) { |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 498 | /* |
| 499 | * Predefined entities don't generate nodes |
| 500 | */ |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 501 | val = xmlStrndup(q, cur - q); |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 502 | ent = xmlGetDocEntity(doc, val); |
| 503 | if ((ent != NULL) && |
| 504 | (ent->type == XML_INTERNAL_PREDEFINED_ENTITY)) { |
| 505 | if (last == NULL) { |
| 506 | node = xmlNewDocText(doc, ent->content); |
| 507 | last = ret = node; |
| 508 | } else |
| 509 | xmlNodeAddContent(last, ent->content); |
| 510 | |
| 511 | } else { |
| 512 | /* |
| 513 | * Create a new REFERENCE_REF node |
| 514 | */ |
| 515 | node = xmlNewReference(doc, val); |
Daniel Veillard | 242590e | 1998-11-13 18:04:35 +0000 | [diff] [blame] | 516 | if (node == NULL) { |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 517 | if (val != NULL) xmlFree(val); |
Daniel Veillard | 242590e | 1998-11-13 18:04:35 +0000 | [diff] [blame] | 518 | return(ret); |
| 519 | } |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 520 | if (last == NULL) |
| 521 | last = ret = node; |
| 522 | else { |
| 523 | last->next = node; |
| 524 | node->prev = last; |
| 525 | last = node; |
| 526 | } |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 527 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 528 | xmlFree(val); |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 529 | } |
| 530 | cur++; |
| 531 | q = cur; |
| 532 | } else |
| 533 | cur++; |
| 534 | } |
| 535 | if (cur != q) { |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 536 | /* |
| 537 | * Handle the last piece of text. |
| 538 | */ |
| 539 | if ((last != NULL) && (last->type == XML_TEXT_NODE)) { |
| 540 | xmlNodeAddContentLen(last, q, cur - q); |
| 541 | } else { |
| 542 | node = xmlNewDocTextLen(doc, q, cur - q); |
| 543 | if (node == NULL) return(ret); |
| 544 | if (last == NULL) |
| 545 | last = ret = node; |
| 546 | else { |
| 547 | last->next = node; |
| 548 | node->prev = last; |
| 549 | last = node; |
| 550 | } |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | return(ret); |
| 554 | } |
| 555 | |
| 556 | /** |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 557 | * xmlStringGetNodeList: |
| 558 | * @doc: the document |
| 559 | * @value: the value of the attribute |
| 560 | * |
| 561 | * Parse the value string and build the node list associated. Should |
| 562 | * produce a flat tree with only TEXTs and ENTITY_REFs. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 563 | * Returns a pointer to the first child |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 564 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 565 | xmlNodePtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 566 | xmlStringGetNodeList(xmlDocPtr doc, const xmlChar *value) { |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 567 | xmlNodePtr ret = NULL, last = NULL; |
| 568 | xmlNodePtr node; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 569 | xmlChar *val; |
| 570 | const xmlChar *cur = value; |
| 571 | const xmlChar *q; |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 572 | xmlEntityPtr ent; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 573 | |
| 574 | if (value == NULL) return(NULL); |
| 575 | |
| 576 | q = cur; |
| 577 | while (*cur != 0) { |
| 578 | if (*cur == '&') { |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 579 | /* |
| 580 | * Save the current text. |
| 581 | */ |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 582 | if (cur != q) { |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 583 | if ((last != NULL) && (last->type == XML_TEXT_NODE)) { |
| 584 | xmlNodeAddContentLen(last, q, cur - q); |
| 585 | } else { |
| 586 | node = xmlNewDocTextLen(doc, q, cur - q); |
| 587 | if (node == NULL) return(ret); |
| 588 | if (last == NULL) |
| 589 | last = ret = node; |
| 590 | else { |
| 591 | last->next = node; |
| 592 | node->prev = last; |
| 593 | last = node; |
| 594 | } |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 595 | } |
| 596 | } |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 597 | /* |
| 598 | * Read the entity string |
| 599 | */ |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 600 | cur++; |
| 601 | q = cur; |
| 602 | while ((*cur != 0) && (*cur != ';')) cur++; |
| 603 | if (*cur == 0) { |
| 604 | fprintf(stderr, |
| 605 | "xmlStringGetNodeList: unterminated entity %30s\n", q); |
| 606 | return(ret); |
| 607 | } |
| 608 | if (cur != q) { |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 609 | /* |
| 610 | * Predefined entities don't generate nodes |
| 611 | */ |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 612 | val = xmlStrndup(q, cur - q); |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 613 | ent = xmlGetDocEntity(doc, val); |
| 614 | if ((ent != NULL) && |
| 615 | (ent->type == XML_INTERNAL_PREDEFINED_ENTITY)) { |
| 616 | if (last == NULL) { |
| 617 | node = xmlNewDocText(doc, ent->content); |
| 618 | last = ret = node; |
| 619 | } else |
| 620 | xmlNodeAddContent(last, ent->content); |
| 621 | |
| 622 | } else { |
| 623 | /* |
| 624 | * Create a new REFERENCE_REF node |
| 625 | */ |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 626 | node = xmlNewReference(doc, val); |
Daniel Veillard | 242590e | 1998-11-13 18:04:35 +0000 | [diff] [blame] | 627 | if (node == NULL) { |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 628 | if (val != NULL) xmlFree(val); |
Daniel Veillard | 242590e | 1998-11-13 18:04:35 +0000 | [diff] [blame] | 629 | return(ret); |
| 630 | } |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 631 | if (last == NULL) |
| 632 | last = ret = node; |
| 633 | else { |
| 634 | last->next = node; |
| 635 | node->prev = last; |
| 636 | last = node; |
| 637 | } |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 638 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 639 | xmlFree(val); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 640 | } |
| 641 | cur++; |
| 642 | q = cur; |
| 643 | } else |
| 644 | cur++; |
| 645 | } |
| 646 | if (cur != q) { |
Daniel Veillard | 25940b7 | 1998-10-29 05:51:30 +0000 | [diff] [blame] | 647 | /* |
| 648 | * Handle the last piece of text. |
| 649 | */ |
| 650 | if ((last != NULL) && (last->type == XML_TEXT_NODE)) { |
| 651 | xmlNodeAddContentLen(last, q, cur - q); |
| 652 | } else { |
| 653 | node = xmlNewDocTextLen(doc, q, cur - q); |
| 654 | if (node == NULL) return(ret); |
| 655 | if (last == NULL) |
| 656 | last = ret = node; |
| 657 | else { |
| 658 | last->next = node; |
| 659 | node->prev = last; |
| 660 | last = node; |
| 661 | } |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | return(ret); |
| 665 | } |
| 666 | |
| 667 | /** |
| 668 | * xmlNodeListGetString: |
| 669 | * @doc: the document |
| 670 | * @list: a Node list |
| 671 | * @inLine: should we replace entity contents or show their external form |
| 672 | * |
| 673 | * Returns the string equivalent to the text contained in the Node list |
| 674 | * made of TEXTs and ENTITY_REFs |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 675 | * Returns a pointer to the string copy, the calller must free it. |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 676 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 677 | xmlChar * |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 678 | xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine) { |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 679 | xmlNodePtr node = list; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 680 | xmlChar *ret = NULL; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 681 | xmlEntityPtr ent; |
| 682 | |
| 683 | if (list == NULL) return(NULL); |
| 684 | |
| 685 | while (node != NULL) { |
| 686 | if (node->type == XML_TEXT_NODE) { |
Daniel Veillard | 3500838 | 1999-10-25 13:15:52 +0000 | [diff] [blame] | 687 | if ((inLine) || (doc->type == XML_HTML_DOCUMENT_NODE)) |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 688 | ret = xmlStrcat(ret, node->content); |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 689 | else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 690 | xmlChar *buffer; |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 691 | |
| 692 | buffer = xmlEncodeEntitiesReentrant(doc, node->content); |
| 693 | if (buffer != NULL) { |
| 694 | ret = xmlStrcat(ret, buffer); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 695 | xmlFree(buffer); |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 696 | } |
| 697 | } |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 698 | } else if (node->type == XML_ENTITY_REF_NODE) { |
| 699 | if (inLine) { |
| 700 | ent = xmlGetDocEntity(doc, node->name); |
| 701 | if (ent != NULL) |
| 702 | ret = xmlStrcat(ret, ent->content); |
| 703 | else |
| 704 | ret = xmlStrcat(ret, node->content); |
| 705 | } else { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 706 | xmlChar buf[2]; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 707 | buf[0] = '&'; buf[1] = 0; |
| 708 | ret = xmlStrncat(ret, buf, 1); |
| 709 | ret = xmlStrcat(ret, node->name); |
| 710 | buf[0] = ';'; buf[1] = 0; |
| 711 | ret = xmlStrncat(ret, buf, 1); |
| 712 | } |
| 713 | } |
| 714 | #if 0 |
| 715 | else { |
| 716 | fprintf(stderr, "xmlGetNodeListString : invalide node type %d\n", |
| 717 | node->type); |
| 718 | } |
| 719 | #endif |
| 720 | node = node->next; |
| 721 | } |
| 722 | return(ret); |
| 723 | } |
| 724 | |
| 725 | /** |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 726 | * xmlNewProp: |
| 727 | * @node: the holding node |
| 728 | * @name: the name of the attribute |
| 729 | * @value: the value of the attribute |
| 730 | * |
| 731 | * Create a new property carried by a node. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 732 | * Returns a pointer to the attribute |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 733 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 734 | xmlAttrPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 735 | xmlNewProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 736 | xmlAttrPtr cur; |
| 737 | |
| 738 | if (name == NULL) { |
| 739 | fprintf(stderr, "xmlNewProp : name == NULL\n"); |
| 740 | return(NULL); |
| 741 | } |
| 742 | |
| 743 | /* |
| 744 | * Allocate a new property and fill the fields. |
| 745 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 746 | cur = (xmlAttrPtr) xmlMalloc(sizeof(xmlAttr)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 747 | if (cur == NULL) { |
| 748 | fprintf(stderr, "xmlNewProp : malloc failed\n"); |
| 749 | return(NULL); |
| 750 | } |
| 751 | |
Daniel Veillard | 3394284 | 1998-10-18 19:12:41 +0000 | [diff] [blame] | 752 | cur->type = XML_ATTRIBUTE_NODE; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 753 | cur->node = node; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 754 | cur->ns = NULL; |
| 755 | cur->name = xmlStrdup(name); |
Daniel Veillard | 51e3b15 | 1999-11-12 17:02:31 +0000 | [diff] [blame] | 756 | if (value != NULL) { |
| 757 | xmlChar *buffer; |
| 758 | buffer = xmlEncodeEntitiesReentrant(node->doc, value); |
| 759 | cur->val = xmlStringGetNodeList(node->doc, buffer); |
| 760 | xmlFree(buffer); |
| 761 | } |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 762 | else |
| 763 | cur->val = NULL; |
| 764 | #ifndef XML_WITHOUT_CORBA |
| 765 | cur->_private = NULL; |
| 766 | cur->vepv = NULL; |
| 767 | #endif |
| 768 | |
| 769 | /* |
| 770 | * Add it at the end to preserve parsing order ... |
| 771 | */ |
| 772 | cur->next = NULL; |
| 773 | if (node != NULL) { |
| 774 | if (node->properties == NULL) { |
| 775 | node->properties = cur; |
| 776 | } else { |
| 777 | xmlAttrPtr prev = node->properties; |
| 778 | |
| 779 | while (prev->next != NULL) prev = prev->next; |
| 780 | prev->next = cur; |
| 781 | } |
| 782 | } |
Daniel Veillard | 00fdf37 | 1999-10-08 09:40:39 +0000 | [diff] [blame] | 783 | #ifndef XML_WITHOUT_CORBA |
| 784 | cur->_private = NULL; |
| 785 | cur->vepv = NULL; |
| 786 | #endif |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 787 | return(cur); |
| 788 | } |
| 789 | |
| 790 | /** |
| 791 | * xmlNewNsProp: |
| 792 | * @node: the holding node |
| 793 | * @ns: the namespace |
| 794 | * @name: the name of the attribute |
| 795 | * @value: the value of the attribute |
| 796 | * |
| 797 | * Create a new property tagged with a namespace and carried by a node. |
| 798 | * Returns a pointer to the attribute |
| 799 | */ |
| 800 | xmlAttrPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 801 | xmlNewNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name, |
| 802 | const xmlChar *value) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 803 | xmlAttrPtr cur; |
| 804 | |
| 805 | if (name == NULL) { |
| 806 | fprintf(stderr, "xmlNewProp : name == NULL\n"); |
| 807 | return(NULL); |
| 808 | } |
| 809 | |
| 810 | /* |
| 811 | * Allocate a new property and fill the fields. |
| 812 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 813 | cur = (xmlAttrPtr) xmlMalloc(sizeof(xmlAttr)); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 814 | if (cur == NULL) { |
| 815 | fprintf(stderr, "xmlNewProp : malloc failed\n"); |
| 816 | return(NULL); |
| 817 | } |
| 818 | |
| 819 | cur->type = XML_ATTRIBUTE_NODE; |
| 820 | cur->node = node; |
| 821 | cur->ns = ns; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 822 | cur->name = xmlStrdup(name); |
| 823 | if (value != NULL) |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 824 | cur->val = xmlStringGetNodeList(node->doc, value); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 825 | else |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 826 | cur->val = NULL; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 827 | #ifndef XML_WITHOUT_CORBA |
Daniel Veillard | 27fb075 | 1998-10-17 06:47:46 +0000 | [diff] [blame] | 828 | cur->_private = NULL; |
| 829 | cur->vepv = NULL; |
| 830 | #endif |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 831 | |
| 832 | /* |
| 833 | * Add it at the end to preserve parsing order ... |
| 834 | */ |
| 835 | cur->next = NULL; |
| 836 | if (node != NULL) { |
| 837 | if (node->properties == NULL) { |
| 838 | node->properties = cur; |
| 839 | } else { |
| 840 | xmlAttrPtr prev = node->properties; |
| 841 | |
| 842 | while (prev->next != NULL) prev = prev->next; |
| 843 | prev->next = cur; |
| 844 | } |
| 845 | } |
| 846 | return(cur); |
| 847 | } |
| 848 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 849 | /** |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 850 | * xmlNewDocProp: |
| 851 | * @doc: the document |
| 852 | * @name: the name of the attribute |
| 853 | * @value: the value of the attribute |
| 854 | * |
| 855 | * Create a new property carried by a document. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 856 | * Returns a pointer to the attribute |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 857 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 858 | xmlAttrPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 859 | xmlNewDocProp(xmlDocPtr doc, const xmlChar *name, const xmlChar *value) { |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 860 | xmlAttrPtr cur; |
| 861 | |
| 862 | if (name == NULL) { |
| 863 | fprintf(stderr, "xmlNewProp : name == NULL\n"); |
| 864 | return(NULL); |
| 865 | } |
| 866 | |
| 867 | /* |
| 868 | * Allocate a new property and fill the fields. |
| 869 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 870 | cur = (xmlAttrPtr) xmlMalloc(sizeof(xmlAttr)); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 871 | if (cur == NULL) { |
| 872 | fprintf(stderr, "xmlNewProp : malloc failed\n"); |
| 873 | return(NULL); |
| 874 | } |
| 875 | |
| 876 | cur->type = XML_ATTRIBUTE_NODE; |
| 877 | cur->node = NULL; |
| 878 | cur->name = xmlStrdup(name); |
| 879 | if (value != NULL) |
| 880 | cur->val = xmlStringGetNodeList(doc, value); |
| 881 | else |
| 882 | cur->val = NULL; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 883 | #ifndef XML_WITHOUT_CORBA |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 884 | cur->_private = NULL; |
| 885 | cur->vepv = NULL; |
| 886 | #endif |
| 887 | |
| 888 | cur->next = NULL; |
| 889 | return(cur); |
| 890 | } |
| 891 | |
| 892 | /** |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 893 | * xmlFreePropList: |
| 894 | * @cur: the first property in the list |
| 895 | * |
| 896 | * Free a property and all its siblings, all the childs are freed too. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 897 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 898 | void |
| 899 | xmlFreePropList(xmlAttrPtr cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 900 | xmlAttrPtr next; |
| 901 | if (cur == NULL) { |
| 902 | fprintf(stderr, "xmlFreePropList : property == NULL\n"); |
| 903 | return; |
| 904 | } |
| 905 | while (cur != NULL) { |
| 906 | next = cur->next; |
| 907 | xmlFreeProp(cur); |
| 908 | cur = next; |
| 909 | } |
| 910 | } |
| 911 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 912 | /** |
| 913 | * xmlFreeProp: |
| 914 | * @cur: the first property in the list |
| 915 | * |
| 916 | * Free one property, all the childs are freed too. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 917 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 918 | void |
| 919 | xmlFreeProp(xmlAttrPtr cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 920 | if (cur == NULL) { |
| 921 | fprintf(stderr, "xmlFreeProp : property == NULL\n"); |
| 922 | return; |
| 923 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 924 | if (cur->name != NULL) xmlFree((char *) cur->name); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 925 | if (cur->val != NULL) xmlFreeNodeList(cur->val); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 926 | memset(cur, -1, sizeof(xmlAttr)); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 927 | xmlFree(cur); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 928 | } |
| 929 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 930 | /** |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 931 | * xmlNewPI: |
| 932 | * @name: the processing instruction name |
| 933 | * @content: the PI content |
| 934 | * |
| 935 | * Creation of a processing instruction element. |
| 936 | * Returns a pointer to the new node object. |
| 937 | */ |
| 938 | xmlNodePtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 939 | xmlNewPI(const xmlChar *name, const xmlChar *content) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 940 | xmlNodePtr cur; |
| 941 | |
| 942 | if (name == NULL) { |
| 943 | fprintf(stderr, "xmlNewPI : name == NULL\n"); |
| 944 | return(NULL); |
| 945 | } |
| 946 | |
| 947 | /* |
| 948 | * Allocate a new node and fill the fields. |
| 949 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 950 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 951 | if (cur == NULL) { |
| 952 | fprintf(stderr, "xmlNewPI : malloc failed\n"); |
| 953 | return(NULL); |
| 954 | } |
| 955 | |
| 956 | cur->type = XML_PI_NODE; |
| 957 | cur->doc = NULL; |
| 958 | cur->parent = NULL; |
| 959 | cur->next = NULL; |
| 960 | cur->prev = NULL; |
| 961 | cur->childs = NULL; |
| 962 | cur->last = NULL; |
| 963 | cur->properties = NULL; |
| 964 | cur->name = xmlStrdup(name); |
| 965 | cur->ns = NULL; |
| 966 | cur->nsDef = NULL; |
| 967 | if (content != NULL) |
| 968 | cur->content = xmlStrdup(content); |
| 969 | else |
| 970 | cur->content = NULL; |
| 971 | #ifndef XML_WITHOUT_CORBA |
| 972 | cur->_private = NULL; |
| 973 | cur->vepv = NULL; |
| 974 | #endif |
| 975 | return(cur); |
| 976 | } |
| 977 | |
| 978 | /** |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 979 | * xmlNewNode: |
| 980 | * @ns: namespace if any |
| 981 | * @name: the node name |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 982 | * |
| 983 | * Creation of a new node element. @ns and @content are optionnal (NULL). |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 984 | * If content is non NULL, a child list containing the TEXTs and |
| 985 | * ENTITY_REFs node will be created. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 986 | * Returns a pointer to the new node object. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 987 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 988 | xmlNodePtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 989 | xmlNewNode(xmlNsPtr ns, const xmlChar *name) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 990 | xmlNodePtr cur; |
| 991 | |
| 992 | if (name == NULL) { |
| 993 | fprintf(stderr, "xmlNewNode : name == NULL\n"); |
| 994 | return(NULL); |
| 995 | } |
| 996 | |
| 997 | /* |
| 998 | * Allocate a new node and fill the fields. |
| 999 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 1000 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1001 | if (cur == NULL) { |
| 1002 | fprintf(stderr, "xmlNewNode : malloc failed\n"); |
| 1003 | return(NULL); |
| 1004 | } |
| 1005 | |
Daniel Veillard | 3394284 | 1998-10-18 19:12:41 +0000 | [diff] [blame] | 1006 | cur->type = XML_ELEMENT_NODE; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1007 | cur->doc = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1008 | cur->parent = NULL; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1009 | cur->next = NULL; |
| 1010 | cur->prev = NULL; |
| 1011 | cur->childs = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1012 | cur->last = NULL; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1013 | cur->properties = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1014 | cur->name = xmlStrdup(name); |
| 1015 | cur->ns = ns; |
| 1016 | cur->nsDef = NULL; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1017 | cur->content = NULL; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1018 | #ifndef XML_WITHOUT_CORBA |
Daniel Veillard | 27fb075 | 1998-10-17 06:47:46 +0000 | [diff] [blame] | 1019 | cur->_private = NULL; |
| 1020 | cur->vepv = NULL; |
| 1021 | #endif |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1022 | return(cur); |
| 1023 | } |
| 1024 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1025 | /** |
| 1026 | * xmlNewDocNode: |
| 1027 | * @doc: the document |
| 1028 | * @ns: namespace if any |
| 1029 | * @name: the node name |
Daniel Veillard | 11a48ec | 1999-11-23 10:40:46 +0000 | [diff] [blame] | 1030 | * @content: the XML text content if any |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1031 | * |
| 1032 | * Creation of a new node element within a document. @ns and @content |
| 1033 | * are optionnal (NULL). |
Daniel Veillard | 11a48ec | 1999-11-23 10:40:46 +0000 | [diff] [blame] | 1034 | * NOTE: @content is supposed to be a piece of XML CDATA, so it allow entities |
| 1035 | * references, but XML special chars need to be escaped first by using |
| 1036 | * xmlEncodeEntitiesReentrant(). Use xmlNewDocRawNode() if you don't |
| 1037 | * need entities support. |
| 1038 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1039 | * Returns a pointer to the new node object. |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1040 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 1041 | xmlNodePtr |
| 1042 | xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns, |
Daniel Veillard | 11a48ec | 1999-11-23 10:40:46 +0000 | [diff] [blame] | 1043 | const xmlChar *name, const xmlChar *content) { |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1044 | xmlNodePtr cur; |
| 1045 | |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1046 | cur = xmlNewNode(ns, name); |
| 1047 | if (cur != NULL) { |
| 1048 | cur->doc = doc; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1049 | if (content != NULL) { |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1050 | cur->childs = xmlStringGetNodeList(doc, content); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1051 | UPDATE_LAST_CHILD(cur) |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1052 | } |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1053 | } |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1054 | return(cur); |
| 1055 | } |
| 1056 | |
| 1057 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1058 | /** |
Daniel Veillard | 11a48ec | 1999-11-23 10:40:46 +0000 | [diff] [blame] | 1059 | * xmlNewDocRawNode: |
| 1060 | * @doc: the document |
| 1061 | * @ns: namespace if any |
| 1062 | * @name: the node name |
| 1063 | * @content: the text content if any |
| 1064 | * |
| 1065 | * Creation of a new node element within a document. @ns and @content |
| 1066 | * are optionnal (NULL). |
| 1067 | * |
| 1068 | * Returns a pointer to the new node object. |
| 1069 | */ |
| 1070 | xmlNodePtr |
| 1071 | xmlNewDocRawNode(xmlDocPtr doc, xmlNsPtr ns, |
| 1072 | const xmlChar *name, const xmlChar *content) { |
| 1073 | xmlNodePtr cur; |
| 1074 | |
| 1075 | cur = xmlNewNode(ns, name); |
| 1076 | if (cur != NULL) { |
| 1077 | cur->doc = doc; |
| 1078 | if (content != NULL) { |
| 1079 | cur->childs = xmlNewDocText(doc, content); |
| 1080 | UPDATE_LAST_CHILD(cur) |
| 1081 | } |
| 1082 | } |
| 1083 | return(cur); |
| 1084 | } |
| 1085 | |
| 1086 | |
| 1087 | /** |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1088 | * xmlNewText: |
| 1089 | * @content: the text content |
| 1090 | * |
| 1091 | * Creation of a new text node. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1092 | * Returns a pointer to the new node object. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1093 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 1094 | xmlNodePtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1095 | xmlNewText(const xmlChar *content) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1096 | xmlNodePtr cur; |
| 1097 | |
| 1098 | /* |
| 1099 | * Allocate a new node and fill the fields. |
| 1100 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 1101 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1102 | if (cur == NULL) { |
| 1103 | fprintf(stderr, "xmlNewText : malloc failed\n"); |
| 1104 | return(NULL); |
| 1105 | } |
| 1106 | |
Daniel Veillard | 3394284 | 1998-10-18 19:12:41 +0000 | [diff] [blame] | 1107 | cur->type = XML_TEXT_NODE; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1108 | cur->doc = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1109 | cur->parent = NULL; |
| 1110 | cur->next = NULL; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1111 | cur->prev = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1112 | cur->childs = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1113 | cur->last = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1114 | cur->properties = NULL; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1115 | cur->type = XML_TEXT_NODE; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1116 | cur->name = xmlStrdup(xmlStringText); |
| 1117 | cur->ns = NULL; |
| 1118 | cur->nsDef = NULL; |
| 1119 | if (content != NULL) |
| 1120 | cur->content = xmlStrdup(content); |
| 1121 | else |
| 1122 | cur->content = NULL; |
Daniel Veillard | 00fdf37 | 1999-10-08 09:40:39 +0000 | [diff] [blame] | 1123 | #ifndef XML_WITHOUT_CORBA |
| 1124 | cur->_private = NULL; |
| 1125 | cur->vepv = NULL; |
| 1126 | #endif |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1127 | return(cur); |
| 1128 | } |
| 1129 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1130 | /** |
Daniel Veillard | 11a48ec | 1999-11-23 10:40:46 +0000 | [diff] [blame] | 1131 | * xmlNewTextChild: |
| 1132 | * @parent: the parent node |
| 1133 | * @ns: a namespace if any |
| 1134 | * @name: the name of the child |
| 1135 | * @content: the text content of the child if any. |
| 1136 | * |
| 1137 | * Creation of a new child element, added at the end of @parent childs list. |
| 1138 | * @ns and @content parameters are optionnal (NULL). If content is non NULL, |
| 1139 | * a child TEXT node will be created containing the string content. |
| 1140 | * |
| 1141 | * Returns a pointer to the new node object. |
| 1142 | */ |
| 1143 | xmlNodePtr |
| 1144 | xmlNewTextChild(xmlNodePtr parent, xmlNsPtr ns, |
| 1145 | const xmlChar *name, const xmlChar *content) { |
| 1146 | xmlNodePtr cur, prev; |
| 1147 | |
| 1148 | if (parent == NULL) { |
| 1149 | fprintf(stderr, "xmlNewTextChild : parent == NULL\n"); |
| 1150 | return(NULL); |
| 1151 | } |
| 1152 | |
| 1153 | if (name == NULL) { |
| 1154 | fprintf(stderr, "xmlNewTextChild : name == NULL\n"); |
| 1155 | return(NULL); |
| 1156 | } |
| 1157 | |
| 1158 | /* |
| 1159 | * Allocate a new node |
| 1160 | */ |
| 1161 | if (ns == NULL) |
| 1162 | cur = xmlNewDocRawNode(parent->doc, parent->ns, name, content); |
| 1163 | else |
| 1164 | cur = xmlNewDocRawNode(parent->doc, ns, name, content); |
| 1165 | if (cur == NULL) return(NULL); |
| 1166 | |
| 1167 | /* |
| 1168 | * add the new element at the end of the childs list. |
| 1169 | */ |
| 1170 | cur->type = XML_ELEMENT_NODE; |
| 1171 | cur->parent = parent; |
| 1172 | cur->doc = parent->doc; |
| 1173 | if (parent->childs == NULL) { |
| 1174 | parent->childs = cur; |
| 1175 | parent->last = cur; |
| 1176 | } else { |
| 1177 | prev = parent->last; |
| 1178 | prev->next = cur; |
| 1179 | cur->prev = prev; |
| 1180 | parent->last = cur; |
| 1181 | } |
| 1182 | |
| 1183 | return(cur); |
| 1184 | } |
| 1185 | |
| 1186 | /** |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1187 | * xmlNewReference: |
| 1188 | * @doc: the document |
| 1189 | * @name: the reference name, or the reference string with & and ; |
| 1190 | * |
| 1191 | * Creation of a new reference node. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1192 | * Returns a pointer to the new node object. |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1193 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 1194 | xmlNodePtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1195 | xmlNewReference(xmlDocPtr doc, const xmlChar *name) { |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1196 | xmlNodePtr cur; |
| 1197 | xmlEntityPtr ent; |
| 1198 | |
| 1199 | /* |
| 1200 | * Allocate a new node and fill the fields. |
| 1201 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 1202 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1203 | if (cur == NULL) { |
| 1204 | fprintf(stderr, "xmlNewText : malloc failed\n"); |
| 1205 | return(NULL); |
| 1206 | } |
| 1207 | |
| 1208 | cur->type = XML_ENTITY_REF_NODE; |
Daniel Veillard | 10c6a8f | 1998-10-28 01:00:12 +0000 | [diff] [blame] | 1209 | cur->doc = doc; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1210 | cur->parent = NULL; |
| 1211 | cur->next = NULL; |
| 1212 | cur->prev = NULL; |
| 1213 | cur->childs = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1214 | cur->last = NULL; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1215 | cur->properties = NULL; |
| 1216 | if (name[0] == '&') { |
| 1217 | int len; |
| 1218 | name++; |
| 1219 | len = xmlStrlen(name); |
| 1220 | if (name[len - 1] == ';') |
| 1221 | cur->name = xmlStrndup(name, len - 1); |
| 1222 | else |
| 1223 | cur->name = xmlStrndup(name, len); |
| 1224 | } else |
| 1225 | cur->name = xmlStrdup(name); |
| 1226 | cur->ns = NULL; |
| 1227 | cur->nsDef = NULL; |
| 1228 | |
| 1229 | ent = xmlGetDocEntity(doc, cur->name); |
| 1230 | if (ent != NULL) |
| 1231 | cur->content = ent->content; |
| 1232 | else |
| 1233 | cur->content = NULL; |
Daniel Veillard | 00fdf37 | 1999-10-08 09:40:39 +0000 | [diff] [blame] | 1234 | #ifndef XML_WITHOUT_CORBA |
| 1235 | cur->_private = NULL; |
| 1236 | cur->vepv = NULL; |
| 1237 | #endif |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1238 | return(cur); |
| 1239 | } |
| 1240 | |
| 1241 | /** |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1242 | * xmlNewDocText: |
| 1243 | * @doc: the document |
| 1244 | * @content: the text content |
| 1245 | * |
| 1246 | * Creation of a new text node within a document. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1247 | * Returns a pointer to the new node object. |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1248 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 1249 | xmlNodePtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1250 | xmlNewDocText(xmlDocPtr doc, const xmlChar *content) { |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1251 | xmlNodePtr cur; |
| 1252 | |
| 1253 | cur = xmlNewText(content); |
| 1254 | if (cur != NULL) cur->doc = doc; |
| 1255 | return(cur); |
| 1256 | } |
| 1257 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1258 | /** |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1259 | * xmlNewTextLen: |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1260 | * @content: the text content |
| 1261 | * @len: the text len. |
| 1262 | * |
| 1263 | * Creation of a new text node with an extra parameter for the content's lenght |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1264 | * Returns a pointer to the new node object. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1265 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 1266 | xmlNodePtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1267 | xmlNewTextLen(const xmlChar *content, int len) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1268 | xmlNodePtr cur; |
| 1269 | |
| 1270 | /* |
| 1271 | * Allocate a new node and fill the fields. |
| 1272 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 1273 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1274 | if (cur == NULL) { |
| 1275 | fprintf(stderr, "xmlNewText : malloc failed\n"); |
| 1276 | return(NULL); |
| 1277 | } |
| 1278 | |
Daniel Veillard | 3394284 | 1998-10-18 19:12:41 +0000 | [diff] [blame] | 1279 | cur->type = XML_TEXT_NODE; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1280 | cur->doc = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1281 | cur->parent = NULL; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1282 | cur->prev = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1283 | cur->next = NULL; |
| 1284 | cur->childs = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1285 | cur->last = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1286 | cur->properties = NULL; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1287 | cur->type = XML_TEXT_NODE; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1288 | cur->name = xmlStrdup(xmlStringText); |
| 1289 | cur->ns = NULL; |
| 1290 | cur->nsDef = NULL; |
| 1291 | if (content != NULL) |
| 1292 | cur->content = xmlStrndup(content, len); |
| 1293 | else |
| 1294 | cur->content = NULL; |
Daniel Veillard | 00fdf37 | 1999-10-08 09:40:39 +0000 | [diff] [blame] | 1295 | #ifndef XML_WITHOUT_CORBA |
| 1296 | cur->_private = NULL; |
| 1297 | cur->vepv = NULL; |
| 1298 | #endif |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1299 | return(cur); |
| 1300 | } |
| 1301 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1302 | /** |
| 1303 | * xmlNewDocTextLen: |
| 1304 | * @doc: the document |
| 1305 | * @content: the text content |
| 1306 | * @len: the text len. |
| 1307 | * |
| 1308 | * Creation of a new text node with an extra content lenght parameter. The |
| 1309 | * text node pertain to a given document. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1310 | * Returns a pointer to the new node object. |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1311 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 1312 | xmlNodePtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1313 | xmlNewDocTextLen(xmlDocPtr doc, const xmlChar *content, int len) { |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1314 | xmlNodePtr cur; |
| 1315 | |
| 1316 | cur = xmlNewTextLen(content, len); |
| 1317 | if (cur != NULL) cur->doc = doc; |
| 1318 | return(cur); |
| 1319 | } |
| 1320 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1321 | /** |
| 1322 | * xmlNewComment: |
| 1323 | * @content: the comment content |
| 1324 | * |
| 1325 | * Creation of a new node containing a comment. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1326 | * Returns a pointer to the new node object. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1327 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 1328 | xmlNodePtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1329 | xmlNewComment(const xmlChar *content) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1330 | xmlNodePtr cur; |
| 1331 | |
| 1332 | /* |
| 1333 | * Allocate a new node and fill the fields. |
| 1334 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 1335 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1336 | if (cur == NULL) { |
| 1337 | fprintf(stderr, "xmlNewComment : malloc failed\n"); |
| 1338 | return(NULL); |
| 1339 | } |
| 1340 | |
Daniel Veillard | 3394284 | 1998-10-18 19:12:41 +0000 | [diff] [blame] | 1341 | cur->type = XML_COMMENT_NODE; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1342 | cur->doc = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1343 | cur->parent = NULL; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1344 | cur->prev = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1345 | cur->next = NULL; |
| 1346 | cur->childs = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1347 | cur->last = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1348 | cur->properties = NULL; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1349 | cur->type = XML_COMMENT_NODE; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1350 | cur->name = xmlStrdup(xmlStringText); |
| 1351 | cur->ns = NULL; |
| 1352 | cur->nsDef = NULL; |
| 1353 | if (content != NULL) |
| 1354 | cur->content = xmlStrdup(content); |
| 1355 | else |
| 1356 | cur->content = NULL; |
Daniel Veillard | 00fdf37 | 1999-10-08 09:40:39 +0000 | [diff] [blame] | 1357 | #ifndef XML_WITHOUT_CORBA |
| 1358 | cur->_private = NULL; |
| 1359 | cur->vepv = NULL; |
| 1360 | #endif |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1361 | return(cur); |
| 1362 | } |
| 1363 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1364 | /** |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1365 | * xmlNewCDataBlock: |
| 1366 | * @doc: the document |
| 1367 | * @content: the CData block content content |
| 1368 | * @len: the length of the block |
| 1369 | * |
| 1370 | * Creation of a new node containing a CData block. |
| 1371 | * Returns a pointer to the new node object. |
| 1372 | */ |
| 1373 | xmlNodePtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1374 | xmlNewCDataBlock(xmlDocPtr doc, const xmlChar *content, int len) { |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1375 | xmlNodePtr cur; |
| 1376 | |
| 1377 | /* |
| 1378 | * Allocate a new node and fill the fields. |
| 1379 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 1380 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1381 | if (cur == NULL) { |
| 1382 | fprintf(stderr, "xmlNewCDataBlock : malloc failed\n"); |
| 1383 | return(NULL); |
| 1384 | } |
| 1385 | |
| 1386 | cur->type = XML_CDATA_SECTION_NODE; |
| 1387 | cur->doc = NULL; |
| 1388 | cur->parent = NULL; |
| 1389 | cur->prev = NULL; |
| 1390 | cur->next = NULL; |
| 1391 | cur->childs = NULL; |
| 1392 | cur->last = NULL; |
| 1393 | cur->properties = NULL; |
| 1394 | cur->name = xmlStrdup(xmlStringText); |
| 1395 | cur->ns = NULL; |
| 1396 | cur->nsDef = NULL; |
| 1397 | if ((content != NULL) && (len > 0)) { |
| 1398 | cur->content = xmlStrndup(content, len); |
| 1399 | } else |
| 1400 | cur->content = NULL; |
Daniel Veillard | 00fdf37 | 1999-10-08 09:40:39 +0000 | [diff] [blame] | 1401 | #ifndef XML_WITHOUT_CORBA |
| 1402 | cur->_private = NULL; |
| 1403 | cur->vepv = NULL; |
| 1404 | #endif |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 1405 | return(cur); |
| 1406 | } |
| 1407 | |
| 1408 | /** |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1409 | * xmlNewDocComment: |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1410 | * @doc: the document |
| 1411 | * @content: the comment content |
| 1412 | * |
| 1413 | * Creation of a new node containing a commentwithin a document. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1414 | * Returns a pointer to the new node object. |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1415 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 1416 | xmlNodePtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 1417 | xmlNewDocComment(xmlDocPtr doc, const xmlChar *content) { |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1418 | xmlNodePtr cur; |
| 1419 | |
| 1420 | cur = xmlNewComment(content); |
| 1421 | if (cur != NULL) cur->doc = doc; |
| 1422 | return(cur); |
| 1423 | } |
| 1424 | |
Daniel Veillard | 11a48ec | 1999-11-23 10:40:46 +0000 | [diff] [blame] | 1425 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1426 | /** |
| 1427 | * xmlNewChild: |
| 1428 | * @parent: the parent node |
| 1429 | * @ns: a namespace if any |
| 1430 | * @name: the name of the child |
Daniel Veillard | 11a48ec | 1999-11-23 10:40:46 +0000 | [diff] [blame] | 1431 | * @content: the XML content of the child if any. |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1432 | * |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1433 | * Creation of a new child element, added at the end of @parent childs list. |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1434 | * @ns and @content parameters are optionnal (NULL). If content is non NULL, |
| 1435 | * a child list containing the TEXTs and ENTITY_REFs node will be created. |
Daniel Veillard | 11a48ec | 1999-11-23 10:40:46 +0000 | [diff] [blame] | 1436 | * NOTE: @content is supposed to be a piece of XML CDATA, so it allow entities |
| 1437 | * references, but XML special chars need to be escaped first by using |
| 1438 | * xmlEncodeEntitiesReentrant(). Use xmlNewTextChild() if entities |
| 1439 | * support is not needed. |
| 1440 | * |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1441 | * Returns a pointer to the new node object. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1442 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 1443 | xmlNodePtr |
| 1444 | xmlNewChild(xmlNodePtr parent, xmlNsPtr ns, |
Daniel Veillard | 11a48ec | 1999-11-23 10:40:46 +0000 | [diff] [blame] | 1445 | const xmlChar *name, const xmlChar *content) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1446 | xmlNodePtr cur, prev; |
| 1447 | |
| 1448 | if (parent == NULL) { |
| 1449 | fprintf(stderr, "xmlNewChild : parent == NULL\n"); |
| 1450 | return(NULL); |
| 1451 | } |
| 1452 | |
| 1453 | if (name == NULL) { |
| 1454 | fprintf(stderr, "xmlNewChild : name == NULL\n"); |
| 1455 | return(NULL); |
| 1456 | } |
| 1457 | |
| 1458 | /* |
| 1459 | * Allocate a new node |
| 1460 | */ |
| 1461 | if (ns == NULL) |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1462 | cur = xmlNewDocNode(parent->doc, parent->ns, name, content); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1463 | else |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1464 | cur = xmlNewDocNode(parent->doc, ns, name, content); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1465 | if (cur == NULL) return(NULL); |
| 1466 | |
| 1467 | /* |
| 1468 | * add the new element at the end of the childs list. |
| 1469 | */ |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1470 | cur->type = XML_ELEMENT_NODE; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1471 | cur->parent = parent; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1472 | cur->doc = parent->doc; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1473 | if (parent->childs == NULL) { |
| 1474 | parent->childs = cur; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1475 | parent->last = cur; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1476 | } else { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1477 | prev = parent->last; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1478 | prev->next = cur; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1479 | cur->prev = prev; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1480 | parent->last = cur; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | return(cur); |
| 1484 | } |
| 1485 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1486 | /** |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1487 | * xmlAddSibling: |
| 1488 | * @cur: the child node |
| 1489 | * @elem: the new node |
| 1490 | * |
| 1491 | * Add a new element to the list of siblings of @cur |
| 1492 | * Returns the element or NULL in case of error. |
| 1493 | */ |
| 1494 | xmlNodePtr |
| 1495 | xmlAddSibling(xmlNodePtr cur, xmlNodePtr elem) { |
| 1496 | xmlNodePtr parent; |
| 1497 | |
| 1498 | if (cur == NULL) { |
| 1499 | fprintf(stderr, "xmlAddSibling : cur == NULL\n"); |
| 1500 | return(NULL); |
| 1501 | } |
| 1502 | |
| 1503 | if (elem == NULL) { |
| 1504 | fprintf(stderr, "xmlAddSibling : elem == NULL\n"); |
| 1505 | return(NULL); |
| 1506 | } |
| 1507 | |
| 1508 | if ((cur->doc != NULL) && (elem->doc != NULL) && |
| 1509 | (cur->doc != elem->doc)) { |
| 1510 | fprintf(stderr, |
| 1511 | "xmlAddSibling: Elements moved to a different document\n"); |
| 1512 | } |
| 1513 | |
| 1514 | while (cur->next != NULL) cur = cur->next; |
| 1515 | |
| 1516 | if (elem->doc == NULL) |
| 1517 | elem->doc = cur->doc; /* the parent may not be linked to a doc ! */ |
| 1518 | |
| 1519 | parent = cur->parent; |
| 1520 | elem->prev = cur; |
| 1521 | elem->next = NULL; |
| 1522 | elem->parent = parent; |
| 1523 | cur->next = elem; |
| 1524 | if (parent != NULL) |
| 1525 | parent->last = elem; |
| 1526 | |
| 1527 | return(elem); |
| 1528 | } |
| 1529 | |
| 1530 | /** |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1531 | * xmlAddChild: |
| 1532 | * @parent: the parent node |
| 1533 | * @cur: the child node |
| 1534 | * |
| 1535 | * Add a new child element, to @parent, at the end of the child list. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1536 | * Returns the child or NULL in case of error. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1537 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 1538 | xmlNodePtr |
| 1539 | xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1540 | xmlNodePtr prev; |
| 1541 | |
| 1542 | if (parent == NULL) { |
| 1543 | fprintf(stderr, "xmladdChild : parent == NULL\n"); |
| 1544 | return(NULL); |
| 1545 | } |
| 1546 | |
| 1547 | if (cur == NULL) { |
| 1548 | fprintf(stderr, "xmladdChild : child == NULL\n"); |
| 1549 | return(NULL); |
| 1550 | } |
| 1551 | |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1552 | if ((cur->doc != NULL) && (parent->doc != NULL) && |
| 1553 | (cur->doc != parent->doc)) { |
| 1554 | fprintf(stderr, "Elements moved to a different document\n"); |
| 1555 | } |
| 1556 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1557 | /* |
| 1558 | * add the new element at the end of the childs list. |
| 1559 | */ |
| 1560 | cur->parent = parent; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1561 | cur->doc = parent->doc; /* the parent may not be linked to a doc ! */ |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1562 | |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1563 | /* |
| 1564 | * Handle the case where parent->content != NULL, in that case it will |
| 1565 | * create a intermediate TEXT node. |
| 1566 | */ |
| 1567 | if (parent->content != NULL) { |
| 1568 | xmlNodePtr text; |
| 1569 | |
| 1570 | text = xmlNewDocText(parent->doc, parent->content); |
| 1571 | if (text != NULL) { |
| 1572 | text->next = parent->childs; |
| 1573 | if (text->next != NULL) |
| 1574 | text->next->prev = text; |
| 1575 | parent->childs = text; |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1576 | UPDATE_LAST_CHILD(parent) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 1577 | xmlFree(parent->content); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1578 | parent->content = NULL; |
| 1579 | } |
| 1580 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1581 | if (parent->childs == NULL) { |
| 1582 | parent->childs = cur; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1583 | parent->last = cur; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1584 | } else { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1585 | prev = parent->last; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1586 | prev->next = cur; |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 1587 | cur->prev = prev; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1588 | parent->last = cur; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1589 | } |
| 1590 | |
| 1591 | return(cur); |
| 1592 | } |
| 1593 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1594 | /** |
| 1595 | * xmlGetLastChild: |
| 1596 | * @parent: the parent node |
| 1597 | * |
| 1598 | * Search the last child of a node. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1599 | * Returns the last child or NULL if none. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1600 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 1601 | xmlNodePtr |
| 1602 | xmlGetLastChild(xmlNodePtr parent) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1603 | if (parent == NULL) { |
| 1604 | fprintf(stderr, "xmlGetLastChild : parent == NULL\n"); |
| 1605 | return(NULL); |
| 1606 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1607 | return(parent->last); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1608 | } |
| 1609 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1610 | /** |
| 1611 | * xmlFreeNodeList: |
| 1612 | * @cur: the first node in the list |
| 1613 | * |
| 1614 | * Free a node and all its siblings, this is a recursive behaviour, all |
| 1615 | * the childs are freed too. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1616 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 1617 | void |
| 1618 | xmlFreeNodeList(xmlNodePtr cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1619 | xmlNodePtr next; |
| 1620 | if (cur == NULL) { |
| 1621 | fprintf(stderr, "xmlFreeNodeList : node == NULL\n"); |
| 1622 | return; |
| 1623 | } |
| 1624 | while (cur != NULL) { |
| 1625 | next = cur->next; |
| 1626 | xmlFreeNode(cur); |
| 1627 | cur = next; |
| 1628 | } |
| 1629 | } |
| 1630 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 1631 | /** |
| 1632 | * xmlFreeNode: |
| 1633 | * @cur: the node |
| 1634 | * |
| 1635 | * Free a node, this is a recursive behaviour, all the childs are freed too. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1636 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 1637 | void |
| 1638 | xmlFreeNode(xmlNodePtr cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1639 | if (cur == NULL) { |
| 1640 | fprintf(stderr, "xmlFreeNode : node == NULL\n"); |
| 1641 | return; |
| 1642 | } |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1643 | cur->doc = NULL; |
| 1644 | cur->parent = NULL; |
| 1645 | cur->next = NULL; |
| 1646 | cur->prev = NULL; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1647 | if (cur->childs != NULL) xmlFreeNodeList(cur->childs); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 1648 | if (cur->properties != NULL) xmlFreePropList(cur->properties); |
| 1649 | if (cur->type != XML_ENTITY_REF_NODE) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 1650 | if (cur->content != NULL) xmlFree(cur->content); |
| 1651 | if (cur->name != NULL) xmlFree((char *) cur->name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1652 | if (cur->nsDef != NULL) xmlFreeNsList(cur->nsDef); |
| 1653 | memset(cur, -1, sizeof(xmlNode)); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 1654 | xmlFree(cur); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 1657 | /** |
| 1658 | * xmlUnlinkNode: |
| 1659 | * @cur: the node |
| 1660 | * |
| 1661 | * Unlink a node from it's current context, the node is not freed |
| 1662 | */ |
| 1663 | void |
| 1664 | xmlUnlinkNode(xmlNodePtr cur) { |
| 1665 | if (cur == NULL) { |
| 1666 | fprintf(stderr, "xmlUnlinkNode : node == NULL\n"); |
| 1667 | return; |
| 1668 | } |
| 1669 | if ((cur->parent != NULL) && (cur->parent->childs == cur)) |
| 1670 | cur->parent->childs = cur->next; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1671 | if ((cur->parent != NULL) && (cur->parent->last == cur)) |
| 1672 | cur->parent->last = cur->prev; |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 1673 | if (cur->next != NULL) |
| 1674 | cur->next->prev = cur->prev; |
| 1675 | if (cur->prev != NULL) |
| 1676 | cur->prev->next = cur->next; |
| 1677 | cur->next = cur->prev = NULL; |
| 1678 | cur->parent = NULL; |
| 1679 | } |
| 1680 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 1681 | /************************************************************************ |
| 1682 | * * |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 1683 | * Copy operations * |
| 1684 | * * |
| 1685 | ************************************************************************/ |
| 1686 | |
| 1687 | /** |
| 1688 | * xmlCopyNamespace: |
| 1689 | * @cur: the namespace |
| 1690 | * |
| 1691 | * Do a copy of the namespace. |
| 1692 | * |
| 1693 | * Returns: a new xmlNsPtr, or NULL in case of error. |
| 1694 | */ |
| 1695 | xmlNsPtr |
| 1696 | xmlCopyNamespace(xmlNsPtr cur) { |
| 1697 | xmlNsPtr ret; |
| 1698 | |
| 1699 | if (cur == NULL) return(NULL); |
| 1700 | switch (cur->type) { |
| 1701 | case XML_GLOBAL_NAMESPACE: |
| 1702 | ret = xmlNewGlobalNs(NULL, cur->href, cur->prefix); |
| 1703 | break; |
| 1704 | case XML_LOCAL_NAMESPACE: |
| 1705 | ret = xmlNewNs(NULL, cur->href, cur->prefix); |
| 1706 | break; |
| 1707 | default: |
| 1708 | fprintf(stderr, "xmlCopyNamespace: unknown type %d\n", cur->type); |
| 1709 | return(NULL); |
| 1710 | } |
| 1711 | return(ret); |
| 1712 | } |
| 1713 | |
| 1714 | /** |
| 1715 | * xmlCopyNamespaceList: |
| 1716 | * @cur: the first namespace |
| 1717 | * |
| 1718 | * Do a copy of an namespace list. |
| 1719 | * |
| 1720 | * Returns: a new xmlNsPtr, or NULL in case of error. |
| 1721 | */ |
| 1722 | xmlNsPtr |
| 1723 | xmlCopyNamespaceList(xmlNsPtr cur) { |
| 1724 | xmlNsPtr ret = NULL; |
| 1725 | xmlNsPtr p = NULL,q; |
| 1726 | |
| 1727 | while (cur != NULL) { |
| 1728 | q = xmlCopyNamespace(cur); |
| 1729 | if (p == NULL) { |
| 1730 | ret = p = q; |
| 1731 | } else { |
| 1732 | p->next = q; |
| 1733 | p = q; |
| 1734 | } |
| 1735 | cur = cur->next; |
| 1736 | } |
| 1737 | return(ret); |
| 1738 | } |
| 1739 | |
| 1740 | /** |
| 1741 | * xmlCopyProp: |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1742 | * @target: the element where the attribute will be grafted |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 1743 | * @cur: the attribute |
| 1744 | * |
| 1745 | * Do a copy of the attribute. |
| 1746 | * |
| 1747 | * Returns: a new xmlAttrPtr, or NULL in case of error. |
| 1748 | */ |
| 1749 | xmlAttrPtr |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1750 | xmlCopyProp(xmlNodePtr target, xmlAttrPtr cur) { |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 1751 | xmlAttrPtr ret; |
| 1752 | |
| 1753 | if (cur == NULL) return(NULL); |
| 1754 | if (cur->val != NULL) |
| 1755 | ret = xmlNewDocProp(cur->val->doc, cur->name, NULL); |
| 1756 | else |
| 1757 | ret = xmlNewDocProp(NULL, cur->name, NULL); |
| 1758 | if (ret == NULL) return(NULL); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1759 | |
| 1760 | if ((cur->ns != NULL) && (target != NULL)) { |
| 1761 | xmlNsPtr ns; |
| 1762 | |
| 1763 | ns = xmlSearchNs(target->doc, target, cur->ns->prefix); |
| 1764 | ret->ns = ns; |
| 1765 | } else |
| 1766 | ret->ns = NULL; |
| 1767 | |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 1768 | if (cur->val != NULL) |
| 1769 | ret->val = xmlCopyNodeList(cur->val); |
| 1770 | return(ret); |
| 1771 | } |
| 1772 | |
| 1773 | /** |
| 1774 | * xmlCopyPropList: |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1775 | * @target: the element where the attributes will be grafted |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 1776 | * @cur: the first attribute |
| 1777 | * |
| 1778 | * Do a copy of an attribute list. |
| 1779 | * |
| 1780 | * Returns: a new xmlAttrPtr, or NULL in case of error. |
| 1781 | */ |
| 1782 | xmlAttrPtr |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1783 | xmlCopyPropList(xmlNodePtr target, xmlAttrPtr cur) { |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 1784 | xmlAttrPtr ret = NULL; |
| 1785 | xmlAttrPtr p = NULL,q; |
| 1786 | |
| 1787 | while (cur != NULL) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1788 | q = xmlCopyProp(target, cur); |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 1789 | if (p == NULL) { |
| 1790 | ret = p = q; |
| 1791 | } else { |
| 1792 | p->next = q; |
| 1793 | p = q; |
| 1794 | } |
| 1795 | cur = cur->next; |
| 1796 | } |
| 1797 | return(ret); |
| 1798 | } |
| 1799 | |
| 1800 | /* |
Daniel Veillard | 11a48ec | 1999-11-23 10:40:46 +0000 | [diff] [blame] | 1801 | * NOTE abeut the CopyNode operations ! |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 1802 | * |
| 1803 | * They are splitted into external and internal parts for one |
| 1804 | * tricky reason: namespaces. Doing a direct copy of a node |
| 1805 | * say RPM:Copyright without changing the namespace pointer to |
| 1806 | * something else can produce stale links. One way to do it is |
| 1807 | * to keep a reference counter but this doesn't work as soon |
| 1808 | * as one move the element or the subtree out of the scope of |
| 1809 | * the existing namespace. The actual solution seems to add |
| 1810 | * a copy of the namespace at the top of the copied tree if |
| 1811 | * not available in the subtree. |
| 1812 | * Hence two functions, the public front-end call the inner ones |
| 1813 | */ |
| 1814 | |
| 1815 | static xmlNodePtr |
| 1816 | xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent); |
| 1817 | |
| 1818 | static xmlNodePtr |
| 1819 | xmlStaticCopyNode(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, |
| 1820 | int recursive) { |
| 1821 | xmlNodePtr ret; |
| 1822 | |
| 1823 | if (node == NULL) return(NULL); |
| 1824 | /* |
| 1825 | * Allocate a new node and fill the fields. |
| 1826 | */ |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 1827 | ret = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 1828 | if (ret == NULL) { |
| 1829 | fprintf(stderr, "xmlStaticCopyNode : malloc failed\n"); |
| 1830 | return(NULL); |
| 1831 | } |
| 1832 | |
| 1833 | ret->type = node->type; |
| 1834 | ret->doc = doc; |
| 1835 | ret->parent = parent; |
| 1836 | ret->next = NULL; |
| 1837 | ret->prev = NULL; |
| 1838 | ret->childs = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 1839 | ret->last = NULL; |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 1840 | ret->properties = NULL; |
| 1841 | if (node->name != NULL) |
| 1842 | ret->name = xmlStrdup(node->name); |
| 1843 | else |
| 1844 | ret->name = NULL; |
| 1845 | ret->ns = NULL; |
| 1846 | ret->nsDef = NULL; |
| 1847 | if ((node->content != NULL) && (node->type != XML_ENTITY_REF_NODE)) |
| 1848 | ret->content = xmlStrdup(node->content); |
| 1849 | else |
| 1850 | ret->content = NULL; |
Daniel Veillard | 27d8874 | 1999-05-29 11:51:49 +0000 | [diff] [blame] | 1851 | #ifndef XML_WITHOUT_CORBA |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 1852 | ret->_private = NULL; |
| 1853 | ret->vepv = NULL; |
| 1854 | #endif |
| 1855 | if (parent != NULL) |
| 1856 | xmlAddChild(parent, ret); |
| 1857 | |
| 1858 | if (!recursive) return(ret); |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 1859 | if (node->nsDef != NULL) |
| 1860 | ret->nsDef = xmlCopyNamespaceList(node->nsDef); |
| 1861 | |
| 1862 | if (node->ns != NULL) { |
| 1863 | xmlNsPtr ns; |
| 1864 | |
| 1865 | ns = xmlSearchNs(doc, ret, node->ns->prefix); |
| 1866 | if (ns == NULL) { |
| 1867 | /* |
| 1868 | * Humm, we are copying an element whose namespace is defined |
| 1869 | * out of the new tree scope. Search it in the original tree |
| 1870 | * and add it at the top of the new tree |
| 1871 | */ |
| 1872 | ns = xmlSearchNs(node->doc, node, node->ns->prefix); |
| 1873 | if (ns != NULL) { |
| 1874 | xmlNodePtr root = ret; |
| 1875 | |
| 1876 | while (root->parent != NULL) root = root->parent; |
| 1877 | xmlNewNs(root, ns->href, ns->prefix); |
| 1878 | } |
| 1879 | } else { |
| 1880 | /* |
| 1881 | * reference the existing namespace definition in our own tree. |
| 1882 | */ |
| 1883 | ret->ns = ns; |
| 1884 | } |
| 1885 | } |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 1886 | if (node->properties != NULL) |
| 1887 | ret->properties = xmlCopyPropList(ret, node->properties); |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 1888 | if (node->childs != NULL) |
| 1889 | ret->childs = xmlStaticCopyNodeList(node->childs, doc, ret); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1890 | UPDATE_LAST_CHILD(ret) |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 1891 | return(ret); |
| 1892 | } |
| 1893 | |
| 1894 | static xmlNodePtr |
| 1895 | xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent) { |
| 1896 | xmlNodePtr ret = NULL; |
| 1897 | xmlNodePtr p = NULL,q; |
| 1898 | |
| 1899 | while (node != NULL) { |
| 1900 | q = xmlStaticCopyNode(node, doc, parent, 1); |
| 1901 | if (parent == NULL) { |
| 1902 | if (ret == NULL) ret = q; |
| 1903 | } else { |
| 1904 | if (ret == NULL) { |
| 1905 | q->prev = NULL; |
| 1906 | ret = p = q; |
| 1907 | } else { |
| 1908 | p->next = q; |
| 1909 | q->prev = p; |
| 1910 | p = q; |
| 1911 | } |
| 1912 | } |
| 1913 | node = node->next; |
| 1914 | } |
| 1915 | return(ret); |
| 1916 | } |
| 1917 | |
| 1918 | /** |
| 1919 | * xmlCopyNode: |
| 1920 | * @node: the node |
| 1921 | * @recursive: if 1 do a recursive copy. |
| 1922 | * |
| 1923 | * Do a copy of the node. |
| 1924 | * |
| 1925 | * Returns: a new xmlNodePtr, or NULL in case of error. |
| 1926 | */ |
| 1927 | xmlNodePtr |
| 1928 | xmlCopyNode(xmlNodePtr node, int recursive) { |
| 1929 | xmlNodePtr ret; |
| 1930 | |
| 1931 | ret = xmlStaticCopyNode(node, NULL, NULL, recursive); |
| 1932 | return(ret); |
| 1933 | } |
| 1934 | |
| 1935 | /** |
| 1936 | * xmlCopyNodeList: |
| 1937 | * @node: the first node in the list. |
| 1938 | * |
| 1939 | * Do a recursive copy of the node list. |
| 1940 | * |
| 1941 | * Returns: a new xmlNodePtr, or NULL in case of error. |
| 1942 | */ |
| 1943 | xmlNodePtr xmlCopyNodeList(xmlNodePtr node) { |
| 1944 | xmlNodePtr ret = xmlStaticCopyNodeList(node, NULL, NULL); |
| 1945 | return(ret); |
| 1946 | } |
| 1947 | |
| 1948 | /** |
| 1949 | * xmlCopyElement: |
| 1950 | * @elem: the element |
| 1951 | * |
| 1952 | * Do a copy of the element definition. |
| 1953 | * |
| 1954 | * Returns: a new xmlElementPtr, or NULL in case of error. |
| 1955 | xmlElementPtr |
| 1956 | xmlCopyElement(xmlElementPtr elem) { |
| 1957 | xmlElementPtr ret; |
| 1958 | |
| 1959 | if (elem == NULL) return(NULL); |
| 1960 | ret = xmlNewDocElement(elem->doc, elem->ns, elem->name, elem->content); |
| 1961 | if (ret == NULL) return(NULL); |
| 1962 | if (!recursive) return(ret); |
| 1963 | if (elem->properties != NULL) |
| 1964 | ret->properties = xmlCopyPropList(elem->properties); |
| 1965 | |
| 1966 | if (elem->nsDef != NULL) |
| 1967 | ret->nsDef = xmlCopyNamespaceList(elem->nsDef); |
| 1968 | if (elem->childs != NULL) |
| 1969 | ret->childs = xmlCopyElementList(elem->childs); |
| 1970 | return(ret); |
| 1971 | } |
| 1972 | */ |
| 1973 | |
| 1974 | /** |
| 1975 | * xmlCopyDtd: |
| 1976 | * @dtd: the dtd |
| 1977 | * |
| 1978 | * Do a copy of the dtd. |
| 1979 | * |
| 1980 | * Returns: a new xmlDtdPtr, or NULL in case of error. |
| 1981 | */ |
| 1982 | xmlDtdPtr |
| 1983 | xmlCopyDtd(xmlDtdPtr dtd) { |
| 1984 | xmlDtdPtr ret; |
| 1985 | |
| 1986 | if (dtd == NULL) return(NULL); |
| 1987 | ret = xmlNewDtd(NULL, dtd->name, dtd->ExternalID, dtd->SystemID); |
| 1988 | if (ret == NULL) return(NULL); |
| 1989 | if (dtd->entities != NULL) |
| 1990 | ret->entities = (void *) xmlCopyEntitiesTable( |
| 1991 | (xmlEntitiesTablePtr) dtd->entities); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 1992 | if (dtd->notations != NULL) |
| 1993 | ret->notations = (void *) xmlCopyNotationTable( |
| 1994 | (xmlNotationTablePtr) dtd->notations); |
| 1995 | if (dtd->elements != NULL) |
| 1996 | ret->elements = (void *) xmlCopyElementTable( |
| 1997 | (xmlElementTablePtr) dtd->elements); |
| 1998 | if (dtd->attributes != NULL) |
| 1999 | ret->attributes = (void *) xmlCopyAttributeTable( |
| 2000 | (xmlAttributeTablePtr) dtd->attributes); |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 2001 | return(ret); |
| 2002 | } |
| 2003 | |
| 2004 | /** |
| 2005 | * xmlCopyDoc: |
| 2006 | * @doc: the document |
| 2007 | * @recursive: if 1 do a recursive copy. |
| 2008 | * |
| 2009 | * Do a copy of the document info. If recursive, the content tree will |
| 2010 | * be copied too as well as Dtd, namespaces and entities. |
| 2011 | * |
| 2012 | * Returns: a new xmlDocPtr, or NULL in case of error. |
| 2013 | */ |
| 2014 | xmlDocPtr |
| 2015 | xmlCopyDoc(xmlDocPtr doc, int recursive) { |
| 2016 | xmlDocPtr ret; |
| 2017 | |
| 2018 | if (doc == NULL) return(NULL); |
| 2019 | ret = xmlNewDoc(doc->version); |
| 2020 | if (ret == NULL) return(NULL); |
| 2021 | if (doc->name != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2022 | ret->name = xmlMemStrdup(doc->name); |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 2023 | if (doc->encoding != NULL) |
| 2024 | ret->encoding = xmlStrdup(doc->encoding); |
| 2025 | ret->compression = doc->compression; |
| 2026 | ret->standalone = doc->standalone; |
| 2027 | if (!recursive) return(ret); |
| 2028 | |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2029 | if (doc->intSubset != NULL) |
| 2030 | ret->intSubset = xmlCopyDtd(doc->intSubset); |
Daniel Veillard | be36afe | 1998-11-27 06:39:50 +0000 | [diff] [blame] | 2031 | if (doc->oldNs != NULL) |
| 2032 | ret->oldNs = xmlCopyNamespaceList(doc->oldNs); |
| 2033 | if (doc->root != NULL) |
| 2034 | ret->root = xmlStaticCopyNodeList(doc->root, ret, NULL); |
| 2035 | return(ret); |
| 2036 | } |
| 2037 | |
| 2038 | /************************************************************************ |
| 2039 | * * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2040 | * Content access functions * |
| 2041 | * * |
| 2042 | ************************************************************************/ |
| 2043 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2044 | /** |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2045 | * xmlNodeSetLang: |
| 2046 | * @cur: the node being changed |
| 2047 | * @lang: the langage description |
| 2048 | * |
| 2049 | * Searches the language of a node, i.e. the values of the xml:lang |
| 2050 | * attribute or the one carried by the nearest ancestor. |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2051 | */ |
| 2052 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2053 | xmlNodeSetLang(xmlNodePtr cur, const xmlChar *lang) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2054 | /* TODO xmlNodeSetLang check against the production [33] LanguageID */ |
| 2055 | xmlSetProp(cur, BAD_CAST "xml:lang", lang); |
| 2056 | } |
| 2057 | |
| 2058 | /** |
| 2059 | * xmlNodeGetLang: |
| 2060 | * @cur: the node being checked |
| 2061 | * |
| 2062 | * Searches the language of a node, i.e. the values of the xml:lang |
| 2063 | * attribute or the one carried by the nearest ancestor. |
| 2064 | * |
| 2065 | * Returns a pointer to the lang value, or NULL if not found |
Daniel Veillard | a819dac | 1999-11-24 18:04:22 +0000 | [diff] [blame^] | 2066 | * It's up to the caller to free the memory. |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2067 | */ |
Daniel Veillard | a819dac | 1999-11-24 18:04:22 +0000 | [diff] [blame^] | 2068 | xmlChar * |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2069 | xmlNodeGetLang(xmlNodePtr cur) { |
Daniel Veillard | a819dac | 1999-11-24 18:04:22 +0000 | [diff] [blame^] | 2070 | xmlChar *lang; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2071 | |
| 2072 | while (cur != NULL) { |
| 2073 | lang = xmlGetProp(cur, BAD_CAST "xml:lang"); |
| 2074 | if (lang != NULL) |
| 2075 | return(lang); |
| 2076 | cur = cur->parent; |
| 2077 | } |
| 2078 | return(NULL); |
| 2079 | } |
| 2080 | |
| 2081 | /** |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2082 | * xmlNodeGetContent: |
| 2083 | * @cur: the node being read |
| 2084 | * |
| 2085 | * Read the value of a node, this can be either the text carried |
| 2086 | * directly by this node if it's a TEXT node or the aggregate string |
| 2087 | * of the values carried by this node child's (TEXT and ENTITY_REF). |
| 2088 | * Entity references are substitued. |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2089 | * Returns a new xmlChar * or NULL if no content is available. |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2090 | * It's up to the caller to free the memory. |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2091 | */ |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2092 | xmlChar * |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2093 | xmlNodeGetContent(xmlNodePtr cur) { |
| 2094 | if (cur == NULL) return(NULL); |
| 2095 | switch (cur->type) { |
| 2096 | case XML_DOCUMENT_FRAG_NODE: |
| 2097 | case XML_ELEMENT_NODE: |
| 2098 | return(xmlNodeListGetString(cur->doc, cur->childs, 1)); |
| 2099 | break; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2100 | case XML_ATTRIBUTE_NODE: { |
| 2101 | xmlAttrPtr attr = (xmlAttrPtr) cur; |
| 2102 | if (attr->node != NULL) |
| 2103 | return(xmlNodeListGetString(attr->node->doc, attr->val, 1)); |
| 2104 | else |
| 2105 | return(xmlNodeListGetString(NULL, attr->val, 1)); |
| 2106 | break; |
| 2107 | } |
| 2108 | case XML_PI_NODE: |
| 2109 | if (cur->content != NULL) |
| 2110 | return(xmlStrdup(cur->content)); |
| 2111 | return(NULL); |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2112 | case XML_ENTITY_REF_NODE: |
| 2113 | case XML_ENTITY_NODE: |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2114 | case XML_COMMENT_NODE: |
| 2115 | case XML_DOCUMENT_NODE: |
Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 2116 | case XML_HTML_DOCUMENT_NODE: |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2117 | case XML_DOCUMENT_TYPE_NODE: |
| 2118 | case XML_NOTATION_NODE: |
| 2119 | return(NULL); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 2120 | case XML_CDATA_SECTION_NODE: |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2121 | case XML_TEXT_NODE: |
| 2122 | if (cur->content != NULL) |
| 2123 | return(xmlStrdup(cur->content)); |
| 2124 | return(NULL); |
| 2125 | } |
| 2126 | return(NULL); |
| 2127 | } |
| 2128 | |
| 2129 | /** |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2130 | * xmlNodeSetContent: |
| 2131 | * @cur: the node being modified |
| 2132 | * @content: the new value of the content |
| 2133 | * |
| 2134 | * Replace the content of a node. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2135 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2136 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2137 | xmlNodeSetContent(xmlNodePtr cur, const xmlChar *content) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2138 | if (cur == NULL) { |
| 2139 | fprintf(stderr, "xmlNodeSetContent : node == NULL\n"); |
| 2140 | return; |
| 2141 | } |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2142 | switch (cur->type) { |
| 2143 | case XML_DOCUMENT_FRAG_NODE: |
| 2144 | case XML_ELEMENT_NODE: |
| 2145 | if (cur->content != NULL) { |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2146 | xmlFree(cur->content); |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2147 | cur->content = NULL; |
| 2148 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2149 | if (cur->childs != NULL) xmlFreeNodeList(cur->childs); |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2150 | cur->childs = xmlStringGetNodeList(cur->doc, content); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2151 | UPDATE_LAST_CHILD(cur) |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2152 | break; |
| 2153 | case XML_ATTRIBUTE_NODE: |
| 2154 | break; |
| 2155 | case XML_TEXT_NODE: |
| 2156 | case XML_CDATA_SECTION_NODE: |
| 2157 | case XML_ENTITY_REF_NODE: |
| 2158 | case XML_ENTITY_NODE: |
| 2159 | case XML_PI_NODE: |
| 2160 | case XML_COMMENT_NODE: |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2161 | if (cur->content != NULL) xmlFree(cur->content); |
| 2162 | if (cur->childs != NULL) xmlFreeNodeList(cur->childs); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2163 | cur->last = cur->childs = NULL; |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2164 | if (content != NULL) |
| 2165 | cur->content = xmlStrdup(content); |
| 2166 | else |
| 2167 | cur->content = NULL; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2168 | break; |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2169 | case XML_DOCUMENT_NODE: |
Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 2170 | case XML_HTML_DOCUMENT_NODE: |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2171 | case XML_DOCUMENT_TYPE_NODE: |
| 2172 | break; |
| 2173 | case XML_NOTATION_NODE: |
| 2174 | break; |
| 2175 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2176 | } |
| 2177 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2178 | /** |
| 2179 | * xmlNodeSetContentLen: |
| 2180 | * @cur: the node being modified |
| 2181 | * @content: the new value of the content |
| 2182 | * @len: the size of @content |
| 2183 | * |
| 2184 | * Replace the content of a node. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2185 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2186 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2187 | xmlNodeSetContentLen(xmlNodePtr cur, const xmlChar *content, int len) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2188 | if (cur == NULL) { |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2189 | fprintf(stderr, "xmlNodeSetContentLen : node == NULL\n"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2190 | return; |
| 2191 | } |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2192 | switch (cur->type) { |
| 2193 | case XML_DOCUMENT_FRAG_NODE: |
| 2194 | case XML_ELEMENT_NODE: |
| 2195 | if (cur->content != NULL) { |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2196 | xmlFree(cur->content); |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2197 | cur->content = NULL; |
| 2198 | } |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2199 | if (cur->childs != NULL) xmlFreeNodeList(cur->childs); |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2200 | cur->childs = xmlStringLenGetNodeList(cur->doc, content, len); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2201 | UPDATE_LAST_CHILD(cur) |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2202 | break; |
| 2203 | case XML_ATTRIBUTE_NODE: |
| 2204 | break; |
| 2205 | case XML_TEXT_NODE: |
| 2206 | case XML_CDATA_SECTION_NODE: |
| 2207 | case XML_ENTITY_REF_NODE: |
| 2208 | case XML_ENTITY_NODE: |
| 2209 | case XML_PI_NODE: |
| 2210 | case XML_COMMENT_NODE: |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2211 | if (cur->content != NULL) xmlFree(cur->content); |
| 2212 | if (cur->childs != NULL) xmlFreeNodeList(cur->childs); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2213 | cur->childs = cur->last = NULL; |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2214 | if (content != NULL) |
| 2215 | cur->content = xmlStrndup(content, len); |
| 2216 | else |
| 2217 | cur->content = NULL; |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2218 | break; |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2219 | case XML_DOCUMENT_NODE: |
Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 2220 | case XML_HTML_DOCUMENT_NODE: |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2221 | case XML_DOCUMENT_TYPE_NODE: |
| 2222 | break; |
| 2223 | case XML_NOTATION_NODE: |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2224 | if (cur->content != NULL) xmlFree(cur->content); |
| 2225 | if (cur->childs != NULL) xmlFreeNodeList(cur->childs); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2226 | cur->childs = cur->last = NULL; |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2227 | if (content != NULL) |
| 2228 | cur->content = xmlStrndup(content, len); |
| 2229 | else |
| 2230 | cur->content = NULL; |
| 2231 | break; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2232 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2233 | } |
| 2234 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2235 | /** |
| 2236 | * xmlNodeAddContentLen: |
| 2237 | * @cur: the node being modified |
| 2238 | * @content: extra content |
| 2239 | * @len: the size of @content |
| 2240 | * |
| 2241 | * Append the extra substring to the node content. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2242 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2243 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2244 | xmlNodeAddContentLen(xmlNodePtr cur, const xmlChar *content, int len) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2245 | if (cur == NULL) { |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2246 | fprintf(stderr, "xmlNodeAddContentLen : node == NULL\n"); |
| 2247 | return; |
| 2248 | } |
| 2249 | if (len <= 0) return; |
| 2250 | switch (cur->type) { |
| 2251 | case XML_DOCUMENT_FRAG_NODE: |
| 2252 | case XML_ELEMENT_NODE: { |
| 2253 | xmlNodePtr last = NULL, new; |
| 2254 | |
| 2255 | if (cur->childs != NULL) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2256 | last = cur->last; |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2257 | } else { |
| 2258 | if (cur->content != NULL) { |
| 2259 | cur->childs = xmlStringGetNodeList(cur->doc, cur->content); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2260 | UPDATE_LAST_CHILD(cur) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2261 | xmlFree(cur->content); |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2262 | cur->content = NULL; |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2263 | last = cur->last; |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2264 | } |
| 2265 | } |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2266 | new = xmlNewTextLen(content, len); |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2267 | if (new != NULL) { |
| 2268 | xmlAddChild(cur, new); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2269 | if ((last != NULL) && (last->next == new)) { |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2270 | xmlTextMerge(last, new); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2271 | } |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2272 | } |
| 2273 | break; |
| 2274 | } |
| 2275 | case XML_ATTRIBUTE_NODE: |
| 2276 | break; |
| 2277 | case XML_TEXT_NODE: |
| 2278 | case XML_CDATA_SECTION_NODE: |
| 2279 | case XML_ENTITY_REF_NODE: |
| 2280 | case XML_ENTITY_NODE: |
| 2281 | case XML_PI_NODE: |
| 2282 | case XML_COMMENT_NODE: |
| 2283 | if (content != NULL) |
| 2284 | cur->content = xmlStrncat(cur->content, content, len); |
| 2285 | case XML_DOCUMENT_NODE: |
Daniel Veillard | 7c1206f | 1999-10-14 09:10:25 +0000 | [diff] [blame] | 2286 | case XML_HTML_DOCUMENT_NODE: |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2287 | case XML_DOCUMENT_TYPE_NODE: |
| 2288 | break; |
| 2289 | case XML_NOTATION_NODE: |
| 2290 | if (content != NULL) |
| 2291 | cur->content = xmlStrncat(cur->content, content, len); |
| 2292 | break; |
| 2293 | } |
| 2294 | } |
| 2295 | |
| 2296 | /** |
| 2297 | * xmlNodeAddContent: |
| 2298 | * @cur: the node being modified |
| 2299 | * @content: extra content |
| 2300 | * |
| 2301 | * Append the extra substring to the node content. |
| 2302 | */ |
| 2303 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2304 | xmlNodeAddContent(xmlNodePtr cur, const xmlChar *content) { |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2305 | int len; |
| 2306 | |
| 2307 | if (cur == NULL) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2308 | fprintf(stderr, "xmlNodeAddContent : node == NULL\n"); |
| 2309 | return; |
| 2310 | } |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2311 | if (content == NULL) return; |
| 2312 | len = xmlStrlen(content); |
| 2313 | xmlNodeAddContentLen(cur, content, len); |
| 2314 | } |
| 2315 | |
| 2316 | /** |
| 2317 | * xmlTextMerge: |
| 2318 | * @first: the first text node |
| 2319 | * @second: the second text node being merged |
| 2320 | * |
| 2321 | * Merge two text nodes into one |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2322 | * Returns the first text node augmented |
Daniel Veillard | 1625364 | 1998-10-28 22:58:05 +0000 | [diff] [blame] | 2323 | */ |
| 2324 | xmlNodePtr |
| 2325 | xmlTextMerge(xmlNodePtr first, xmlNodePtr second) { |
| 2326 | if (first == NULL) return(second); |
| 2327 | if (second == NULL) return(first); |
| 2328 | if (first->type != XML_TEXT_NODE) return(first); |
| 2329 | if (second->type != XML_TEXT_NODE) return(first); |
| 2330 | xmlNodeAddContent(first, second->content); |
| 2331 | xmlUnlinkNode(second); |
| 2332 | xmlFreeNode(second); |
| 2333 | return(first); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2334 | } |
| 2335 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2336 | /** |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2337 | * xmlGetNsList: |
| 2338 | * @doc: the document |
| 2339 | * @node: the current node |
| 2340 | * |
| 2341 | * Search all the namespace applying to a given element. |
| 2342 | * Returns an NULL terminated array of all the xmlNsPtr found |
| 2343 | * that need to be freed by the caller or NULL if no |
| 2344 | * namespace if defined |
| 2345 | */ |
| 2346 | xmlNsPtr * |
| 2347 | xmlGetNsList(xmlDocPtr doc, xmlNodePtr node) { |
| 2348 | xmlNsPtr cur; |
| 2349 | xmlNsPtr *ret = NULL; |
| 2350 | int nbns = 0; |
| 2351 | int maxns = 10; |
| 2352 | int i; |
| 2353 | |
| 2354 | while (node != NULL) { |
| 2355 | cur = node->nsDef; |
| 2356 | while (cur != NULL) { |
| 2357 | if (ret == NULL) { |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2358 | ret = (xmlNsPtr *) xmlMalloc((maxns + 1) * sizeof(xmlNsPtr)); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2359 | if (ret == NULL) { |
| 2360 | fprintf(stderr, "xmlGetNsList : out of memory!\n"); |
| 2361 | return(NULL); |
| 2362 | } |
| 2363 | ret[nbns] = NULL; |
| 2364 | } |
| 2365 | for (i = 0;i < nbns;i++) { |
| 2366 | if ((cur->prefix == ret[i]->prefix) || |
| 2367 | (!xmlStrcmp(cur->prefix, ret[i]->prefix))) break; |
| 2368 | } |
| 2369 | if (i >= nbns) { |
| 2370 | if (nbns >= maxns) { |
| 2371 | maxns *= 2; |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2372 | ret = (xmlNsPtr *) xmlRealloc(ret, |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2373 | (maxns + 1) * sizeof(xmlNsPtr)); |
| 2374 | if (ret == NULL) { |
| 2375 | fprintf(stderr, "xmlGetNsList : realloc failed!\n"); |
| 2376 | return(NULL); |
| 2377 | } |
| 2378 | } |
| 2379 | ret[nbns++] = cur; |
| 2380 | ret[nbns] = NULL; |
| 2381 | } |
| 2382 | |
| 2383 | cur = cur->next; |
| 2384 | } |
| 2385 | node = node->parent; |
| 2386 | } |
| 2387 | return(ret); |
| 2388 | } |
| 2389 | |
| 2390 | /** |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2391 | * xmlSearchNs: |
| 2392 | * @doc: the document |
| 2393 | * @node: the current node |
| 2394 | * @nameSpace: the namespace string |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2395 | * |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2396 | * Search a Ns registered under a given name space for a document. |
| 2397 | * recurse on the parents until it finds the defined namespace |
| 2398 | * or return NULL otherwise. |
| 2399 | * @nameSpace can be NULL, this is a search for the default namespace. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2400 | * Returns the namespace pointer or NULL. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2401 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2402 | xmlNsPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2403 | xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2404 | xmlNsPtr cur; |
| 2405 | |
| 2406 | while (node != NULL) { |
| 2407 | cur = node->nsDef; |
| 2408 | while (cur != NULL) { |
| 2409 | if ((cur->prefix == NULL) && (nameSpace == NULL)) |
| 2410 | return(cur); |
| 2411 | if ((cur->prefix != NULL) && (nameSpace != NULL) && |
| 2412 | (!xmlStrcmp(cur->prefix, nameSpace))) |
| 2413 | return(cur); |
| 2414 | cur = cur->next; |
| 2415 | } |
| 2416 | node = node->parent; |
| 2417 | } |
| 2418 | if (doc != NULL) { |
| 2419 | cur = doc->oldNs; |
| 2420 | while (cur != NULL) { |
| 2421 | if ((cur->prefix != NULL) && (nameSpace != NULL) && |
| 2422 | (!xmlStrcmp(cur->prefix, nameSpace))) |
| 2423 | return(cur); |
| 2424 | cur = cur->next; |
| 2425 | } |
| 2426 | } |
| 2427 | return(NULL); |
| 2428 | } |
| 2429 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2430 | /** |
| 2431 | * xmlSearchNsByHref: |
| 2432 | * @doc: the document |
| 2433 | * @node: the current node |
| 2434 | * @href: the namespace value |
| 2435 | * |
| 2436 | * Search a Ns aliasing a given URI. Recurse on the parents until it finds |
| 2437 | * the defined namespace or return NULL otherwise. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2438 | * Returns the namespace pointer or NULL. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2439 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2440 | xmlNsPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2441 | xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const xmlChar *href) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2442 | xmlNsPtr cur; |
| 2443 | |
| 2444 | while (node != NULL) { |
| 2445 | cur = node->nsDef; |
| 2446 | while (cur != NULL) { |
| 2447 | if ((cur->href != NULL) && (href != NULL) && |
| 2448 | (!xmlStrcmp(cur->href, href))) |
| 2449 | return(cur); |
| 2450 | cur = cur->next; |
| 2451 | } |
| 2452 | node = node->parent; |
| 2453 | } |
| 2454 | if (doc != NULL) { |
| 2455 | cur = doc->oldNs; |
| 2456 | while (cur != NULL) { |
| 2457 | if ((cur->href != NULL) && (href != NULL) && |
| 2458 | (!xmlStrcmp(cur->href, href))) |
| 2459 | return(cur); |
| 2460 | cur = cur->next; |
| 2461 | } |
| 2462 | } |
| 2463 | return(NULL); |
| 2464 | } |
| 2465 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2466 | /** |
| 2467 | * xmlGetProp: |
| 2468 | * @node: the node |
| 2469 | * @name: the attribute name |
| 2470 | * |
| 2471 | * Search and get the value of an attribute associated to a node |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 2472 | * This does the entity substitution. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2473 | * Returns the attribute value or NULL if not found. |
Daniel Veillard | a819dac | 1999-11-24 18:04:22 +0000 | [diff] [blame^] | 2474 | * It's up to the caller to free the memory. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2475 | */ |
Daniel Veillard | a819dac | 1999-11-24 18:04:22 +0000 | [diff] [blame^] | 2476 | xmlChar * |
| 2477 | xmlGetProp(xmlNodePtr node, const xmlChar *name) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2478 | xmlAttrPtr prop = node->properties; |
| 2479 | |
| 2480 | while (prop != NULL) { |
Daniel Veillard | 6817893 | 1999-02-08 18:34:36 +0000 | [diff] [blame] | 2481 | if (!xmlStrcmp(prop->name, name)) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2482 | xmlChar *ret; |
Daniel Veillard | 6800ef3 | 1999-02-08 18:33:22 +0000 | [diff] [blame] | 2483 | |
| 2484 | ret = xmlNodeListGetString(node->doc, prop->val, 1); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2485 | if (ret == NULL) return(xmlStrdup((xmlChar *)"")); |
Daniel Veillard | 6800ef3 | 1999-02-08 18:33:22 +0000 | [diff] [blame] | 2486 | return(ret); |
Daniel Veillard | 6817893 | 1999-02-08 18:34:36 +0000 | [diff] [blame] | 2487 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2488 | prop = prop->next; |
| 2489 | } |
| 2490 | return(NULL); |
| 2491 | } |
| 2492 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2493 | /** |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 2494 | * xmlSetProp: |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2495 | * @node: the node |
| 2496 | * @name: the attribute name |
| 2497 | * @value: the attribute value |
| 2498 | * |
| 2499 | * Set (or reset) an attribute carried by a node. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2500 | * Returns the attribute pointer. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2501 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2502 | xmlAttrPtr |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2503 | xmlSetProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2504 | xmlAttrPtr prop = node->properties; |
| 2505 | |
| 2506 | while (prop != NULL) { |
| 2507 | if (!xmlStrcmp(prop->name, name)) { |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 2508 | if (prop->val != NULL) |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2509 | xmlFreeNodeList(prop->val); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 2510 | prop->val = NULL; |
Daniel Veillard | 51e3b15 | 1999-11-12 17:02:31 +0000 | [diff] [blame] | 2511 | if (value != NULL) { |
| 2512 | xmlChar *buffer; |
| 2513 | buffer = xmlEncodeEntitiesReentrant(node->doc, value); |
| 2514 | prop->val = xmlStringGetNodeList(node->doc, buffer); |
| 2515 | xmlFree(buffer); |
| 2516 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2517 | return(prop); |
| 2518 | } |
| 2519 | prop = prop->next; |
| 2520 | } |
| 2521 | prop = xmlNewProp(node, name, value); |
| 2522 | return(prop); |
| 2523 | } |
| 2524 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2525 | /** |
| 2526 | * xmlNodeIsText: |
| 2527 | * @node: the node |
| 2528 | * |
| 2529 | * Is this node a Text node ? |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2530 | * Returns 1 yes, 0 no |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2531 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2532 | int |
| 2533 | xmlNodeIsText(xmlNodePtr node) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2534 | if (node == NULL) return(0); |
| 2535 | |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 2536 | if (node->type == XML_TEXT_NODE) return(1); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2537 | return(0); |
| 2538 | } |
| 2539 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2540 | /** |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2541 | * xmlTextConcat: |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2542 | * @node: the node |
| 2543 | * @content: the content |
| 2544 | * @len: @content lenght |
| 2545 | * |
| 2546 | * Concat the given string at the end of the existing node content |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2547 | */ |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2548 | |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2549 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2550 | xmlTextConcat(xmlNodePtr node, const xmlChar *content, int len) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2551 | if (node == NULL) return; |
| 2552 | |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 2553 | if (node->type != XML_TEXT_NODE) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2554 | fprintf(stderr, "xmlTextConcat: node is not text\n"); |
| 2555 | return; |
| 2556 | } |
| 2557 | node->content = xmlStrncat(node->content, content, len); |
| 2558 | } |
| 2559 | |
| 2560 | /************************************************************************ |
| 2561 | * * |
| 2562 | * Output : to a FILE or in memory * |
| 2563 | * * |
| 2564 | ************************************************************************/ |
| 2565 | |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2566 | #define BASE_BUFFER_SIZE 4000 |
| 2567 | |
| 2568 | /** |
| 2569 | * xmlBufferCreate: |
| 2570 | * |
| 2571 | * routine to create an XML buffer. |
| 2572 | * returns the new structure. |
| 2573 | */ |
| 2574 | xmlBufferPtr |
| 2575 | xmlBufferCreate(void) { |
| 2576 | xmlBufferPtr ret; |
| 2577 | |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2578 | ret = (xmlBufferPtr) xmlMalloc(sizeof(xmlBuffer)); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2579 | if (ret == NULL) { |
| 2580 | fprintf(stderr, "xmlBufferCreate : out of memory!\n"); |
| 2581 | return(NULL); |
| 2582 | } |
| 2583 | ret->use = 0; |
| 2584 | ret->size = BASE_BUFFER_SIZE; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2585 | ret->content = (xmlChar *) xmlMalloc(ret->size * sizeof(xmlChar)); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2586 | if (ret->content == NULL) { |
| 2587 | fprintf(stderr, "xmlBufferCreate : out of memory!\n"); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2588 | xmlFree(ret); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2589 | return(NULL); |
| 2590 | } |
| 2591 | ret->content[0] = 0; |
| 2592 | return(ret); |
| 2593 | } |
| 2594 | |
| 2595 | /** |
| 2596 | * xmlBufferFree: |
| 2597 | * @buf: the buffer to free |
| 2598 | * |
| 2599 | * Frees an XML buffer. |
| 2600 | */ |
| 2601 | void |
| 2602 | xmlBufferFree(xmlBufferPtr buf) { |
| 2603 | if (buf == NULL) { |
| 2604 | fprintf(stderr, "xmlBufferFree: buf == NULL\n"); |
| 2605 | return; |
| 2606 | } |
| 2607 | if (buf->content == NULL) { |
| 2608 | fprintf(stderr, "xmlBufferFree: buf->content == NULL\n"); |
| 2609 | } else { |
| 2610 | memset(buf->content, -1, BASE_BUFFER_SIZE); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2611 | xmlFree(buf->content); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2612 | } |
| 2613 | memset(buf, -1, sizeof(xmlBuffer)); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2614 | xmlFree(buf); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2615 | } |
| 2616 | |
| 2617 | /** |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2618 | * xmlBufferEmpty: |
| 2619 | * @buf: the buffer |
| 2620 | * |
| 2621 | * empty a buffer. |
| 2622 | */ |
| 2623 | void |
| 2624 | xmlBufferEmpty(xmlBufferPtr buf) { |
| 2625 | buf->use = 0; |
| 2626 | memset(buf->content, -1, buf->size);/* just for debug */ |
| 2627 | } |
| 2628 | |
| 2629 | /** |
| 2630 | * xmlBufferShrink: |
| 2631 | * @buf: the buffer to dump |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2632 | * @len: the number of xmlChar to remove |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2633 | * |
| 2634 | * Remove the beginning of an XML buffer. |
| 2635 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2636 | * Returns the number of xmlChar removed, or -1 in case of failure. |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2637 | */ |
| 2638 | int |
| 2639 | xmlBufferShrink(xmlBufferPtr buf, int len) { |
| 2640 | if (len == 0) return(0); |
| 2641 | if (len > buf->use) return(-1); |
| 2642 | |
| 2643 | buf->use -= len; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2644 | memmove(buf->content, &buf->content[len], buf->use * sizeof(xmlChar)); |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2645 | |
| 2646 | buf->content[buf->use] = 0; |
| 2647 | return(len); |
| 2648 | } |
| 2649 | |
| 2650 | /** |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2651 | * xmlBufferDump: |
| 2652 | * @file: the file output |
| 2653 | * @buf: the buffer to dump |
| 2654 | * |
| 2655 | * Dumps an XML buffer to a FILE *. |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2656 | * Returns the number of xmlChar written |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2657 | */ |
| 2658 | int |
| 2659 | xmlBufferDump(FILE *file, xmlBufferPtr buf) { |
| 2660 | int ret; |
| 2661 | |
| 2662 | if (buf == NULL) { |
| 2663 | fprintf(stderr, "xmlBufferDump: buf == NULL\n"); |
| 2664 | return(0); |
| 2665 | } |
| 2666 | if (buf->content == NULL) { |
| 2667 | fprintf(stderr, "xmlBufferDump: buf->content == NULL\n"); |
| 2668 | return(0); |
| 2669 | } |
| 2670 | if (file == NULL) file = stdout; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2671 | ret = fwrite(buf->content, sizeof(xmlChar), buf->use, file); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2672 | return(ret); |
| 2673 | } |
| 2674 | |
| 2675 | /** |
| 2676 | * xmlBufferAdd: |
| 2677 | * @buf: the buffer to dump |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2678 | * @str: the xmlChar string |
| 2679 | * @len: the number of xmlChar to add |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2680 | * |
| 2681 | * Add a string range to an XML buffer. |
| 2682 | */ |
| 2683 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2684 | xmlBufferAdd(xmlBufferPtr buf, const xmlChar *str, int len) { |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2685 | int l; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2686 | |
| 2687 | if (str == NULL) { |
| 2688 | fprintf(stderr, "xmlBufferAdd: str == NULL\n"); |
| 2689 | return; |
| 2690 | } |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2691 | l = xmlStrlen(str); |
| 2692 | if (l < len) len = l; |
| 2693 | if (len <= 0) return; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2694 | |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2695 | if (buf->use + len + 10 >= buf->size) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2696 | xmlChar *rebuf; |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2697 | |
| 2698 | buf->size *= 2; |
| 2699 | if (buf->use + len + 10 > buf->size) |
| 2700 | buf->size = buf->use + len + 10; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2701 | rebuf = (xmlChar *) xmlRealloc(buf->content, buf->size * sizeof(xmlChar)); |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2702 | if (rebuf == NULL) { |
| 2703 | fprintf(stderr, "xmlBufferAdd : out of memory!\n"); |
| 2704 | return; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2705 | } |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2706 | buf->content = rebuf; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2707 | } |
Daniel Veillard | e2d034d | 1999-07-27 19:52:06 +0000 | [diff] [blame] | 2708 | memmove(&buf->content[buf->use], str, len); |
| 2709 | buf->use += len; |
| 2710 | buf->content[buf->use] = 0; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2711 | } |
| 2712 | |
| 2713 | /** |
| 2714 | * xmlBufferCat: |
| 2715 | * @buf: the buffer to dump |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2716 | * @str: the xmlChar string |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2717 | * |
| 2718 | * Append a zero terminated string to an XML buffer. |
| 2719 | */ |
| 2720 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2721 | xmlBufferCat(xmlBufferPtr buf, const xmlChar *str) { |
| 2722 | const xmlChar *cur; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2723 | |
| 2724 | if (str == NULL) { |
| 2725 | fprintf(stderr, "xmlBufferAdd: str == NULL\n"); |
| 2726 | return; |
| 2727 | } |
| 2728 | for (cur = str;*cur != 0;cur++) { |
| 2729 | if (buf->use + 10 >= buf->size) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2730 | xmlChar *rebuf; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2731 | |
| 2732 | buf->size *= 2; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2733 | rebuf = (xmlChar *) xmlRealloc(buf->content, buf->size * sizeof(xmlChar)); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2734 | if (rebuf == NULL) { |
| 2735 | fprintf(stderr, "xmlBufferAdd : out of memory!\n"); |
| 2736 | return; |
| 2737 | } |
| 2738 | buf->content = rebuf; |
| 2739 | } |
| 2740 | buf->content[buf->use++] = *cur; |
| 2741 | } |
| 2742 | } |
| 2743 | |
| 2744 | /** |
| 2745 | * xmlBufferCCat: |
| 2746 | * @buf: the buffer to dump |
| 2747 | * @str: the C char string |
| 2748 | * |
| 2749 | * Append a zero terminated C string to an XML buffer. |
| 2750 | */ |
| 2751 | void |
| 2752 | xmlBufferCCat(xmlBufferPtr buf, const char *str) { |
| 2753 | const char *cur; |
| 2754 | |
| 2755 | if (str == NULL) { |
| 2756 | fprintf(stderr, "xmlBufferAdd: str == NULL\n"); |
| 2757 | return; |
| 2758 | } |
| 2759 | for (cur = str;*cur != 0;cur++) { |
| 2760 | if (buf->use + 10 >= buf->size) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2761 | xmlChar *rebuf; |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2762 | |
| 2763 | buf->size *= 2; |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2764 | rebuf = (xmlChar *) xmlRealloc(buf->content, buf->size * sizeof(xmlChar)); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2765 | if (rebuf == NULL) { |
| 2766 | fprintf(stderr, "xmlBufferAdd : out of memory!\n"); |
| 2767 | return; |
| 2768 | } |
| 2769 | buf->content = rebuf; |
| 2770 | } |
| 2771 | buf->content[buf->use++] = *cur; |
| 2772 | } |
| 2773 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2774 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2775 | /** |
Daniel Veillard | 7d2c276 | 1999-10-11 15:09:51 +0000 | [diff] [blame] | 2776 | * xmlBufferLastChar: |
| 2777 | * @buf: the buffer to dump |
| 2778 | * |
| 2779 | * Get the last char of the buffer |
| 2780 | * |
| 2781 | * Returns the last char from the buffer or 0 if empty |
| 2782 | */ |
| 2783 | xmlChar |
| 2784 | xmlBufferLastChar(xmlBufferPtr buf) { |
| 2785 | if ((buf == NULL) || (buf->use <= 0)) return(0); |
| 2786 | return(buf->content[buf->use - 1]); |
| 2787 | } |
| 2788 | |
| 2789 | /** |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2790 | * xmlBufferWriteCHAR: |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2791 | * @buf: the XML buffer |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2792 | * @string: the string to add |
| 2793 | * |
| 2794 | * routine which manage and grows an output buffer. This one add |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2795 | * xmlChars at the end of the buffer. |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2796 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2797 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2798 | xmlBufferWriteCHAR(xmlBufferPtr buf, const xmlChar *string) { |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2799 | xmlBufferCat(buf, string); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2800 | } |
| 2801 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2802 | /** |
| 2803 | * xmlBufferWriteChar: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2804 | * @buf: the XML buffer output |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2805 | * @string: the string to add |
| 2806 | * |
| 2807 | * routine which manage and grows an output buffer. This one add |
| 2808 | * C chars at the end of the array. |
| 2809 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2810 | void |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2811 | xmlBufferWriteChar(xmlBufferPtr buf, const char *string) { |
| 2812 | xmlBufferCCat(buf, string); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2813 | } |
| 2814 | |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2815 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2816 | /** |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2817 | * xmlBufferWriteQuotedString: |
| 2818 | * @buf: the XML buffer output |
| 2819 | * @string: the string to add |
| 2820 | * |
| 2821 | * routine which manage and grows an output buffer. This one writes |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2822 | * a quoted or double quoted xmlChar string, checking first if it holds |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2823 | * quote or double-quotes internally |
| 2824 | */ |
| 2825 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2826 | xmlBufferWriteQuotedString(xmlBufferPtr buf, const xmlChar *string) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2827 | if (xmlStrchr(string, '"')) { |
| 2828 | if (xmlStrchr(string, '\'')) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2829 | fprintf(stderr, |
| 2830 | "xmlBufferWriteQuotedString: string contains quote and double-quotes !\n"); |
| 2831 | } |
| 2832 | xmlBufferCCat(buf, "'"); |
| 2833 | xmlBufferCat(buf, string); |
| 2834 | xmlBufferCCat(buf, "'"); |
| 2835 | } else { |
| 2836 | xmlBufferCCat(buf, "\""); |
| 2837 | xmlBufferCat(buf, string); |
| 2838 | xmlBufferCCat(buf, "\""); |
| 2839 | } |
| 2840 | } |
| 2841 | |
| 2842 | |
| 2843 | /** |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2844 | * xmlGlobalNsDump: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2845 | * @buf: the XML buffer output |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2846 | * @cur: a namespace |
| 2847 | * |
| 2848 | * Dump a global Namespace, this is the old version based on PIs. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2849 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2850 | static void |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2851 | xmlGlobalNsDump(xmlBufferPtr buf, xmlNsPtr cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2852 | if (cur == NULL) { |
| 2853 | fprintf(stderr, "xmlGlobalNsDump : Ns == NULL\n"); |
| 2854 | return; |
| 2855 | } |
| 2856 | if (cur->type == XML_GLOBAL_NAMESPACE) { |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2857 | xmlBufferWriteChar(buf, "<?namespace"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2858 | if (cur->href != NULL) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2859 | xmlBufferWriteChar(buf, " href="); |
| 2860 | xmlBufferWriteQuotedString(buf, cur->href); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2861 | } |
| 2862 | if (cur->prefix != NULL) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2863 | xmlBufferWriteChar(buf, " AS="); |
| 2864 | xmlBufferWriteQuotedString(buf, cur->prefix); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2865 | } |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2866 | xmlBufferWriteChar(buf, "?>\n"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2867 | } |
| 2868 | } |
| 2869 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2870 | /** |
| 2871 | * xmlGlobalNsListDump: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2872 | * @buf: the XML buffer output |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2873 | * @cur: the first namespace |
| 2874 | * |
| 2875 | * Dump a list of global Namespace, this is the old version based on PIs. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2876 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2877 | static void |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2878 | xmlGlobalNsListDump(xmlBufferPtr buf, xmlNsPtr cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2879 | while (cur != NULL) { |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2880 | xmlGlobalNsDump(buf, cur); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2881 | cur = cur->next; |
| 2882 | } |
| 2883 | } |
| 2884 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2885 | /** |
| 2886 | * xmlNsDump: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2887 | * @buf: the XML buffer output |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2888 | * @cur: a namespace |
| 2889 | * |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2890 | * Dump a local Namespace definition. |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2891 | * Should be called in the context of attributes dumps. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2892 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2893 | static void |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2894 | xmlNsDump(xmlBufferPtr buf, xmlNsPtr cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2895 | if (cur == NULL) { |
| 2896 | fprintf(stderr, "xmlNsDump : Ns == NULL\n"); |
| 2897 | return; |
| 2898 | } |
| 2899 | if (cur->type == XML_LOCAL_NAMESPACE) { |
| 2900 | /* Within the context of an element attributes */ |
| 2901 | if (cur->prefix != NULL) { |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2902 | xmlBufferWriteChar(buf, " xmlns:"); |
| 2903 | xmlBufferWriteCHAR(buf, cur->prefix); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2904 | } else |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2905 | xmlBufferWriteChar(buf, " xmlns"); |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2906 | xmlBufferWriteChar(buf, "="); |
| 2907 | xmlBufferWriteQuotedString(buf, cur->href); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2908 | } |
| 2909 | } |
| 2910 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2911 | /** |
| 2912 | * xmlNsListDump: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2913 | * @buf: the XML buffer output |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2914 | * @cur: the first namespace |
| 2915 | * |
| 2916 | * Dump a list of local Namespace definitions. |
| 2917 | * Should be called in the context of attributes dumps. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2918 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2919 | static void |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2920 | xmlNsListDump(xmlBufferPtr buf, xmlNsPtr cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2921 | while (cur != NULL) { |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2922 | xmlNsDump(buf, cur); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2923 | cur = cur->next; |
| 2924 | } |
| 2925 | } |
| 2926 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2927 | /** |
| 2928 | * xmlDtdDump: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2929 | * @buf: the XML buffer output |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2930 | * @doc: the document |
| 2931 | * |
| 2932 | * Dump the XML document DTD, if any. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2933 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2934 | static void |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2935 | xmlDtdDump(xmlBufferPtr buf, xmlDocPtr doc) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2936 | xmlDtdPtr cur = doc->intSubset; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2937 | |
| 2938 | if (cur == NULL) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 2939 | fprintf(stderr, "xmlDtdDump : no internal subset\n"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2940 | return; |
| 2941 | } |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2942 | xmlBufferWriteChar(buf, "<!DOCTYPE "); |
| 2943 | xmlBufferWriteCHAR(buf, cur->name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2944 | if (cur->ExternalID != NULL) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2945 | xmlBufferWriteChar(buf, " PUBLIC "); |
| 2946 | xmlBufferWriteQuotedString(buf, cur->ExternalID); |
| 2947 | xmlBufferWriteChar(buf, " "); |
| 2948 | xmlBufferWriteQuotedString(buf, cur->SystemID); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2949 | } else if (cur->SystemID != NULL) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2950 | xmlBufferWriteChar(buf, " SYSTEM "); |
| 2951 | xmlBufferWriteQuotedString(buf, cur->SystemID); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2952 | } |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2953 | if ((cur->entities == NULL) && (cur->elements == NULL) && |
| 2954 | (cur->attributes == NULL) && (cur->notations == NULL)) { |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2955 | xmlBufferWriteChar(buf, ">\n"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2956 | return; |
| 2957 | } |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2958 | xmlBufferWriteChar(buf, " [\n"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2959 | if (cur->entities != NULL) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2960 | xmlDumpEntitiesTable(buf, (xmlEntitiesTablePtr) cur->entities); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2961 | if (cur->notations != NULL) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2962 | xmlDumpNotationTable(buf, (xmlNotationTablePtr) cur->notations); |
Daniel Veillard | 3b9def1 | 1999-01-31 22:15:06 +0000 | [diff] [blame] | 2963 | if (cur->elements != NULL) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2964 | xmlDumpElementTable(buf, (xmlElementTablePtr) cur->elements); |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 2965 | if (cur->attributes != NULL) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2966 | xmlDumpAttributeTable(buf, (xmlAttributeTablePtr) cur->attributes); |
| 2967 | xmlBufferWriteChar(buf, "]"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2968 | |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2969 | xmlBufferWriteChar(buf, ">\n"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2970 | } |
| 2971 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2972 | /** |
| 2973 | * xmlAttrDump: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2974 | * @buf: the XML buffer output |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 2975 | * @doc: the document |
| 2976 | * @cur: the attribute pointer |
| 2977 | * |
| 2978 | * Dump an XML attribute |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2979 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 2980 | static void |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2981 | xmlAttrDump(xmlBufferPtr buf, xmlDocPtr doc, xmlAttrPtr cur) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 2982 | xmlChar *value; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 2983 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 2984 | if (cur == NULL) { |
| 2985 | fprintf(stderr, "xmlAttrDump : property == NULL\n"); |
| 2986 | return; |
| 2987 | } |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2988 | xmlBufferWriteChar(buf, " "); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 2989 | if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { |
| 2990 | xmlBufferWriteCHAR(buf, cur->ns->prefix); |
| 2991 | xmlBufferWriteChar(buf, ":"); |
| 2992 | } |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 2993 | xmlBufferWriteCHAR(buf, cur->name); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 2994 | value = xmlNodeListGetString(doc, cur->val, 0); |
| 2995 | if (value) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 2996 | xmlBufferWriteChar(buf, "="); |
| 2997 | xmlBufferWriteQuotedString(buf, value); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 2998 | xmlFree(value); |
Daniel Veillard | 726c7e3 | 1999-02-08 15:13:10 +0000 | [diff] [blame] | 2999 | } else { |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3000 | xmlBufferWriteChar(buf, "=\"\""); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3001 | } |
| 3002 | } |
| 3003 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3004 | /** |
| 3005 | * xmlAttrListDump: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 3006 | * @buf: the XML buffer output |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3007 | * @doc: the document |
| 3008 | * @cur: the first attribute pointer |
| 3009 | * |
| 3010 | * Dump a list of XML attributes |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3011 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 3012 | static void |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3013 | xmlAttrListDump(xmlBufferPtr buf, xmlDocPtr doc, xmlAttrPtr cur) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3014 | if (cur == NULL) { |
| 3015 | fprintf(stderr, "xmlAttrListDump : property == NULL\n"); |
| 3016 | return; |
| 3017 | } |
| 3018 | while (cur != NULL) { |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3019 | xmlAttrDump(buf, doc, cur); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3020 | cur = cur->next; |
| 3021 | } |
| 3022 | } |
| 3023 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3024 | |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 3025 | static void |
Daniel Veillard | 7d2c276 | 1999-10-11 15:09:51 +0000 | [diff] [blame] | 3026 | xmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level, |
| 3027 | int format); |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3028 | /** |
| 3029 | * xmlNodeListDump: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 3030 | * @buf: the XML buffer output |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3031 | * @doc: the document |
| 3032 | * @cur: the first node |
| 3033 | * @level: the imbrication level for indenting |
Daniel Veillard | 7d2c276 | 1999-10-11 15:09:51 +0000 | [diff] [blame] | 3034 | * @format: is formatting allowed |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3035 | * |
| 3036 | * Dump an XML node list, recursive behaviour,children are printed too. |
| 3037 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 3038 | static void |
Daniel Veillard | 7d2c276 | 1999-10-11 15:09:51 +0000 | [diff] [blame] | 3039 | xmlNodeListDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level, |
| 3040 | int format) { |
| 3041 | int i; |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 3042 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3043 | if (cur == NULL) { |
| 3044 | fprintf(stderr, "xmlNodeListDump : node == NULL\n"); |
| 3045 | return; |
| 3046 | } |
| 3047 | while (cur != NULL) { |
Daniel Veillard | 7d2c276 | 1999-10-11 15:09:51 +0000 | [diff] [blame] | 3048 | if ((format) && (xmlIndentTreeOutput) && |
| 3049 | (cur->type == XML_ELEMENT_NODE)) |
| 3050 | for (i = 0;i < level;i++) |
| 3051 | xmlBufferWriteChar(buf, " "); |
| 3052 | xmlNodeDump(buf, doc, cur, level, format); |
| 3053 | if (format) { |
| 3054 | xmlBufferWriteChar(buf, "\n"); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 3055 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3056 | cur = cur->next; |
| 3057 | } |
| 3058 | } |
| 3059 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3060 | /** |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 3061 | * xmlNodeDump: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 3062 | * @buf: the XML buffer output |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3063 | * @doc: the document |
| 3064 | * @cur: the current node |
| 3065 | * @level: the imbrication level for indenting |
Daniel Veillard | 7d2c276 | 1999-10-11 15:09:51 +0000 | [diff] [blame] | 3066 | * @format: is formatting allowed |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3067 | * |
| 3068 | * Dump an XML node, recursive behaviour,children are printed too. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3069 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 3070 | static void |
Daniel Veillard | 7d2c276 | 1999-10-11 15:09:51 +0000 | [diff] [blame] | 3071 | xmlNodeDump(xmlBufferPtr buf, xmlDocPtr doc, xmlNodePtr cur, int level, |
| 3072 | int format) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3073 | int i; |
Daniel Veillard | 7d2c276 | 1999-10-11 15:09:51 +0000 | [diff] [blame] | 3074 | xmlNodePtr tmp; |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3075 | |
| 3076 | if (cur == NULL) { |
| 3077 | fprintf(stderr, "xmlNodeDump : node == NULL\n"); |
| 3078 | return; |
| 3079 | } |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 3080 | if (cur->type == XML_TEXT_NODE) { |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 3081 | if (cur->content != NULL) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3082 | xmlChar *buffer; |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 3083 | |
| 3084 | buffer = xmlEncodeEntitiesReentrant(doc, cur->content); |
| 3085 | if (buffer != NULL) { |
| 3086 | xmlBufferWriteCHAR(buf, buffer); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3087 | xmlFree(buffer); |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 3088 | } |
| 3089 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3090 | return; |
| 3091 | } |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3092 | if (cur->type == XML_PI_NODE) { |
| 3093 | if (cur->content != NULL) { |
| 3094 | xmlBufferWriteChar(buf, "<?"); |
| 3095 | xmlBufferWriteCHAR(buf, cur->name); |
| 3096 | if (cur->content != NULL) { |
| 3097 | xmlBufferWriteChar(buf, " "); |
| 3098 | xmlBufferWriteCHAR(buf, cur->content); |
| 3099 | } |
Daniel Veillard | 7d2c276 | 1999-10-11 15:09:51 +0000 | [diff] [blame] | 3100 | xmlBufferWriteChar(buf, "?>"); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3101 | } |
| 3102 | return; |
| 3103 | } |
Daniel Veillard | 0bef131 | 1998-10-14 02:36:47 +0000 | [diff] [blame] | 3104 | if (cur->type == XML_COMMENT_NODE) { |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3105 | if (cur->content != NULL) { |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3106 | xmlBufferWriteChar(buf, "<!--"); |
| 3107 | xmlBufferWriteCHAR(buf, cur->content); |
Daniel Veillard | 7d2c276 | 1999-10-11 15:09:51 +0000 | [diff] [blame] | 3108 | xmlBufferWriteChar(buf, "-->"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3109 | } |
| 3110 | return; |
| 3111 | } |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 3112 | if (cur->type == XML_ENTITY_REF_NODE) { |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3113 | xmlBufferWriteChar(buf, "&"); |
| 3114 | xmlBufferWriteCHAR(buf, cur->name); |
| 3115 | xmlBufferWriteChar(buf, ";"); |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 3116 | return; |
| 3117 | } |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3118 | if (cur->type == XML_CDATA_SECTION_NODE) { |
| 3119 | xmlBufferWriteChar(buf, "<![CDATA["); |
| 3120 | if (cur->content != NULL) |
| 3121 | xmlBufferWriteCHAR(buf, cur->content); |
| 3122 | xmlBufferWriteChar(buf, "]]>"); |
| 3123 | return; |
| 3124 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3125 | |
Daniel Veillard | 7d2c276 | 1999-10-11 15:09:51 +0000 | [diff] [blame] | 3126 | if (format == 1) { |
| 3127 | tmp = cur->childs; |
| 3128 | while (tmp != NULL) { |
| 3129 | if ((tmp->type == XML_TEXT_NODE) || |
| 3130 | (tmp->type == XML_ENTITY_REF_NODE)) { |
| 3131 | format = 0; |
| 3132 | break; |
| 3133 | } |
| 3134 | tmp = tmp->next; |
| 3135 | } |
| 3136 | } |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3137 | xmlBufferWriteChar(buf, "<"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3138 | if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3139 | xmlBufferWriteCHAR(buf, cur->ns->prefix); |
| 3140 | xmlBufferWriteChar(buf, ":"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3141 | } |
| 3142 | |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3143 | xmlBufferWriteCHAR(buf, cur->name); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3144 | if (cur->nsDef) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3145 | xmlNsListDump(buf, cur->nsDef); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3146 | if (cur->properties != NULL) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3147 | xmlAttrListDump(buf, doc, cur->properties); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3148 | |
| 3149 | if ((cur->content == NULL) && (cur->childs == NULL)) { |
Daniel Veillard | 7d2c276 | 1999-10-11 15:09:51 +0000 | [diff] [blame] | 3150 | xmlBufferWriteChar(buf, "/>"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3151 | return; |
| 3152 | } |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3153 | xmlBufferWriteChar(buf, ">"); |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 3154 | if (cur->content != NULL) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3155 | xmlChar *buffer; |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 3156 | |
| 3157 | buffer = xmlEncodeEntitiesReentrant(doc, cur->content); |
| 3158 | if (buffer != NULL) { |
| 3159 | xmlBufferWriteCHAR(buf, buffer); |
Daniel Veillard | 6454aec | 1999-09-02 22:04:43 +0000 | [diff] [blame] | 3160 | xmlFree(buffer); |
Daniel Veillard | 14fff06 | 1999-06-22 21:49:07 +0000 | [diff] [blame] | 3161 | } |
| 3162 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3163 | if (cur->childs != NULL) { |
Daniel Veillard | 7d2c276 | 1999-10-11 15:09:51 +0000 | [diff] [blame] | 3164 | if (format) xmlBufferWriteChar(buf, "\n"); |
| 3165 | xmlNodeListDump(buf, doc, cur->childs, level + 1, format); |
| 3166 | if ((xmlIndentTreeOutput) && (format)) |
| 3167 | for (i = 0;i < level;i++) |
| 3168 | xmlBufferWriteChar(buf, " "); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3169 | } |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3170 | xmlBufferWriteChar(buf, "</"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3171 | if ((cur->ns != NULL) && (cur->ns->prefix != NULL)) { |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3172 | xmlBufferWriteCHAR(buf, cur->ns->prefix); |
| 3173 | xmlBufferWriteChar(buf, ":"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3174 | } |
| 3175 | |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3176 | xmlBufferWriteCHAR(buf, cur->name); |
Daniel Veillard | 7d2c276 | 1999-10-11 15:09:51 +0000 | [diff] [blame] | 3177 | xmlBufferWriteChar(buf, ">"); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3178 | } |
| 3179 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3180 | /** |
| 3181 | * xmlDocContentDump: |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 3182 | * @buf: the XML buffer output |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3183 | * @cur: the document |
| 3184 | * |
| 3185 | * Dump an XML document. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3186 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 3187 | static void |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3188 | xmlDocContentDump(xmlBufferPtr buf, xmlDocPtr cur) { |
Daniel Veillard | be70ff7 | 1999-07-05 16:50:46 +0000 | [diff] [blame] | 3189 | xmlBufferWriteChar(buf, "<?xml version="); |
| 3190 | if (cur->version != NULL) |
| 3191 | xmlBufferWriteQuotedString(buf, cur->version); |
| 3192 | else |
| 3193 | xmlBufferWriteChar(buf, "\"1.0\""); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3194 | if (cur->encoding != NULL) { |
Daniel Veillard | 011b63c | 1999-06-02 17:44:04 +0000 | [diff] [blame] | 3195 | xmlBufferWriteChar(buf, " encoding="); |
| 3196 | xmlBufferWriteQuotedString(buf, cur->encoding); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3197 | } |
| 3198 | switch (cur->standalone) { |
| 3199 | case 0: |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3200 | xmlBufferWriteChar(buf, " standalone=\"no\""); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3201 | break; |
| 3202 | case 1: |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3203 | xmlBufferWriteChar(buf, " standalone=\"yes\""); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3204 | break; |
| 3205 | } |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3206 | xmlBufferWriteChar(buf, "?>\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3207 | if (cur->intSubset != NULL) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3208 | xmlDtdDump(buf, cur); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3209 | if (cur->root != NULL) { |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3210 | xmlNodePtr child = cur->root; |
| 3211 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3212 | /* global namespace definitions, the old way */ |
| 3213 | if (oldXMLWDcompatibility) |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3214 | xmlGlobalNsListDump(buf, cur->oldNs); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3215 | else |
| 3216 | xmlUpgradeOldNs(cur); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3217 | |
| 3218 | while (child != NULL) { |
Daniel Veillard | 7d2c276 | 1999-10-11 15:09:51 +0000 | [diff] [blame] | 3219 | xmlNodeDump(buf, cur, child, 0, 1); |
| 3220 | xmlBufferWriteChar(buf, "\n"); |
Daniel Veillard | b96e643 | 1999-08-29 21:02:19 +0000 | [diff] [blame] | 3221 | child = child->next; |
| 3222 | } |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3223 | } |
| 3224 | } |
| 3225 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3226 | /** |
| 3227 | * xmlDocDumpMemory: |
| 3228 | * @cur: the document |
| 3229 | * @mem: OUT: the memory pointer |
| 3230 | * @size: OUT: the memory lenght |
| 3231 | * |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3232 | * Dump an XML document in memory and return the xmlChar * and it's size. |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3233 | * It's up to the caller to free the memory. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3234 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 3235 | void |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3236 | xmlDocDumpMemory(xmlDocPtr cur, xmlChar**mem, int *size) { |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3237 | xmlBufferPtr buf; |
| 3238 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3239 | if (cur == NULL) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3240 | #ifdef DEBUG_TREE |
| 3241 | fprintf(stderr, "xmlDocDumpMemory : document == NULL\n"); |
| 3242 | #endif |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3243 | *mem = NULL; |
| 3244 | *size = 0; |
| 3245 | return; |
| 3246 | } |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3247 | buf = xmlBufferCreate(); |
| 3248 | if (buf == NULL) { |
| 3249 | *mem = NULL; |
| 3250 | *size = 0; |
| 3251 | return; |
| 3252 | } |
| 3253 | xmlDocContentDump(buf, cur); |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3254 | *mem = xmlStrndup(buf->content, buf->use); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3255 | *size = buf->use; |
Daniel Veillard | b05deb7 | 1999-08-10 19:04:08 +0000 | [diff] [blame] | 3256 | xmlBufferFree(buf); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3257 | } |
| 3258 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3259 | /** |
| 3260 | * xmlGetDocCompressMode: |
| 3261 | * @doc: the document |
| 3262 | * |
| 3263 | * get the compression ratio for a document, ZLIB based |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3264 | * Returns 0 (uncompressed) to 9 (max compression) |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 3265 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 3266 | int |
| 3267 | xmlGetDocCompressMode (xmlDocPtr doc) { |
Daniel Veillard | 15a8df4 | 1998-09-24 19:15:06 +0000 | [diff] [blame] | 3268 | if (doc == NULL) return(-1); |
| 3269 | return(doc->compression); |
| 3270 | } |
| 3271 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3272 | /** |
| 3273 | * xmlSetDocCompressMode: |
| 3274 | * @doc: the document |
| 3275 | * @mode: the compression ratio |
| 3276 | * |
| 3277 | * set the compression ratio for a document, ZLIB based |
| 3278 | * Correct values: 0 (uncompressed) to 9 (max compression) |
| 3279 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 3280 | void |
| 3281 | xmlSetDocCompressMode (xmlDocPtr doc, int mode) { |
Daniel Veillard | 15a8df4 | 1998-09-24 19:15:06 +0000 | [diff] [blame] | 3282 | if (doc == NULL) return; |
| 3283 | if (mode < 0) doc->compression = 0; |
| 3284 | else if (mode > 9) doc->compression = 9; |
| 3285 | else doc->compression = mode; |
| 3286 | } |
| 3287 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3288 | /** |
| 3289 | * xmlGetCompressMode: |
| 3290 | * |
| 3291 | * get the default compression mode used, ZLIB based. |
Daniel Veillard | 1e346af | 1999-02-22 10:33:01 +0000 | [diff] [blame] | 3292 | * Returns 0 (uncompressed) to 9 (max compression) |
Daniel Veillard | 15a8df4 | 1998-09-24 19:15:06 +0000 | [diff] [blame] | 3293 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 3294 | int |
| 3295 | xmlGetCompressMode(void) { |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 3296 | return(xmlCompressMode); |
| 3297 | } |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3298 | |
| 3299 | /** |
| 3300 | * xmlSetCompressMode: |
| 3301 | * @mode: the compression ratio |
| 3302 | * |
| 3303 | * set the default compression mode used, ZLIB based |
| 3304 | * Correct values: 0 (uncompressed) to 9 (max compression) |
| 3305 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 3306 | void |
| 3307 | xmlSetCompressMode(int mode) { |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 3308 | if (mode < 0) xmlCompressMode = 0; |
Daniel Veillard | 15a8df4 | 1998-09-24 19:15:06 +0000 | [diff] [blame] | 3309 | else if (mode > 9) xmlCompressMode = 9; |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 3310 | else xmlCompressMode = mode; |
| 3311 | } |
| 3312 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3313 | /** |
| 3314 | * xmlDocDump: |
| 3315 | * @f: the FILE* |
| 3316 | * @cur: the document |
| 3317 | * |
| 3318 | * Dump an XML document to an open FILE. |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3319 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 3320 | void |
| 3321 | xmlDocDump(FILE *f, xmlDocPtr cur) { |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3322 | xmlBufferPtr buf; |
| 3323 | |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3324 | if (cur == NULL) { |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3325 | #ifdef DEBUG_TREE |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3326 | fprintf(stderr, "xmlDocDump : document == NULL\n"); |
Daniel Veillard | 39a1f9a | 1999-01-17 19:11:59 +0000 | [diff] [blame] | 3327 | #endif |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3328 | return; |
| 3329 | } |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3330 | buf = xmlBufferCreate(); |
| 3331 | if (buf == NULL) return; |
| 3332 | xmlDocContentDump(buf, cur); |
| 3333 | xmlBufferDump(f, buf); |
| 3334 | xmlBufferFree(buf); |
Daniel Veillard | 260a68f | 1998-08-13 03:39:55 +0000 | [diff] [blame] | 3335 | } |
| 3336 | |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3337 | /** |
| 3338 | * xmlSaveFile: |
| 3339 | * @filename: the filename |
| 3340 | * @cur: the document |
| 3341 | * |
| 3342 | * Dump an XML document to a file. Will use compression if |
Daniel Veillard | 11a48ec | 1999-11-23 10:40:46 +0000 | [diff] [blame] | 3343 | * compiled in and enabled. If @filename is "-" the stdout file is |
| 3344 | * used. |
Daniel Veillard | 97b5877 | 1998-10-20 06:14:16 +0000 | [diff] [blame] | 3345 | * returns: the number of file written or -1 in case of failure. |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 3346 | */ |
Daniel Veillard | baf4cd5 | 1998-10-27 22:56:57 +0000 | [diff] [blame] | 3347 | int |
| 3348 | xmlSaveFile(const char *filename, xmlDocPtr cur) { |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3349 | xmlBufferPtr buf; |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 3350 | #ifdef HAVE_ZLIB_H |
| 3351 | gzFile zoutput = NULL; |
| 3352 | char mode[15]; |
| 3353 | #endif |
Daniel Veillard | ccb0963 | 1998-10-27 06:21:04 +0000 | [diff] [blame] | 3354 | FILE *output = NULL; |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 3355 | int ret; |
| 3356 | |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3357 | /* |
| 3358 | * save the content to a temp buffer. |
| 3359 | */ |
| 3360 | buf = xmlBufferCreate(); |
| 3361 | if (buf == NULL) return(0); |
| 3362 | xmlDocContentDump(buf, cur); |
| 3363 | |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 3364 | #ifdef HAVE_ZLIB_H |
Daniel Veillard | 11a48ec | 1999-11-23 10:40:46 +0000 | [diff] [blame] | 3365 | if (cur->compression < 0) cur->compression = xmlCompressMode; |
Daniel Veillard | dc3dd9d | 1998-09-24 19:25:54 +0000 | [diff] [blame] | 3366 | if ((cur->compression > 0) && (cur->compression <= 9)) { |
| 3367 | sprintf(mode, "w%d", cur->compression); |
Daniel Veillard | 11a48ec | 1999-11-23 10:40:46 +0000 | [diff] [blame] | 3368 | if (!strcmp(filename, "-")) |
| 3369 | zoutput = gzdopen(1, mode); |
| 3370 | else |
| 3371 | zoutput = gzopen(filename, mode); |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 3372 | } |
| 3373 | if (zoutput == NULL) { |
| 3374 | #endif |
| 3375 | output = fopen(filename, "w"); |
| 3376 | if (output == NULL) return(-1); |
| 3377 | #ifdef HAVE_ZLIB_H |
| 3378 | } |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 3379 | |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 3380 | if (zoutput != NULL) { |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3381 | ret = gzwrite(zoutput, buf->content, sizeof(xmlChar) * buf->use); |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 3382 | gzclose(zoutput); |
Daniel Veillard | 5099ae8 | 1999-04-21 20:12:07 +0000 | [diff] [blame] | 3383 | } else { |
| 3384 | #endif |
| 3385 | ret = xmlBufferDump(output, buf); |
| 3386 | fclose(output); |
| 3387 | #ifdef HAVE_ZLIB_H |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 3388 | } |
| 3389 | #endif |
Manish Vachharajani | 5e60f5a | 1999-05-29 03:04:30 +0000 | [diff] [blame] | 3390 | xmlBufferFree(buf); |
Daniel Veillard | dd6b367 | 1999-09-23 22:19:22 +0000 | [diff] [blame] | 3391 | return(ret * sizeof(xmlChar)); |
Daniel Veillard | 151b1b0 | 1998-09-23 00:49:46 +0000 | [diff] [blame] | 3392 | } |
| 3393 | |