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