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