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