Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
tree.c@1:26f20484cbdc, 2016-08-25 (annotated)
- Committer:
- pcercuei
- Date:
- Thu Aug 25 10:07:34 2016 +0000
- Revision:
- 1:26f20484cbdc
- Parent:
- 0:03b5121a232e
Add config.h and dummy.c containing empty functions
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| pcercuei | 0:03b5121a232e | 1 | /* |
| pcercuei | 0:03b5121a232e | 2 | * tree.c : implementation of access function for an XML tree. |
| pcercuei | 0:03b5121a232e | 3 | * |
| pcercuei | 0:03b5121a232e | 4 | * References: |
| pcercuei | 0:03b5121a232e | 5 | * XHTML 1.0 W3C REC: http://www.w3.org/TR/2002/REC-xhtml1-20020801/ |
| pcercuei | 0:03b5121a232e | 6 | * |
| pcercuei | 0:03b5121a232e | 7 | * See Copyright for the status of this software. |
| pcercuei | 0:03b5121a232e | 8 | * |
| pcercuei | 0:03b5121a232e | 9 | * daniel@veillard.com |
| pcercuei | 0:03b5121a232e | 10 | * |
| pcercuei | 0:03b5121a232e | 11 | */ |
| pcercuei | 0:03b5121a232e | 12 | |
| pcercuei | 0:03b5121a232e | 13 | #define IN_LIBXML |
| pcercuei | 0:03b5121a232e | 14 | #include "libxml.h" |
| pcercuei | 0:03b5121a232e | 15 | |
| pcercuei | 0:03b5121a232e | 16 | #include <string.h> /* for memset() only ! */ |
| pcercuei | 0:03b5121a232e | 17 | #include <limits.h> |
| pcercuei | 0:03b5121a232e | 18 | #ifdef HAVE_CTYPE_H |
| pcercuei | 0:03b5121a232e | 19 | #include <ctype.h> |
| pcercuei | 0:03b5121a232e | 20 | #endif |
| pcercuei | 0:03b5121a232e | 21 | #ifdef HAVE_STDLIB_H |
| pcercuei | 0:03b5121a232e | 22 | #include <stdlib.h> |
| pcercuei | 0:03b5121a232e | 23 | #endif |
| pcercuei | 0:03b5121a232e | 24 | #ifdef HAVE_ZLIB_H |
| pcercuei | 0:03b5121a232e | 25 | #include <zlib.h> |
| pcercuei | 0:03b5121a232e | 26 | #endif |
| pcercuei | 0:03b5121a232e | 27 | |
| pcercuei | 0:03b5121a232e | 28 | #include <libxml/xmlmemory.h> |
| pcercuei | 0:03b5121a232e | 29 | #include <libxml/tree.h> |
| pcercuei | 0:03b5121a232e | 30 | #include <libxml/parser.h> |
| pcercuei | 0:03b5121a232e | 31 | #include <libxml/uri.h> |
| pcercuei | 0:03b5121a232e | 32 | #include <libxml/entities.h> |
| pcercuei | 0:03b5121a232e | 33 | #include <libxml/valid.h> |
| pcercuei | 0:03b5121a232e | 34 | #include <libxml/xmlerror.h> |
| pcercuei | 0:03b5121a232e | 35 | #include <libxml/parserInternals.h> |
| pcercuei | 0:03b5121a232e | 36 | #include <libxml/globals.h> |
| pcercuei | 0:03b5121a232e | 37 | #ifdef LIBXML_HTML_ENABLED |
| pcercuei | 0:03b5121a232e | 38 | #include <libxml/HTMLtree.h> |
| pcercuei | 0:03b5121a232e | 39 | #endif |
| pcercuei | 0:03b5121a232e | 40 | #ifdef LIBXML_DEBUG_ENABLED |
| pcercuei | 0:03b5121a232e | 41 | #include <libxml/debugXML.h> |
| pcercuei | 0:03b5121a232e | 42 | #endif |
| pcercuei | 0:03b5121a232e | 43 | |
| pcercuei | 0:03b5121a232e | 44 | #include "buf.h" |
| pcercuei | 0:03b5121a232e | 45 | #include "save.h" |
| pcercuei | 0:03b5121a232e | 46 | |
| pcercuei | 0:03b5121a232e | 47 | int __xmlRegisterCallbacks = 0; |
| pcercuei | 0:03b5121a232e | 48 | |
| pcercuei | 0:03b5121a232e | 49 | /************************************************************************ |
| pcercuei | 0:03b5121a232e | 50 | * * |
| pcercuei | 0:03b5121a232e | 51 | * Forward declarations * |
| pcercuei | 0:03b5121a232e | 52 | * * |
| pcercuei | 0:03b5121a232e | 53 | ************************************************************************/ |
| pcercuei | 0:03b5121a232e | 54 | |
| pcercuei | 0:03b5121a232e | 55 | static xmlNsPtr |
| pcercuei | 0:03b5121a232e | 56 | xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns); |
| pcercuei | 0:03b5121a232e | 57 | |
| pcercuei | 0:03b5121a232e | 58 | static xmlChar* xmlGetPropNodeValueInternal(const xmlAttr *prop); |
| pcercuei | 0:03b5121a232e | 59 | |
| pcercuei | 0:03b5121a232e | 60 | /************************************************************************ |
| pcercuei | 0:03b5121a232e | 61 | * * |
| pcercuei | 0:03b5121a232e | 62 | * Tree memory error handler * |
| pcercuei | 0:03b5121a232e | 63 | * * |
| pcercuei | 0:03b5121a232e | 64 | ************************************************************************/ |
| pcercuei | 0:03b5121a232e | 65 | /** |
| pcercuei | 0:03b5121a232e | 66 | * xmlTreeErrMemory: |
| pcercuei | 0:03b5121a232e | 67 | * @extra: extra informations |
| pcercuei | 0:03b5121a232e | 68 | * |
| pcercuei | 0:03b5121a232e | 69 | * Handle an out of memory condition |
| pcercuei | 0:03b5121a232e | 70 | */ |
| pcercuei | 0:03b5121a232e | 71 | static void |
| pcercuei | 0:03b5121a232e | 72 | xmlTreeErrMemory(const char *extra) |
| pcercuei | 0:03b5121a232e | 73 | { |
| pcercuei | 0:03b5121a232e | 74 | __xmlSimpleError(XML_FROM_TREE, XML_ERR_NO_MEMORY, NULL, NULL, extra); |
| pcercuei | 0:03b5121a232e | 75 | } |
| pcercuei | 0:03b5121a232e | 76 | |
| pcercuei | 0:03b5121a232e | 77 | /** |
| pcercuei | 0:03b5121a232e | 78 | * xmlTreeErr: |
| pcercuei | 0:03b5121a232e | 79 | * @code: the error number |
| pcercuei | 0:03b5121a232e | 80 | * @extra: extra informations |
| pcercuei | 0:03b5121a232e | 81 | * |
| pcercuei | 0:03b5121a232e | 82 | * Handle an out of memory condition |
| pcercuei | 0:03b5121a232e | 83 | */ |
| pcercuei | 0:03b5121a232e | 84 | static void |
| pcercuei | 0:03b5121a232e | 85 | xmlTreeErr(int code, xmlNodePtr node, const char *extra) |
| pcercuei | 0:03b5121a232e | 86 | { |
| pcercuei | 0:03b5121a232e | 87 | const char *msg = NULL; |
| pcercuei | 0:03b5121a232e | 88 | |
| pcercuei | 0:03b5121a232e | 89 | switch(code) { |
| pcercuei | 0:03b5121a232e | 90 | case XML_TREE_INVALID_HEX: |
| pcercuei | 0:03b5121a232e | 91 | msg = "invalid hexadecimal character value\n"; |
| pcercuei | 0:03b5121a232e | 92 | break; |
| pcercuei | 0:03b5121a232e | 93 | case XML_TREE_INVALID_DEC: |
| pcercuei | 0:03b5121a232e | 94 | msg = "invalid decimal character value\n"; |
| pcercuei | 0:03b5121a232e | 95 | break; |
| pcercuei | 0:03b5121a232e | 96 | case XML_TREE_UNTERMINATED_ENTITY: |
| pcercuei | 0:03b5121a232e | 97 | msg = "unterminated entity reference %15s\n"; |
| pcercuei | 0:03b5121a232e | 98 | break; |
| pcercuei | 0:03b5121a232e | 99 | case XML_TREE_NOT_UTF8: |
| pcercuei | 0:03b5121a232e | 100 | msg = "string is not in UTF-8\n"; |
| pcercuei | 0:03b5121a232e | 101 | break; |
| pcercuei | 0:03b5121a232e | 102 | default: |
| pcercuei | 0:03b5121a232e | 103 | msg = "unexpected error number\n"; |
| pcercuei | 0:03b5121a232e | 104 | } |
| pcercuei | 0:03b5121a232e | 105 | __xmlSimpleError(XML_FROM_TREE, code, node, msg, extra); |
| pcercuei | 0:03b5121a232e | 106 | } |
| pcercuei | 0:03b5121a232e | 107 | |
| pcercuei | 0:03b5121a232e | 108 | /************************************************************************ |
| pcercuei | 0:03b5121a232e | 109 | * * |
| pcercuei | 0:03b5121a232e | 110 | * A few static variables and macros * |
| pcercuei | 0:03b5121a232e | 111 | * * |
| pcercuei | 0:03b5121a232e | 112 | ************************************************************************/ |
| pcercuei | 0:03b5121a232e | 113 | /* #undef xmlStringText */ |
| pcercuei | 0:03b5121a232e | 114 | const xmlChar xmlStringText[] = { 't', 'e', 'x', 't', 0 }; |
| pcercuei | 0:03b5121a232e | 115 | /* #undef xmlStringTextNoenc */ |
| pcercuei | 0:03b5121a232e | 116 | const xmlChar xmlStringTextNoenc[] = |
| pcercuei | 0:03b5121a232e | 117 | { 't', 'e', 'x', 't', 'n', 'o', 'e', 'n', 'c', 0 }; |
| pcercuei | 0:03b5121a232e | 118 | /* #undef xmlStringComment */ |
| pcercuei | 0:03b5121a232e | 119 | const xmlChar xmlStringComment[] = { 'c', 'o', 'm', 'm', 'e', 'n', 't', 0 }; |
| pcercuei | 0:03b5121a232e | 120 | |
| pcercuei | 0:03b5121a232e | 121 | static int xmlCompressMode = 0; |
| pcercuei | 0:03b5121a232e | 122 | static int xmlCheckDTD = 1; |
| pcercuei | 0:03b5121a232e | 123 | |
| pcercuei | 0:03b5121a232e | 124 | #define UPDATE_LAST_CHILD_AND_PARENT(n) if ((n) != NULL) { \ |
| pcercuei | 0:03b5121a232e | 125 | xmlNodePtr ulccur = (n)->children; \ |
| pcercuei | 0:03b5121a232e | 126 | if (ulccur == NULL) { \ |
| pcercuei | 0:03b5121a232e | 127 | (n)->last = NULL; \ |
| pcercuei | 0:03b5121a232e | 128 | } else { \ |
| pcercuei | 0:03b5121a232e | 129 | while (ulccur->next != NULL) { \ |
| pcercuei | 0:03b5121a232e | 130 | ulccur->parent = (n); \ |
| pcercuei | 0:03b5121a232e | 131 | ulccur = ulccur->next; \ |
| pcercuei | 0:03b5121a232e | 132 | } \ |
| pcercuei | 0:03b5121a232e | 133 | ulccur->parent = (n); \ |
| pcercuei | 0:03b5121a232e | 134 | (n)->last = ulccur; \ |
| pcercuei | 0:03b5121a232e | 135 | }} |
| pcercuei | 0:03b5121a232e | 136 | |
| pcercuei | 0:03b5121a232e | 137 | #define IS_STR_XML(str) ((str != NULL) && (str[0] == 'x') && \ |
| pcercuei | 0:03b5121a232e | 138 | (str[1] == 'm') && (str[2] == 'l') && (str[3] == 0)) |
| pcercuei | 0:03b5121a232e | 139 | |
| pcercuei | 0:03b5121a232e | 140 | /* #define DEBUG_BUFFER */ |
| pcercuei | 0:03b5121a232e | 141 | /* #define DEBUG_TREE */ |
| pcercuei | 0:03b5121a232e | 142 | |
| pcercuei | 0:03b5121a232e | 143 | /************************************************************************ |
| pcercuei | 0:03b5121a232e | 144 | * * |
| pcercuei | 0:03b5121a232e | 145 | * Functions to move to entities.c once the * |
| pcercuei | 0:03b5121a232e | 146 | * API freeze is smoothen and they can be made public. * |
| pcercuei | 0:03b5121a232e | 147 | * * |
| pcercuei | 0:03b5121a232e | 148 | ************************************************************************/ |
| pcercuei | 0:03b5121a232e | 149 | #include <libxml/hash.h> |
| pcercuei | 0:03b5121a232e | 150 | |
| pcercuei | 0:03b5121a232e | 151 | #ifdef LIBXML_TREE_ENABLED |
| pcercuei | 0:03b5121a232e | 152 | /** |
| pcercuei | 0:03b5121a232e | 153 | * xmlGetEntityFromDtd: |
| pcercuei | 0:03b5121a232e | 154 | * @dtd: A pointer to the DTD to search |
| pcercuei | 0:03b5121a232e | 155 | * @name: The entity name |
| pcercuei | 0:03b5121a232e | 156 | * |
| pcercuei | 0:03b5121a232e | 157 | * Do an entity lookup in the DTD entity hash table and |
| pcercuei | 0:03b5121a232e | 158 | * return the corresponding entity, if found. |
| pcercuei | 0:03b5121a232e | 159 | * |
| pcercuei | 0:03b5121a232e | 160 | * Returns A pointer to the entity structure or NULL if not found. |
| pcercuei | 0:03b5121a232e | 161 | */ |
| pcercuei | 0:03b5121a232e | 162 | static xmlEntityPtr |
| pcercuei | 0:03b5121a232e | 163 | xmlGetEntityFromDtd(const xmlDtd *dtd, const xmlChar *name) { |
| pcercuei | 0:03b5121a232e | 164 | xmlEntitiesTablePtr table; |
| pcercuei | 0:03b5121a232e | 165 | |
| pcercuei | 0:03b5121a232e | 166 | if((dtd != NULL) && (dtd->entities != NULL)) { |
| pcercuei | 0:03b5121a232e | 167 | table = (xmlEntitiesTablePtr) dtd->entities; |
| pcercuei | 0:03b5121a232e | 168 | return((xmlEntityPtr) xmlHashLookup(table, name)); |
| pcercuei | 0:03b5121a232e | 169 | /* return(xmlGetEntityFromTable(table, name)); */ |
| pcercuei | 0:03b5121a232e | 170 | } |
| pcercuei | 0:03b5121a232e | 171 | return(NULL); |
| pcercuei | 0:03b5121a232e | 172 | } |
| pcercuei | 0:03b5121a232e | 173 | /** |
| pcercuei | 0:03b5121a232e | 174 | * xmlGetParameterEntityFromDtd: |
| pcercuei | 0:03b5121a232e | 175 | * @dtd: A pointer to the DTD to search |
| pcercuei | 0:03b5121a232e | 176 | * @name: The entity name |
| pcercuei | 0:03b5121a232e | 177 | * |
| pcercuei | 0:03b5121a232e | 178 | * Do an entity lookup in the DTD pararmeter entity hash table and |
| pcercuei | 0:03b5121a232e | 179 | * return the corresponding entity, if found. |
| pcercuei | 0:03b5121a232e | 180 | * |
| pcercuei | 0:03b5121a232e | 181 | * Returns A pointer to the entity structure or NULL if not found. |
| pcercuei | 0:03b5121a232e | 182 | */ |
| pcercuei | 0:03b5121a232e | 183 | static xmlEntityPtr |
| pcercuei | 0:03b5121a232e | 184 | xmlGetParameterEntityFromDtd(const xmlDtd *dtd, const xmlChar *name) { |
| pcercuei | 0:03b5121a232e | 185 | xmlEntitiesTablePtr table; |
| pcercuei | 0:03b5121a232e | 186 | |
| pcercuei | 0:03b5121a232e | 187 | if ((dtd != NULL) && (dtd->pentities != NULL)) { |
| pcercuei | 0:03b5121a232e | 188 | table = (xmlEntitiesTablePtr) dtd->pentities; |
| pcercuei | 0:03b5121a232e | 189 | return((xmlEntityPtr) xmlHashLookup(table, name)); |
| pcercuei | 0:03b5121a232e | 190 | /* return(xmlGetEntityFromTable(table, name)); */ |
| pcercuei | 0:03b5121a232e | 191 | } |
| pcercuei | 0:03b5121a232e | 192 | return(NULL); |
| pcercuei | 0:03b5121a232e | 193 | } |
| pcercuei | 0:03b5121a232e | 194 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 195 | |
| pcercuei | 0:03b5121a232e | 196 | /************************************************************************ |
| pcercuei | 0:03b5121a232e | 197 | * * |
| pcercuei | 0:03b5121a232e | 198 | * QName handling helper * |
| pcercuei | 0:03b5121a232e | 199 | * * |
| pcercuei | 0:03b5121a232e | 200 | ************************************************************************/ |
| pcercuei | 0:03b5121a232e | 201 | |
| pcercuei | 0:03b5121a232e | 202 | /** |
| pcercuei | 0:03b5121a232e | 203 | * xmlBuildQName: |
| pcercuei | 0:03b5121a232e | 204 | * @ncname: the Name |
| pcercuei | 0:03b5121a232e | 205 | * @prefix: the prefix |
| pcercuei | 0:03b5121a232e | 206 | * @memory: preallocated memory |
| pcercuei | 0:03b5121a232e | 207 | * @len: preallocated memory length |
| pcercuei | 0:03b5121a232e | 208 | * |
| pcercuei | 0:03b5121a232e | 209 | * Builds the QName @prefix:@ncname in @memory if there is enough space |
| pcercuei | 0:03b5121a232e | 210 | * and prefix is not NULL nor empty, otherwise allocate a new string. |
| pcercuei | 0:03b5121a232e | 211 | * If prefix is NULL or empty it returns ncname. |
| pcercuei | 0:03b5121a232e | 212 | * |
| pcercuei | 0:03b5121a232e | 213 | * Returns the new string which must be freed by the caller if different from |
| pcercuei | 0:03b5121a232e | 214 | * @memory and @ncname or NULL in case of error |
| pcercuei | 0:03b5121a232e | 215 | */ |
| pcercuei | 0:03b5121a232e | 216 | xmlChar * |
| pcercuei | 0:03b5121a232e | 217 | xmlBuildQName(const xmlChar *ncname, const xmlChar *prefix, |
| pcercuei | 0:03b5121a232e | 218 | xmlChar *memory, int len) { |
| pcercuei | 0:03b5121a232e | 219 | int lenn, lenp; |
| pcercuei | 0:03b5121a232e | 220 | xmlChar *ret; |
| pcercuei | 0:03b5121a232e | 221 | |
| pcercuei | 0:03b5121a232e | 222 | if (ncname == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 223 | if (prefix == NULL) return((xmlChar *) ncname); |
| pcercuei | 0:03b5121a232e | 224 | |
| pcercuei | 0:03b5121a232e | 225 | lenn = strlen((char *) ncname); |
| pcercuei | 0:03b5121a232e | 226 | lenp = strlen((char *) prefix); |
| pcercuei | 0:03b5121a232e | 227 | |
| pcercuei | 0:03b5121a232e | 228 | if ((memory == NULL) || (len < lenn + lenp + 2)) { |
| pcercuei | 0:03b5121a232e | 229 | ret = (xmlChar *) xmlMallocAtomic(lenn + lenp + 2); |
| pcercuei | 0:03b5121a232e | 230 | if (ret == NULL) { |
| pcercuei | 0:03b5121a232e | 231 | xmlTreeErrMemory("building QName"); |
| pcercuei | 0:03b5121a232e | 232 | return(NULL); |
| pcercuei | 0:03b5121a232e | 233 | } |
| pcercuei | 0:03b5121a232e | 234 | } else { |
| pcercuei | 0:03b5121a232e | 235 | ret = memory; |
| pcercuei | 0:03b5121a232e | 236 | } |
| pcercuei | 0:03b5121a232e | 237 | memcpy(&ret[0], prefix, lenp); |
| pcercuei | 0:03b5121a232e | 238 | ret[lenp] = ':'; |
| pcercuei | 0:03b5121a232e | 239 | memcpy(&ret[lenp + 1], ncname, lenn); |
| pcercuei | 0:03b5121a232e | 240 | ret[lenn + lenp + 1] = 0; |
| pcercuei | 0:03b5121a232e | 241 | return(ret); |
| pcercuei | 0:03b5121a232e | 242 | } |
| pcercuei | 0:03b5121a232e | 243 | |
| pcercuei | 0:03b5121a232e | 244 | /** |
| pcercuei | 0:03b5121a232e | 245 | * xmlSplitQName2: |
| pcercuei | 0:03b5121a232e | 246 | * @name: the full QName |
| pcercuei | 0:03b5121a232e | 247 | * @prefix: a xmlChar ** |
| pcercuei | 0:03b5121a232e | 248 | * |
| pcercuei | 0:03b5121a232e | 249 | * parse an XML qualified name string |
| pcercuei | 0:03b5121a232e | 250 | * |
| pcercuei | 0:03b5121a232e | 251 | * [NS 5] QName ::= (Prefix ':')? LocalPart |
| pcercuei | 0:03b5121a232e | 252 | * |
| pcercuei | 0:03b5121a232e | 253 | * [NS 6] Prefix ::= NCName |
| pcercuei | 0:03b5121a232e | 254 | * |
| pcercuei | 0:03b5121a232e | 255 | * [NS 7] LocalPart ::= NCName |
| pcercuei | 0:03b5121a232e | 256 | * |
| pcercuei | 0:03b5121a232e | 257 | * Returns NULL if not a QName, otherwise the local part, and prefix |
| pcercuei | 0:03b5121a232e | 258 | * is updated to get the Prefix if any. |
| pcercuei | 0:03b5121a232e | 259 | */ |
| pcercuei | 0:03b5121a232e | 260 | |
| pcercuei | 0:03b5121a232e | 261 | xmlChar * |
| pcercuei | 0:03b5121a232e | 262 | xmlSplitQName2(const xmlChar *name, xmlChar **prefix) { |
| pcercuei | 0:03b5121a232e | 263 | int len = 0; |
| pcercuei | 0:03b5121a232e | 264 | xmlChar *ret = NULL; |
| pcercuei | 0:03b5121a232e | 265 | |
| pcercuei | 0:03b5121a232e | 266 | if (prefix == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 267 | *prefix = NULL; |
| pcercuei | 0:03b5121a232e | 268 | if (name == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 269 | |
| pcercuei | 0:03b5121a232e | 270 | #ifndef XML_XML_NAMESPACE |
| pcercuei | 0:03b5121a232e | 271 | /* xml: prefix is not really a namespace */ |
| pcercuei | 0:03b5121a232e | 272 | if ((name[0] == 'x') && (name[1] == 'm') && |
| pcercuei | 0:03b5121a232e | 273 | (name[2] == 'l') && (name[3] == ':')) |
| pcercuei | 0:03b5121a232e | 274 | return(NULL); |
| pcercuei | 0:03b5121a232e | 275 | #endif |
| pcercuei | 0:03b5121a232e | 276 | |
| pcercuei | 0:03b5121a232e | 277 | /* nasty but valid */ |
| pcercuei | 0:03b5121a232e | 278 | if (name[0] == ':') |
| pcercuei | 0:03b5121a232e | 279 | return(NULL); |
| pcercuei | 0:03b5121a232e | 280 | |
| pcercuei | 0:03b5121a232e | 281 | /* |
| pcercuei | 0:03b5121a232e | 282 | * we are not trying to validate but just to cut, and yes it will |
| pcercuei | 0:03b5121a232e | 283 | * work even if this is as set of UTF-8 encoded chars |
| pcercuei | 0:03b5121a232e | 284 | */ |
| pcercuei | 0:03b5121a232e | 285 | while ((name[len] != 0) && (name[len] != ':')) |
| pcercuei | 0:03b5121a232e | 286 | len++; |
| pcercuei | 0:03b5121a232e | 287 | |
| pcercuei | 0:03b5121a232e | 288 | if (name[len] == 0) |
| pcercuei | 0:03b5121a232e | 289 | return(NULL); |
| pcercuei | 0:03b5121a232e | 290 | |
| pcercuei | 0:03b5121a232e | 291 | *prefix = xmlStrndup(name, len); |
| pcercuei | 0:03b5121a232e | 292 | if (*prefix == NULL) { |
| pcercuei | 0:03b5121a232e | 293 | xmlTreeErrMemory("QName split"); |
| pcercuei | 0:03b5121a232e | 294 | return(NULL); |
| pcercuei | 0:03b5121a232e | 295 | } |
| pcercuei | 0:03b5121a232e | 296 | ret = xmlStrdup(&name[len + 1]); |
| pcercuei | 0:03b5121a232e | 297 | if (ret == NULL) { |
| pcercuei | 0:03b5121a232e | 298 | xmlTreeErrMemory("QName split"); |
| pcercuei | 0:03b5121a232e | 299 | if (*prefix != NULL) { |
| pcercuei | 0:03b5121a232e | 300 | xmlFree(*prefix); |
| pcercuei | 0:03b5121a232e | 301 | *prefix = NULL; |
| pcercuei | 0:03b5121a232e | 302 | } |
| pcercuei | 0:03b5121a232e | 303 | return(NULL); |
| pcercuei | 0:03b5121a232e | 304 | } |
| pcercuei | 0:03b5121a232e | 305 | |
| pcercuei | 0:03b5121a232e | 306 | return(ret); |
| pcercuei | 0:03b5121a232e | 307 | } |
| pcercuei | 0:03b5121a232e | 308 | |
| pcercuei | 0:03b5121a232e | 309 | /** |
| pcercuei | 0:03b5121a232e | 310 | * xmlSplitQName3: |
| pcercuei | 0:03b5121a232e | 311 | * @name: the full QName |
| pcercuei | 0:03b5121a232e | 312 | * @len: an int * |
| pcercuei | 0:03b5121a232e | 313 | * |
| pcercuei | 0:03b5121a232e | 314 | * parse an XML qualified name string,i |
| pcercuei | 0:03b5121a232e | 315 | * |
| pcercuei | 0:03b5121a232e | 316 | * returns NULL if it is not a Qualified Name, otherwise, update len |
| pcercuei | 0:03b5121a232e | 317 | * with the length in byte of the prefix and return a pointer |
| pcercuei | 0:03b5121a232e | 318 | * to the start of the name without the prefix |
| pcercuei | 0:03b5121a232e | 319 | */ |
| pcercuei | 0:03b5121a232e | 320 | |
| pcercuei | 0:03b5121a232e | 321 | const xmlChar * |
| pcercuei | 0:03b5121a232e | 322 | xmlSplitQName3(const xmlChar *name, int *len) { |
| pcercuei | 0:03b5121a232e | 323 | int l = 0; |
| pcercuei | 0:03b5121a232e | 324 | |
| pcercuei | 0:03b5121a232e | 325 | if (name == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 326 | if (len == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 327 | |
| pcercuei | 0:03b5121a232e | 328 | /* nasty but valid */ |
| pcercuei | 0:03b5121a232e | 329 | if (name[0] == ':') |
| pcercuei | 0:03b5121a232e | 330 | return(NULL); |
| pcercuei | 0:03b5121a232e | 331 | |
| pcercuei | 0:03b5121a232e | 332 | /* |
| pcercuei | 0:03b5121a232e | 333 | * we are not trying to validate but just to cut, and yes it will |
| pcercuei | 0:03b5121a232e | 334 | * work even if this is as set of UTF-8 encoded chars |
| pcercuei | 0:03b5121a232e | 335 | */ |
| pcercuei | 0:03b5121a232e | 336 | while ((name[l] != 0) && (name[l] != ':')) |
| pcercuei | 0:03b5121a232e | 337 | l++; |
| pcercuei | 0:03b5121a232e | 338 | |
| pcercuei | 0:03b5121a232e | 339 | if (name[l] == 0) |
| pcercuei | 0:03b5121a232e | 340 | return(NULL); |
| pcercuei | 0:03b5121a232e | 341 | |
| pcercuei | 0:03b5121a232e | 342 | *len = l; |
| pcercuei | 0:03b5121a232e | 343 | |
| pcercuei | 0:03b5121a232e | 344 | return(&name[l+1]); |
| pcercuei | 0:03b5121a232e | 345 | } |
| pcercuei | 0:03b5121a232e | 346 | |
| pcercuei | 0:03b5121a232e | 347 | /************************************************************************ |
| pcercuei | 0:03b5121a232e | 348 | * * |
| pcercuei | 0:03b5121a232e | 349 | * Check Name, NCName and QName strings * |
| pcercuei | 0:03b5121a232e | 350 | * * |
| pcercuei | 0:03b5121a232e | 351 | ************************************************************************/ |
| pcercuei | 0:03b5121a232e | 352 | |
| pcercuei | 0:03b5121a232e | 353 | #define CUR_SCHAR(s, l) xmlStringCurrentChar(NULL, s, &l) |
| pcercuei | 0:03b5121a232e | 354 | |
| pcercuei | 0:03b5121a232e | 355 | #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) || defined (LIBXML_HTML_ENABLED) || defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
| pcercuei | 0:03b5121a232e | 356 | /** |
| pcercuei | 0:03b5121a232e | 357 | * xmlValidateNCName: |
| pcercuei | 0:03b5121a232e | 358 | * @value: the value to check |
| pcercuei | 0:03b5121a232e | 359 | * @space: allow spaces in front and end of the string |
| pcercuei | 0:03b5121a232e | 360 | * |
| pcercuei | 0:03b5121a232e | 361 | * Check that a value conforms to the lexical space of NCName |
| pcercuei | 0:03b5121a232e | 362 | * |
| pcercuei | 0:03b5121a232e | 363 | * Returns 0 if this validates, a positive error code number otherwise |
| pcercuei | 0:03b5121a232e | 364 | * and -1 in case of internal or API error. |
| pcercuei | 0:03b5121a232e | 365 | */ |
| pcercuei | 0:03b5121a232e | 366 | int |
| pcercuei | 0:03b5121a232e | 367 | xmlValidateNCName(const xmlChar *value, int space) { |
| pcercuei | 0:03b5121a232e | 368 | const xmlChar *cur = value; |
| pcercuei | 0:03b5121a232e | 369 | int c,l; |
| pcercuei | 0:03b5121a232e | 370 | |
| pcercuei | 0:03b5121a232e | 371 | if (value == NULL) |
| pcercuei | 0:03b5121a232e | 372 | return(-1); |
| pcercuei | 0:03b5121a232e | 373 | |
| pcercuei | 0:03b5121a232e | 374 | /* |
| pcercuei | 0:03b5121a232e | 375 | * First quick algorithm for ASCII range |
| pcercuei | 0:03b5121a232e | 376 | */ |
| pcercuei | 0:03b5121a232e | 377 | if (space) |
| pcercuei | 0:03b5121a232e | 378 | while (IS_BLANK_CH(*cur)) cur++; |
| pcercuei | 0:03b5121a232e | 379 | if (((*cur >= 'a') && (*cur <= 'z')) || ((*cur >= 'A') && (*cur <= 'Z')) || |
| pcercuei | 0:03b5121a232e | 380 | (*cur == '_')) |
| pcercuei | 0:03b5121a232e | 381 | cur++; |
| pcercuei | 0:03b5121a232e | 382 | else |
| pcercuei | 0:03b5121a232e | 383 | goto try_complex; |
| pcercuei | 0:03b5121a232e | 384 | while (((*cur >= 'a') && (*cur <= 'z')) || |
| pcercuei | 0:03b5121a232e | 385 | ((*cur >= 'A') && (*cur <= 'Z')) || |
| pcercuei | 0:03b5121a232e | 386 | ((*cur >= '0') && (*cur <= '9')) || |
| pcercuei | 0:03b5121a232e | 387 | (*cur == '_') || (*cur == '-') || (*cur == '.')) |
| pcercuei | 0:03b5121a232e | 388 | cur++; |
| pcercuei | 0:03b5121a232e | 389 | if (space) |
| pcercuei | 0:03b5121a232e | 390 | while (IS_BLANK_CH(*cur)) cur++; |
| pcercuei | 0:03b5121a232e | 391 | if (*cur == 0) |
| pcercuei | 0:03b5121a232e | 392 | return(0); |
| pcercuei | 0:03b5121a232e | 393 | |
| pcercuei | 0:03b5121a232e | 394 | try_complex: |
| pcercuei | 0:03b5121a232e | 395 | /* |
| pcercuei | 0:03b5121a232e | 396 | * Second check for chars outside the ASCII range |
| pcercuei | 0:03b5121a232e | 397 | */ |
| pcercuei | 0:03b5121a232e | 398 | cur = value; |
| pcercuei | 0:03b5121a232e | 399 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 400 | if (space) { |
| pcercuei | 0:03b5121a232e | 401 | while (IS_BLANK(c)) { |
| pcercuei | 0:03b5121a232e | 402 | cur += l; |
| pcercuei | 0:03b5121a232e | 403 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 404 | } |
| pcercuei | 0:03b5121a232e | 405 | } |
| pcercuei | 0:03b5121a232e | 406 | if ((!IS_LETTER(c)) && (c != '_')) |
| pcercuei | 0:03b5121a232e | 407 | return(1); |
| pcercuei | 0:03b5121a232e | 408 | cur += l; |
| pcercuei | 0:03b5121a232e | 409 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 410 | while (IS_LETTER(c) || IS_DIGIT(c) || (c == '.') || |
| pcercuei | 0:03b5121a232e | 411 | (c == '-') || (c == '_') || IS_COMBINING(c) || |
| pcercuei | 0:03b5121a232e | 412 | IS_EXTENDER(c)) { |
| pcercuei | 0:03b5121a232e | 413 | cur += l; |
| pcercuei | 0:03b5121a232e | 414 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 415 | } |
| pcercuei | 0:03b5121a232e | 416 | if (space) { |
| pcercuei | 0:03b5121a232e | 417 | while (IS_BLANK(c)) { |
| pcercuei | 0:03b5121a232e | 418 | cur += l; |
| pcercuei | 0:03b5121a232e | 419 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 420 | } |
| pcercuei | 0:03b5121a232e | 421 | } |
| pcercuei | 0:03b5121a232e | 422 | if (c != 0) |
| pcercuei | 0:03b5121a232e | 423 | return(1); |
| pcercuei | 0:03b5121a232e | 424 | |
| pcercuei | 0:03b5121a232e | 425 | return(0); |
| pcercuei | 0:03b5121a232e | 426 | } |
| pcercuei | 0:03b5121a232e | 427 | #endif |
| pcercuei | 0:03b5121a232e | 428 | |
| pcercuei | 0:03b5121a232e | 429 | #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) |
| pcercuei | 0:03b5121a232e | 430 | /** |
| pcercuei | 0:03b5121a232e | 431 | * xmlValidateQName: |
| pcercuei | 0:03b5121a232e | 432 | * @value: the value to check |
| pcercuei | 0:03b5121a232e | 433 | * @space: allow spaces in front and end of the string |
| pcercuei | 0:03b5121a232e | 434 | * |
| pcercuei | 0:03b5121a232e | 435 | * Check that a value conforms to the lexical space of QName |
| pcercuei | 0:03b5121a232e | 436 | * |
| pcercuei | 0:03b5121a232e | 437 | * Returns 0 if this validates, a positive error code number otherwise |
| pcercuei | 0:03b5121a232e | 438 | * and -1 in case of internal or API error. |
| pcercuei | 0:03b5121a232e | 439 | */ |
| pcercuei | 0:03b5121a232e | 440 | int |
| pcercuei | 0:03b5121a232e | 441 | xmlValidateQName(const xmlChar *value, int space) { |
| pcercuei | 0:03b5121a232e | 442 | const xmlChar *cur = value; |
| pcercuei | 0:03b5121a232e | 443 | int c,l; |
| pcercuei | 0:03b5121a232e | 444 | |
| pcercuei | 0:03b5121a232e | 445 | if (value == NULL) |
| pcercuei | 0:03b5121a232e | 446 | return(-1); |
| pcercuei | 0:03b5121a232e | 447 | /* |
| pcercuei | 0:03b5121a232e | 448 | * First quick algorithm for ASCII range |
| pcercuei | 0:03b5121a232e | 449 | */ |
| pcercuei | 0:03b5121a232e | 450 | if (space) |
| pcercuei | 0:03b5121a232e | 451 | while (IS_BLANK_CH(*cur)) cur++; |
| pcercuei | 0:03b5121a232e | 452 | if (((*cur >= 'a') && (*cur <= 'z')) || ((*cur >= 'A') && (*cur <= 'Z')) || |
| pcercuei | 0:03b5121a232e | 453 | (*cur == '_')) |
| pcercuei | 0:03b5121a232e | 454 | cur++; |
| pcercuei | 0:03b5121a232e | 455 | else |
| pcercuei | 0:03b5121a232e | 456 | goto try_complex; |
| pcercuei | 0:03b5121a232e | 457 | while (((*cur >= 'a') && (*cur <= 'z')) || |
| pcercuei | 0:03b5121a232e | 458 | ((*cur >= 'A') && (*cur <= 'Z')) || |
| pcercuei | 0:03b5121a232e | 459 | ((*cur >= '0') && (*cur <= '9')) || |
| pcercuei | 0:03b5121a232e | 460 | (*cur == '_') || (*cur == '-') || (*cur == '.')) |
| pcercuei | 0:03b5121a232e | 461 | cur++; |
| pcercuei | 0:03b5121a232e | 462 | if (*cur == ':') { |
| pcercuei | 0:03b5121a232e | 463 | cur++; |
| pcercuei | 0:03b5121a232e | 464 | if (((*cur >= 'a') && (*cur <= 'z')) || |
| pcercuei | 0:03b5121a232e | 465 | ((*cur >= 'A') && (*cur <= 'Z')) || |
| pcercuei | 0:03b5121a232e | 466 | (*cur == '_')) |
| pcercuei | 0:03b5121a232e | 467 | cur++; |
| pcercuei | 0:03b5121a232e | 468 | else |
| pcercuei | 0:03b5121a232e | 469 | goto try_complex; |
| pcercuei | 0:03b5121a232e | 470 | while (((*cur >= 'a') && (*cur <= 'z')) || |
| pcercuei | 0:03b5121a232e | 471 | ((*cur >= 'A') && (*cur <= 'Z')) || |
| pcercuei | 0:03b5121a232e | 472 | ((*cur >= '0') && (*cur <= '9')) || |
| pcercuei | 0:03b5121a232e | 473 | (*cur == '_') || (*cur == '-') || (*cur == '.')) |
| pcercuei | 0:03b5121a232e | 474 | cur++; |
| pcercuei | 0:03b5121a232e | 475 | } |
| pcercuei | 0:03b5121a232e | 476 | if (space) |
| pcercuei | 0:03b5121a232e | 477 | while (IS_BLANK_CH(*cur)) cur++; |
| pcercuei | 0:03b5121a232e | 478 | if (*cur == 0) |
| pcercuei | 0:03b5121a232e | 479 | return(0); |
| pcercuei | 0:03b5121a232e | 480 | |
| pcercuei | 0:03b5121a232e | 481 | try_complex: |
| pcercuei | 0:03b5121a232e | 482 | /* |
| pcercuei | 0:03b5121a232e | 483 | * Second check for chars outside the ASCII range |
| pcercuei | 0:03b5121a232e | 484 | */ |
| pcercuei | 0:03b5121a232e | 485 | cur = value; |
| pcercuei | 0:03b5121a232e | 486 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 487 | if (space) { |
| pcercuei | 0:03b5121a232e | 488 | while (IS_BLANK(c)) { |
| pcercuei | 0:03b5121a232e | 489 | cur += l; |
| pcercuei | 0:03b5121a232e | 490 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 491 | } |
| pcercuei | 0:03b5121a232e | 492 | } |
| pcercuei | 0:03b5121a232e | 493 | if ((!IS_LETTER(c)) && (c != '_')) |
| pcercuei | 0:03b5121a232e | 494 | return(1); |
| pcercuei | 0:03b5121a232e | 495 | cur += l; |
| pcercuei | 0:03b5121a232e | 496 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 497 | while (IS_LETTER(c) || IS_DIGIT(c) || (c == '.') || |
| pcercuei | 0:03b5121a232e | 498 | (c == '-') || (c == '_') || IS_COMBINING(c) || |
| pcercuei | 0:03b5121a232e | 499 | IS_EXTENDER(c)) { |
| pcercuei | 0:03b5121a232e | 500 | cur += l; |
| pcercuei | 0:03b5121a232e | 501 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 502 | } |
| pcercuei | 0:03b5121a232e | 503 | if (c == ':') { |
| pcercuei | 0:03b5121a232e | 504 | cur += l; |
| pcercuei | 0:03b5121a232e | 505 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 506 | if ((!IS_LETTER(c)) && (c != '_')) |
| pcercuei | 0:03b5121a232e | 507 | return(1); |
| pcercuei | 0:03b5121a232e | 508 | cur += l; |
| pcercuei | 0:03b5121a232e | 509 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 510 | while (IS_LETTER(c) || IS_DIGIT(c) || (c == '.') || |
| pcercuei | 0:03b5121a232e | 511 | (c == '-') || (c == '_') || IS_COMBINING(c) || |
| pcercuei | 0:03b5121a232e | 512 | IS_EXTENDER(c)) { |
| pcercuei | 0:03b5121a232e | 513 | cur += l; |
| pcercuei | 0:03b5121a232e | 514 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 515 | } |
| pcercuei | 0:03b5121a232e | 516 | } |
| pcercuei | 0:03b5121a232e | 517 | if (space) { |
| pcercuei | 0:03b5121a232e | 518 | while (IS_BLANK(c)) { |
| pcercuei | 0:03b5121a232e | 519 | cur += l; |
| pcercuei | 0:03b5121a232e | 520 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 521 | } |
| pcercuei | 0:03b5121a232e | 522 | } |
| pcercuei | 0:03b5121a232e | 523 | if (c != 0) |
| pcercuei | 0:03b5121a232e | 524 | return(1); |
| pcercuei | 0:03b5121a232e | 525 | return(0); |
| pcercuei | 0:03b5121a232e | 526 | } |
| pcercuei | 0:03b5121a232e | 527 | |
| pcercuei | 0:03b5121a232e | 528 | /** |
| pcercuei | 0:03b5121a232e | 529 | * xmlValidateName: |
| pcercuei | 0:03b5121a232e | 530 | * @value: the value to check |
| pcercuei | 0:03b5121a232e | 531 | * @space: allow spaces in front and end of the string |
| pcercuei | 0:03b5121a232e | 532 | * |
| pcercuei | 0:03b5121a232e | 533 | * Check that a value conforms to the lexical space of Name |
| pcercuei | 0:03b5121a232e | 534 | * |
| pcercuei | 0:03b5121a232e | 535 | * Returns 0 if this validates, a positive error code number otherwise |
| pcercuei | 0:03b5121a232e | 536 | * and -1 in case of internal or API error. |
| pcercuei | 0:03b5121a232e | 537 | */ |
| pcercuei | 0:03b5121a232e | 538 | int |
| pcercuei | 0:03b5121a232e | 539 | xmlValidateName(const xmlChar *value, int space) { |
| pcercuei | 0:03b5121a232e | 540 | const xmlChar *cur = value; |
| pcercuei | 0:03b5121a232e | 541 | int c,l; |
| pcercuei | 0:03b5121a232e | 542 | |
| pcercuei | 0:03b5121a232e | 543 | if (value == NULL) |
| pcercuei | 0:03b5121a232e | 544 | return(-1); |
| pcercuei | 0:03b5121a232e | 545 | /* |
| pcercuei | 0:03b5121a232e | 546 | * First quick algorithm for ASCII range |
| pcercuei | 0:03b5121a232e | 547 | */ |
| pcercuei | 0:03b5121a232e | 548 | if (space) |
| pcercuei | 0:03b5121a232e | 549 | while (IS_BLANK_CH(*cur)) cur++; |
| pcercuei | 0:03b5121a232e | 550 | if (((*cur >= 'a') && (*cur <= 'z')) || ((*cur >= 'A') && (*cur <= 'Z')) || |
| pcercuei | 0:03b5121a232e | 551 | (*cur == '_') || (*cur == ':')) |
| pcercuei | 0:03b5121a232e | 552 | cur++; |
| pcercuei | 0:03b5121a232e | 553 | else |
| pcercuei | 0:03b5121a232e | 554 | goto try_complex; |
| pcercuei | 0:03b5121a232e | 555 | while (((*cur >= 'a') && (*cur <= 'z')) || |
| pcercuei | 0:03b5121a232e | 556 | ((*cur >= 'A') && (*cur <= 'Z')) || |
| pcercuei | 0:03b5121a232e | 557 | ((*cur >= '0') && (*cur <= '9')) || |
| pcercuei | 0:03b5121a232e | 558 | (*cur == '_') || (*cur == '-') || (*cur == '.') || (*cur == ':')) |
| pcercuei | 0:03b5121a232e | 559 | cur++; |
| pcercuei | 0:03b5121a232e | 560 | if (space) |
| pcercuei | 0:03b5121a232e | 561 | while (IS_BLANK_CH(*cur)) cur++; |
| pcercuei | 0:03b5121a232e | 562 | if (*cur == 0) |
| pcercuei | 0:03b5121a232e | 563 | return(0); |
| pcercuei | 0:03b5121a232e | 564 | |
| pcercuei | 0:03b5121a232e | 565 | try_complex: |
| pcercuei | 0:03b5121a232e | 566 | /* |
| pcercuei | 0:03b5121a232e | 567 | * Second check for chars outside the ASCII range |
| pcercuei | 0:03b5121a232e | 568 | */ |
| pcercuei | 0:03b5121a232e | 569 | cur = value; |
| pcercuei | 0:03b5121a232e | 570 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 571 | if (space) { |
| pcercuei | 0:03b5121a232e | 572 | while (IS_BLANK(c)) { |
| pcercuei | 0:03b5121a232e | 573 | cur += l; |
| pcercuei | 0:03b5121a232e | 574 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 575 | } |
| pcercuei | 0:03b5121a232e | 576 | } |
| pcercuei | 0:03b5121a232e | 577 | if ((!IS_LETTER(c)) && (c != '_') && (c != ':')) |
| pcercuei | 0:03b5121a232e | 578 | return(1); |
| pcercuei | 0:03b5121a232e | 579 | cur += l; |
| pcercuei | 0:03b5121a232e | 580 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 581 | while (IS_LETTER(c) || IS_DIGIT(c) || (c == '.') || (c == ':') || |
| pcercuei | 0:03b5121a232e | 582 | (c == '-') || (c == '_') || IS_COMBINING(c) || IS_EXTENDER(c)) { |
| pcercuei | 0:03b5121a232e | 583 | cur += l; |
| pcercuei | 0:03b5121a232e | 584 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 585 | } |
| pcercuei | 0:03b5121a232e | 586 | if (space) { |
| pcercuei | 0:03b5121a232e | 587 | while (IS_BLANK(c)) { |
| pcercuei | 0:03b5121a232e | 588 | cur += l; |
| pcercuei | 0:03b5121a232e | 589 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 590 | } |
| pcercuei | 0:03b5121a232e | 591 | } |
| pcercuei | 0:03b5121a232e | 592 | if (c != 0) |
| pcercuei | 0:03b5121a232e | 593 | return(1); |
| pcercuei | 0:03b5121a232e | 594 | return(0); |
| pcercuei | 0:03b5121a232e | 595 | } |
| pcercuei | 0:03b5121a232e | 596 | |
| pcercuei | 0:03b5121a232e | 597 | /** |
| pcercuei | 0:03b5121a232e | 598 | * xmlValidateNMToken: |
| pcercuei | 0:03b5121a232e | 599 | * @value: the value to check |
| pcercuei | 0:03b5121a232e | 600 | * @space: allow spaces in front and end of the string |
| pcercuei | 0:03b5121a232e | 601 | * |
| pcercuei | 0:03b5121a232e | 602 | * Check that a value conforms to the lexical space of NMToken |
| pcercuei | 0:03b5121a232e | 603 | * |
| pcercuei | 0:03b5121a232e | 604 | * Returns 0 if this validates, a positive error code number otherwise |
| pcercuei | 0:03b5121a232e | 605 | * and -1 in case of internal or API error. |
| pcercuei | 0:03b5121a232e | 606 | */ |
| pcercuei | 0:03b5121a232e | 607 | int |
| pcercuei | 0:03b5121a232e | 608 | xmlValidateNMToken(const xmlChar *value, int space) { |
| pcercuei | 0:03b5121a232e | 609 | const xmlChar *cur = value; |
| pcercuei | 0:03b5121a232e | 610 | int c,l; |
| pcercuei | 0:03b5121a232e | 611 | |
| pcercuei | 0:03b5121a232e | 612 | if (value == NULL) |
| pcercuei | 0:03b5121a232e | 613 | return(-1); |
| pcercuei | 0:03b5121a232e | 614 | /* |
| pcercuei | 0:03b5121a232e | 615 | * First quick algorithm for ASCII range |
| pcercuei | 0:03b5121a232e | 616 | */ |
| pcercuei | 0:03b5121a232e | 617 | if (space) |
| pcercuei | 0:03b5121a232e | 618 | while (IS_BLANK_CH(*cur)) cur++; |
| pcercuei | 0:03b5121a232e | 619 | if (((*cur >= 'a') && (*cur <= 'z')) || |
| pcercuei | 0:03b5121a232e | 620 | ((*cur >= 'A') && (*cur <= 'Z')) || |
| pcercuei | 0:03b5121a232e | 621 | ((*cur >= '0') && (*cur <= '9')) || |
| pcercuei | 0:03b5121a232e | 622 | (*cur == '_') || (*cur == '-') || (*cur == '.') || (*cur == ':')) |
| pcercuei | 0:03b5121a232e | 623 | cur++; |
| pcercuei | 0:03b5121a232e | 624 | else |
| pcercuei | 0:03b5121a232e | 625 | goto try_complex; |
| pcercuei | 0:03b5121a232e | 626 | while (((*cur >= 'a') && (*cur <= 'z')) || |
| pcercuei | 0:03b5121a232e | 627 | ((*cur >= 'A') && (*cur <= 'Z')) || |
| pcercuei | 0:03b5121a232e | 628 | ((*cur >= '0') && (*cur <= '9')) || |
| pcercuei | 0:03b5121a232e | 629 | (*cur == '_') || (*cur == '-') || (*cur == '.') || (*cur == ':')) |
| pcercuei | 0:03b5121a232e | 630 | cur++; |
| pcercuei | 0:03b5121a232e | 631 | if (space) |
| pcercuei | 0:03b5121a232e | 632 | while (IS_BLANK_CH(*cur)) cur++; |
| pcercuei | 0:03b5121a232e | 633 | if (*cur == 0) |
| pcercuei | 0:03b5121a232e | 634 | return(0); |
| pcercuei | 0:03b5121a232e | 635 | |
| pcercuei | 0:03b5121a232e | 636 | try_complex: |
| pcercuei | 0:03b5121a232e | 637 | /* |
| pcercuei | 0:03b5121a232e | 638 | * Second check for chars outside the ASCII range |
| pcercuei | 0:03b5121a232e | 639 | */ |
| pcercuei | 0:03b5121a232e | 640 | cur = value; |
| pcercuei | 0:03b5121a232e | 641 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 642 | if (space) { |
| pcercuei | 0:03b5121a232e | 643 | while (IS_BLANK(c)) { |
| pcercuei | 0:03b5121a232e | 644 | cur += l; |
| pcercuei | 0:03b5121a232e | 645 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 646 | } |
| pcercuei | 0:03b5121a232e | 647 | } |
| pcercuei | 0:03b5121a232e | 648 | if (!(IS_LETTER(c) || IS_DIGIT(c) || (c == '.') || (c == ':') || |
| pcercuei | 0:03b5121a232e | 649 | (c == '-') || (c == '_') || IS_COMBINING(c) || IS_EXTENDER(c))) |
| pcercuei | 0:03b5121a232e | 650 | return(1); |
| pcercuei | 0:03b5121a232e | 651 | cur += l; |
| pcercuei | 0:03b5121a232e | 652 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 653 | while (IS_LETTER(c) || IS_DIGIT(c) || (c == '.') || (c == ':') || |
| pcercuei | 0:03b5121a232e | 654 | (c == '-') || (c == '_') || IS_COMBINING(c) || IS_EXTENDER(c)) { |
| pcercuei | 0:03b5121a232e | 655 | cur += l; |
| pcercuei | 0:03b5121a232e | 656 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 657 | } |
| pcercuei | 0:03b5121a232e | 658 | if (space) { |
| pcercuei | 0:03b5121a232e | 659 | while (IS_BLANK(c)) { |
| pcercuei | 0:03b5121a232e | 660 | cur += l; |
| pcercuei | 0:03b5121a232e | 661 | c = CUR_SCHAR(cur, l); |
| pcercuei | 0:03b5121a232e | 662 | } |
| pcercuei | 0:03b5121a232e | 663 | } |
| pcercuei | 0:03b5121a232e | 664 | if (c != 0) |
| pcercuei | 0:03b5121a232e | 665 | return(1); |
| pcercuei | 0:03b5121a232e | 666 | return(0); |
| pcercuei | 0:03b5121a232e | 667 | } |
| pcercuei | 0:03b5121a232e | 668 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 669 | |
| pcercuei | 0:03b5121a232e | 670 | /************************************************************************ |
| pcercuei | 0:03b5121a232e | 671 | * * |
| pcercuei | 0:03b5121a232e | 672 | * Allocation and deallocation of basic structures * |
| pcercuei | 0:03b5121a232e | 673 | * * |
| pcercuei | 0:03b5121a232e | 674 | ************************************************************************/ |
| pcercuei | 0:03b5121a232e | 675 | |
| pcercuei | 0:03b5121a232e | 676 | /** |
| pcercuei | 0:03b5121a232e | 677 | * xmlSetBufferAllocationScheme: |
| pcercuei | 0:03b5121a232e | 678 | * @scheme: allocation method to use |
| pcercuei | 0:03b5121a232e | 679 | * |
| pcercuei | 0:03b5121a232e | 680 | * Set the buffer allocation method. Types are |
| pcercuei | 0:03b5121a232e | 681 | * XML_BUFFER_ALLOC_EXACT - use exact sizes, keeps memory usage down |
| pcercuei | 0:03b5121a232e | 682 | * XML_BUFFER_ALLOC_DOUBLEIT - double buffer when extra needed, |
| pcercuei | 0:03b5121a232e | 683 | * improves performance |
| pcercuei | 0:03b5121a232e | 684 | */ |
| pcercuei | 0:03b5121a232e | 685 | void |
| pcercuei | 0:03b5121a232e | 686 | xmlSetBufferAllocationScheme(xmlBufferAllocationScheme scheme) { |
| pcercuei | 0:03b5121a232e | 687 | if ((scheme == XML_BUFFER_ALLOC_EXACT) || |
| pcercuei | 0:03b5121a232e | 688 | (scheme == XML_BUFFER_ALLOC_DOUBLEIT) || |
| pcercuei | 0:03b5121a232e | 689 | (scheme == XML_BUFFER_ALLOC_HYBRID)) |
| pcercuei | 0:03b5121a232e | 690 | xmlBufferAllocScheme = scheme; |
| pcercuei | 0:03b5121a232e | 691 | } |
| pcercuei | 0:03b5121a232e | 692 | |
| pcercuei | 0:03b5121a232e | 693 | /** |
| pcercuei | 0:03b5121a232e | 694 | * xmlGetBufferAllocationScheme: |
| pcercuei | 0:03b5121a232e | 695 | * |
| pcercuei | 0:03b5121a232e | 696 | * Types are |
| pcercuei | 0:03b5121a232e | 697 | * XML_BUFFER_ALLOC_EXACT - use exact sizes, keeps memory usage down |
| pcercuei | 0:03b5121a232e | 698 | * XML_BUFFER_ALLOC_DOUBLEIT - double buffer when extra needed, |
| pcercuei | 0:03b5121a232e | 699 | * improves performance |
| pcercuei | 0:03b5121a232e | 700 | * XML_BUFFER_ALLOC_HYBRID - use exact sizes on small strings to keep memory usage tight |
| pcercuei | 0:03b5121a232e | 701 | * in normal usage, and doubleit on large strings to avoid |
| pcercuei | 0:03b5121a232e | 702 | * pathological performance. |
| pcercuei | 0:03b5121a232e | 703 | * |
| pcercuei | 0:03b5121a232e | 704 | * Returns the current allocation scheme |
| pcercuei | 0:03b5121a232e | 705 | */ |
| pcercuei | 0:03b5121a232e | 706 | xmlBufferAllocationScheme |
| pcercuei | 0:03b5121a232e | 707 | xmlGetBufferAllocationScheme(void) { |
| pcercuei | 0:03b5121a232e | 708 | return(xmlBufferAllocScheme); |
| pcercuei | 0:03b5121a232e | 709 | } |
| pcercuei | 0:03b5121a232e | 710 | |
| pcercuei | 0:03b5121a232e | 711 | /** |
| pcercuei | 0:03b5121a232e | 712 | * xmlNewNs: |
| pcercuei | 0:03b5121a232e | 713 | * @node: the element carrying the namespace |
| pcercuei | 0:03b5121a232e | 714 | * @href: the URI associated |
| pcercuei | 0:03b5121a232e | 715 | * @prefix: the prefix for the namespace |
| pcercuei | 0:03b5121a232e | 716 | * |
| pcercuei | 0:03b5121a232e | 717 | * Creation of a new Namespace. This function will refuse to create |
| pcercuei | 0:03b5121a232e | 718 | * a namespace with a similar prefix than an existing one present on this |
| pcercuei | 0:03b5121a232e | 719 | * node. |
| pcercuei | 0:03b5121a232e | 720 | * Note that for a default namespace, @prefix should be NULL. |
| pcercuei | 0:03b5121a232e | 721 | * |
| pcercuei | 0:03b5121a232e | 722 | * We use href==NULL in the case of an element creation where the namespace |
| pcercuei | 0:03b5121a232e | 723 | * was not defined. |
| pcercuei | 0:03b5121a232e | 724 | * |
| pcercuei | 0:03b5121a232e | 725 | * Returns a new namespace pointer or NULL |
| pcercuei | 0:03b5121a232e | 726 | */ |
| pcercuei | 0:03b5121a232e | 727 | xmlNsPtr |
| pcercuei | 0:03b5121a232e | 728 | xmlNewNs(xmlNodePtr node, const xmlChar *href, const xmlChar *prefix) { |
| pcercuei | 0:03b5121a232e | 729 | xmlNsPtr cur; |
| pcercuei | 0:03b5121a232e | 730 | |
| pcercuei | 0:03b5121a232e | 731 | if ((node != NULL) && (node->type != XML_ELEMENT_NODE)) |
| pcercuei | 0:03b5121a232e | 732 | return(NULL); |
| pcercuei | 0:03b5121a232e | 733 | |
| pcercuei | 0:03b5121a232e | 734 | if ((prefix != NULL) && (xmlStrEqual(prefix, BAD_CAST "xml"))) { |
| pcercuei | 0:03b5121a232e | 735 | /* xml namespace is predefined, no need to add it */ |
| pcercuei | 0:03b5121a232e | 736 | if (xmlStrEqual(href, XML_XML_NAMESPACE)) |
| pcercuei | 0:03b5121a232e | 737 | return(NULL); |
| pcercuei | 0:03b5121a232e | 738 | |
| pcercuei | 0:03b5121a232e | 739 | /* |
| pcercuei | 0:03b5121a232e | 740 | * Problem, this is an attempt to bind xml prefix to a wrong |
| pcercuei | 0:03b5121a232e | 741 | * namespace, which breaks |
| pcercuei | 0:03b5121a232e | 742 | * Namespace constraint: Reserved Prefixes and Namespace Names |
| pcercuei | 0:03b5121a232e | 743 | * from XML namespace. But documents authors may not care in |
| pcercuei | 0:03b5121a232e | 744 | * their context so let's proceed. |
| pcercuei | 0:03b5121a232e | 745 | */ |
| pcercuei | 0:03b5121a232e | 746 | } |
| pcercuei | 0:03b5121a232e | 747 | |
| pcercuei | 0:03b5121a232e | 748 | /* |
| pcercuei | 0:03b5121a232e | 749 | * Allocate a new Namespace and fill the fields. |
| pcercuei | 0:03b5121a232e | 750 | */ |
| pcercuei | 0:03b5121a232e | 751 | cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); |
| pcercuei | 0:03b5121a232e | 752 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 753 | xmlTreeErrMemory("building namespace"); |
| pcercuei | 0:03b5121a232e | 754 | return(NULL); |
| pcercuei | 0:03b5121a232e | 755 | } |
| pcercuei | 0:03b5121a232e | 756 | memset(cur, 0, sizeof(xmlNs)); |
| pcercuei | 0:03b5121a232e | 757 | cur->type = XML_LOCAL_NAMESPACE; |
| pcercuei | 0:03b5121a232e | 758 | |
| pcercuei | 0:03b5121a232e | 759 | if (href != NULL) |
| pcercuei | 0:03b5121a232e | 760 | cur->href = xmlStrdup(href); |
| pcercuei | 0:03b5121a232e | 761 | if (prefix != NULL) |
| pcercuei | 0:03b5121a232e | 762 | cur->prefix = xmlStrdup(prefix); |
| pcercuei | 0:03b5121a232e | 763 | |
| pcercuei | 0:03b5121a232e | 764 | /* |
| pcercuei | 0:03b5121a232e | 765 | * Add it at the end to preserve parsing order ... |
| pcercuei | 0:03b5121a232e | 766 | * and checks for existing use of the prefix |
| pcercuei | 0:03b5121a232e | 767 | */ |
| pcercuei | 0:03b5121a232e | 768 | if (node != NULL) { |
| pcercuei | 0:03b5121a232e | 769 | if (node->nsDef == NULL) { |
| pcercuei | 0:03b5121a232e | 770 | node->nsDef = cur; |
| pcercuei | 0:03b5121a232e | 771 | } else { |
| pcercuei | 0:03b5121a232e | 772 | xmlNsPtr prev = node->nsDef; |
| pcercuei | 0:03b5121a232e | 773 | |
| pcercuei | 0:03b5121a232e | 774 | if (((prev->prefix == NULL) && (cur->prefix == NULL)) || |
| pcercuei | 0:03b5121a232e | 775 | (xmlStrEqual(prev->prefix, cur->prefix))) { |
| pcercuei | 0:03b5121a232e | 776 | xmlFreeNs(cur); |
| pcercuei | 0:03b5121a232e | 777 | return(NULL); |
| pcercuei | 0:03b5121a232e | 778 | } |
| pcercuei | 0:03b5121a232e | 779 | while (prev->next != NULL) { |
| pcercuei | 0:03b5121a232e | 780 | prev = prev->next; |
| pcercuei | 0:03b5121a232e | 781 | if (((prev->prefix == NULL) && (cur->prefix == NULL)) || |
| pcercuei | 0:03b5121a232e | 782 | (xmlStrEqual(prev->prefix, cur->prefix))) { |
| pcercuei | 0:03b5121a232e | 783 | xmlFreeNs(cur); |
| pcercuei | 0:03b5121a232e | 784 | return(NULL); |
| pcercuei | 0:03b5121a232e | 785 | } |
| pcercuei | 0:03b5121a232e | 786 | } |
| pcercuei | 0:03b5121a232e | 787 | prev->next = cur; |
| pcercuei | 0:03b5121a232e | 788 | } |
| pcercuei | 0:03b5121a232e | 789 | } |
| pcercuei | 0:03b5121a232e | 790 | return(cur); |
| pcercuei | 0:03b5121a232e | 791 | } |
| pcercuei | 0:03b5121a232e | 792 | |
| pcercuei | 0:03b5121a232e | 793 | /** |
| pcercuei | 0:03b5121a232e | 794 | * xmlSetNs: |
| pcercuei | 0:03b5121a232e | 795 | * @node: a node in the document |
| pcercuei | 0:03b5121a232e | 796 | * @ns: a namespace pointer |
| pcercuei | 0:03b5121a232e | 797 | * |
| pcercuei | 0:03b5121a232e | 798 | * Associate a namespace to a node, a posteriori. |
| pcercuei | 0:03b5121a232e | 799 | */ |
| pcercuei | 0:03b5121a232e | 800 | void |
| pcercuei | 0:03b5121a232e | 801 | xmlSetNs(xmlNodePtr node, xmlNsPtr ns) { |
| pcercuei | 0:03b5121a232e | 802 | if (node == NULL) { |
| pcercuei | 0:03b5121a232e | 803 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 804 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 805 | "xmlSetNs: node == NULL\n"); |
| pcercuei | 0:03b5121a232e | 806 | #endif |
| pcercuei | 0:03b5121a232e | 807 | return; |
| pcercuei | 0:03b5121a232e | 808 | } |
| pcercuei | 0:03b5121a232e | 809 | if ((node->type == XML_ELEMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 810 | (node->type == XML_ATTRIBUTE_NODE)) |
| pcercuei | 0:03b5121a232e | 811 | node->ns = ns; |
| pcercuei | 0:03b5121a232e | 812 | } |
| pcercuei | 0:03b5121a232e | 813 | |
| pcercuei | 0:03b5121a232e | 814 | /** |
| pcercuei | 0:03b5121a232e | 815 | * xmlFreeNs: |
| pcercuei | 0:03b5121a232e | 816 | * @cur: the namespace pointer |
| pcercuei | 0:03b5121a232e | 817 | * |
| pcercuei | 0:03b5121a232e | 818 | * Free up the structures associated to a namespace |
| pcercuei | 0:03b5121a232e | 819 | */ |
| pcercuei | 0:03b5121a232e | 820 | void |
| pcercuei | 0:03b5121a232e | 821 | xmlFreeNs(xmlNsPtr cur) { |
| pcercuei | 0:03b5121a232e | 822 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 823 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 824 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 825 | "xmlFreeNs : ns == NULL\n"); |
| pcercuei | 0:03b5121a232e | 826 | #endif |
| pcercuei | 0:03b5121a232e | 827 | return; |
| pcercuei | 0:03b5121a232e | 828 | } |
| pcercuei | 0:03b5121a232e | 829 | if (cur->href != NULL) xmlFree((char *) cur->href); |
| pcercuei | 0:03b5121a232e | 830 | if (cur->prefix != NULL) xmlFree((char *) cur->prefix); |
| pcercuei | 0:03b5121a232e | 831 | xmlFree(cur); |
| pcercuei | 0:03b5121a232e | 832 | } |
| pcercuei | 0:03b5121a232e | 833 | |
| pcercuei | 0:03b5121a232e | 834 | /** |
| pcercuei | 0:03b5121a232e | 835 | * xmlFreeNsList: |
| pcercuei | 0:03b5121a232e | 836 | * @cur: the first namespace pointer |
| pcercuei | 0:03b5121a232e | 837 | * |
| pcercuei | 0:03b5121a232e | 838 | * Free up all the structures associated to the chained namespaces. |
| pcercuei | 0:03b5121a232e | 839 | */ |
| pcercuei | 0:03b5121a232e | 840 | void |
| pcercuei | 0:03b5121a232e | 841 | xmlFreeNsList(xmlNsPtr cur) { |
| pcercuei | 0:03b5121a232e | 842 | xmlNsPtr next; |
| pcercuei | 0:03b5121a232e | 843 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 844 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 845 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 846 | "xmlFreeNsList : ns == NULL\n"); |
| pcercuei | 0:03b5121a232e | 847 | #endif |
| pcercuei | 0:03b5121a232e | 848 | return; |
| pcercuei | 0:03b5121a232e | 849 | } |
| pcercuei | 0:03b5121a232e | 850 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 851 | next = cur->next; |
| pcercuei | 0:03b5121a232e | 852 | xmlFreeNs(cur); |
| pcercuei | 0:03b5121a232e | 853 | cur = next; |
| pcercuei | 0:03b5121a232e | 854 | } |
| pcercuei | 0:03b5121a232e | 855 | } |
| pcercuei | 0:03b5121a232e | 856 | |
| pcercuei | 0:03b5121a232e | 857 | /** |
| pcercuei | 0:03b5121a232e | 858 | * xmlNewDtd: |
| pcercuei | 0:03b5121a232e | 859 | * @doc: the document pointer |
| pcercuei | 0:03b5121a232e | 860 | * @name: the DTD name |
| pcercuei | 0:03b5121a232e | 861 | * @ExternalID: the external ID |
| pcercuei | 0:03b5121a232e | 862 | * @SystemID: the system ID |
| pcercuei | 0:03b5121a232e | 863 | * |
| pcercuei | 0:03b5121a232e | 864 | * Creation of a new DTD for the external subset. To create an |
| pcercuei | 0:03b5121a232e | 865 | * internal subset, use xmlCreateIntSubset(). |
| pcercuei | 0:03b5121a232e | 866 | * |
| pcercuei | 0:03b5121a232e | 867 | * Returns a pointer to the new DTD structure |
| pcercuei | 0:03b5121a232e | 868 | */ |
| pcercuei | 0:03b5121a232e | 869 | xmlDtdPtr |
| pcercuei | 0:03b5121a232e | 870 | xmlNewDtd(xmlDocPtr doc, const xmlChar *name, |
| pcercuei | 0:03b5121a232e | 871 | const xmlChar *ExternalID, const xmlChar *SystemID) { |
| pcercuei | 0:03b5121a232e | 872 | xmlDtdPtr cur; |
| pcercuei | 0:03b5121a232e | 873 | |
| pcercuei | 0:03b5121a232e | 874 | if ((doc != NULL) && (doc->extSubset != NULL)) { |
| pcercuei | 0:03b5121a232e | 875 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 876 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 877 | "xmlNewDtd(%s): document %s already have a DTD %s\n", |
| pcercuei | 0:03b5121a232e | 878 | /* !!! */ (char *) name, doc->name, |
| pcercuei | 0:03b5121a232e | 879 | /* !!! */ (char *)doc->extSubset->name); |
| pcercuei | 0:03b5121a232e | 880 | #endif |
| pcercuei | 0:03b5121a232e | 881 | return(NULL); |
| pcercuei | 0:03b5121a232e | 882 | } |
| pcercuei | 0:03b5121a232e | 883 | |
| pcercuei | 0:03b5121a232e | 884 | /* |
| pcercuei | 0:03b5121a232e | 885 | * Allocate a new DTD and fill the fields. |
| pcercuei | 0:03b5121a232e | 886 | */ |
| pcercuei | 0:03b5121a232e | 887 | cur = (xmlDtdPtr) xmlMalloc(sizeof(xmlDtd)); |
| pcercuei | 0:03b5121a232e | 888 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 889 | xmlTreeErrMemory("building DTD"); |
| pcercuei | 0:03b5121a232e | 890 | return(NULL); |
| pcercuei | 0:03b5121a232e | 891 | } |
| pcercuei | 0:03b5121a232e | 892 | memset(cur, 0 , sizeof(xmlDtd)); |
| pcercuei | 0:03b5121a232e | 893 | cur->type = XML_DTD_NODE; |
| pcercuei | 0:03b5121a232e | 894 | |
| pcercuei | 0:03b5121a232e | 895 | if (name != NULL) |
| pcercuei | 0:03b5121a232e | 896 | cur->name = xmlStrdup(name); |
| pcercuei | 0:03b5121a232e | 897 | if (ExternalID != NULL) |
| pcercuei | 0:03b5121a232e | 898 | cur->ExternalID = xmlStrdup(ExternalID); |
| pcercuei | 0:03b5121a232e | 899 | if (SystemID != NULL) |
| pcercuei | 0:03b5121a232e | 900 | cur->SystemID = xmlStrdup(SystemID); |
| pcercuei | 0:03b5121a232e | 901 | if (doc != NULL) |
| pcercuei | 0:03b5121a232e | 902 | doc->extSubset = cur; |
| pcercuei | 0:03b5121a232e | 903 | cur->doc = doc; |
| pcercuei | 0:03b5121a232e | 904 | |
| pcercuei | 0:03b5121a232e | 905 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 906 | xmlRegisterNodeDefaultValue((xmlNodePtr)cur); |
| pcercuei | 0:03b5121a232e | 907 | return(cur); |
| pcercuei | 0:03b5121a232e | 908 | } |
| pcercuei | 0:03b5121a232e | 909 | |
| pcercuei | 0:03b5121a232e | 910 | /** |
| pcercuei | 0:03b5121a232e | 911 | * xmlGetIntSubset: |
| pcercuei | 0:03b5121a232e | 912 | * @doc: the document pointer |
| pcercuei | 0:03b5121a232e | 913 | * |
| pcercuei | 0:03b5121a232e | 914 | * Get the internal subset of a document |
| pcercuei | 0:03b5121a232e | 915 | * Returns a pointer to the DTD structure or NULL if not found |
| pcercuei | 0:03b5121a232e | 916 | */ |
| pcercuei | 0:03b5121a232e | 917 | |
| pcercuei | 0:03b5121a232e | 918 | xmlDtdPtr |
| pcercuei | 0:03b5121a232e | 919 | xmlGetIntSubset(const xmlDoc *doc) { |
| pcercuei | 0:03b5121a232e | 920 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 921 | |
| pcercuei | 0:03b5121a232e | 922 | if (doc == NULL) |
| pcercuei | 0:03b5121a232e | 923 | return(NULL); |
| pcercuei | 0:03b5121a232e | 924 | cur = doc->children; |
| pcercuei | 0:03b5121a232e | 925 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 926 | if (cur->type == XML_DTD_NODE) |
| pcercuei | 0:03b5121a232e | 927 | return((xmlDtdPtr) cur); |
| pcercuei | 0:03b5121a232e | 928 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 929 | } |
| pcercuei | 0:03b5121a232e | 930 | return((xmlDtdPtr) doc->intSubset); |
| pcercuei | 0:03b5121a232e | 931 | } |
| pcercuei | 0:03b5121a232e | 932 | |
| pcercuei | 0:03b5121a232e | 933 | /** |
| pcercuei | 0:03b5121a232e | 934 | * xmlCreateIntSubset: |
| pcercuei | 0:03b5121a232e | 935 | * @doc: the document pointer |
| pcercuei | 0:03b5121a232e | 936 | * @name: the DTD name |
| pcercuei | 0:03b5121a232e | 937 | * @ExternalID: the external (PUBLIC) ID |
| pcercuei | 0:03b5121a232e | 938 | * @SystemID: the system ID |
| pcercuei | 0:03b5121a232e | 939 | * |
| pcercuei | 0:03b5121a232e | 940 | * Create the internal subset of a document |
| pcercuei | 0:03b5121a232e | 941 | * Returns a pointer to the new DTD structure |
| pcercuei | 0:03b5121a232e | 942 | */ |
| pcercuei | 0:03b5121a232e | 943 | xmlDtdPtr |
| pcercuei | 0:03b5121a232e | 944 | xmlCreateIntSubset(xmlDocPtr doc, const xmlChar *name, |
| pcercuei | 0:03b5121a232e | 945 | const xmlChar *ExternalID, const xmlChar *SystemID) { |
| pcercuei | 0:03b5121a232e | 946 | xmlDtdPtr cur; |
| pcercuei | 0:03b5121a232e | 947 | |
| pcercuei | 0:03b5121a232e | 948 | if ((doc != NULL) && (xmlGetIntSubset(doc) != NULL)) { |
| pcercuei | 0:03b5121a232e | 949 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 950 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 951 | |
| pcercuei | 0:03b5121a232e | 952 | "xmlCreateIntSubset(): document %s already have an internal subset\n", |
| pcercuei | 0:03b5121a232e | 953 | doc->name); |
| pcercuei | 0:03b5121a232e | 954 | #endif |
| pcercuei | 0:03b5121a232e | 955 | return(NULL); |
| pcercuei | 0:03b5121a232e | 956 | } |
| pcercuei | 0:03b5121a232e | 957 | |
| pcercuei | 0:03b5121a232e | 958 | /* |
| pcercuei | 0:03b5121a232e | 959 | * Allocate a new DTD and fill the fields. |
| pcercuei | 0:03b5121a232e | 960 | */ |
| pcercuei | 0:03b5121a232e | 961 | cur = (xmlDtdPtr) xmlMalloc(sizeof(xmlDtd)); |
| pcercuei | 0:03b5121a232e | 962 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 963 | xmlTreeErrMemory("building internal subset"); |
| pcercuei | 0:03b5121a232e | 964 | return(NULL); |
| pcercuei | 0:03b5121a232e | 965 | } |
| pcercuei | 0:03b5121a232e | 966 | memset(cur, 0, sizeof(xmlDtd)); |
| pcercuei | 0:03b5121a232e | 967 | cur->type = XML_DTD_NODE; |
| pcercuei | 0:03b5121a232e | 968 | |
| pcercuei | 0:03b5121a232e | 969 | if (name != NULL) { |
| pcercuei | 0:03b5121a232e | 970 | cur->name = xmlStrdup(name); |
| pcercuei | 0:03b5121a232e | 971 | if (cur->name == NULL) { |
| pcercuei | 0:03b5121a232e | 972 | xmlTreeErrMemory("building internal subset"); |
| pcercuei | 0:03b5121a232e | 973 | xmlFree(cur); |
| pcercuei | 0:03b5121a232e | 974 | return(NULL); |
| pcercuei | 0:03b5121a232e | 975 | } |
| pcercuei | 0:03b5121a232e | 976 | } |
| pcercuei | 0:03b5121a232e | 977 | if (ExternalID != NULL) { |
| pcercuei | 0:03b5121a232e | 978 | cur->ExternalID = xmlStrdup(ExternalID); |
| pcercuei | 0:03b5121a232e | 979 | if (cur->ExternalID == NULL) { |
| pcercuei | 0:03b5121a232e | 980 | xmlTreeErrMemory("building internal subset"); |
| pcercuei | 0:03b5121a232e | 981 | if (cur->name != NULL) |
| pcercuei | 0:03b5121a232e | 982 | xmlFree((char *)cur->name); |
| pcercuei | 0:03b5121a232e | 983 | xmlFree(cur); |
| pcercuei | 0:03b5121a232e | 984 | return(NULL); |
| pcercuei | 0:03b5121a232e | 985 | } |
| pcercuei | 0:03b5121a232e | 986 | } |
| pcercuei | 0:03b5121a232e | 987 | if (SystemID != NULL) { |
| pcercuei | 0:03b5121a232e | 988 | cur->SystemID = xmlStrdup(SystemID); |
| pcercuei | 0:03b5121a232e | 989 | if (cur->SystemID == NULL) { |
| pcercuei | 0:03b5121a232e | 990 | xmlTreeErrMemory("building internal subset"); |
| pcercuei | 0:03b5121a232e | 991 | if (cur->name != NULL) |
| pcercuei | 0:03b5121a232e | 992 | xmlFree((char *)cur->name); |
| pcercuei | 0:03b5121a232e | 993 | if (cur->ExternalID != NULL) |
| pcercuei | 0:03b5121a232e | 994 | xmlFree((char *)cur->ExternalID); |
| pcercuei | 0:03b5121a232e | 995 | xmlFree(cur); |
| pcercuei | 0:03b5121a232e | 996 | return(NULL); |
| pcercuei | 0:03b5121a232e | 997 | } |
| pcercuei | 0:03b5121a232e | 998 | } |
| pcercuei | 0:03b5121a232e | 999 | if (doc != NULL) { |
| pcercuei | 0:03b5121a232e | 1000 | doc->intSubset = cur; |
| pcercuei | 0:03b5121a232e | 1001 | cur->parent = doc; |
| pcercuei | 0:03b5121a232e | 1002 | cur->doc = doc; |
| pcercuei | 0:03b5121a232e | 1003 | if (doc->children == NULL) { |
| pcercuei | 0:03b5121a232e | 1004 | doc->children = (xmlNodePtr) cur; |
| pcercuei | 0:03b5121a232e | 1005 | doc->last = (xmlNodePtr) cur; |
| pcercuei | 0:03b5121a232e | 1006 | } else { |
| pcercuei | 0:03b5121a232e | 1007 | if (doc->type == XML_HTML_DOCUMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 1008 | xmlNodePtr prev; |
| pcercuei | 0:03b5121a232e | 1009 | |
| pcercuei | 0:03b5121a232e | 1010 | prev = doc->children; |
| pcercuei | 0:03b5121a232e | 1011 | prev->prev = (xmlNodePtr) cur; |
| pcercuei | 0:03b5121a232e | 1012 | cur->next = prev; |
| pcercuei | 0:03b5121a232e | 1013 | doc->children = (xmlNodePtr) cur; |
| pcercuei | 0:03b5121a232e | 1014 | } else { |
| pcercuei | 0:03b5121a232e | 1015 | xmlNodePtr next; |
| pcercuei | 0:03b5121a232e | 1016 | |
| pcercuei | 0:03b5121a232e | 1017 | next = doc->children; |
| pcercuei | 0:03b5121a232e | 1018 | while ((next != NULL) && (next->type != XML_ELEMENT_NODE)) |
| pcercuei | 0:03b5121a232e | 1019 | next = next->next; |
| pcercuei | 0:03b5121a232e | 1020 | if (next == NULL) { |
| pcercuei | 0:03b5121a232e | 1021 | cur->prev = doc->last; |
| pcercuei | 0:03b5121a232e | 1022 | cur->prev->next = (xmlNodePtr) cur; |
| pcercuei | 0:03b5121a232e | 1023 | cur->next = NULL; |
| pcercuei | 0:03b5121a232e | 1024 | doc->last = (xmlNodePtr) cur; |
| pcercuei | 0:03b5121a232e | 1025 | } else { |
| pcercuei | 0:03b5121a232e | 1026 | cur->next = next; |
| pcercuei | 0:03b5121a232e | 1027 | cur->prev = next->prev; |
| pcercuei | 0:03b5121a232e | 1028 | if (cur->prev == NULL) |
| pcercuei | 0:03b5121a232e | 1029 | doc->children = (xmlNodePtr) cur; |
| pcercuei | 0:03b5121a232e | 1030 | else |
| pcercuei | 0:03b5121a232e | 1031 | cur->prev->next = (xmlNodePtr) cur; |
| pcercuei | 0:03b5121a232e | 1032 | next->prev = (xmlNodePtr) cur; |
| pcercuei | 0:03b5121a232e | 1033 | } |
| pcercuei | 0:03b5121a232e | 1034 | } |
| pcercuei | 0:03b5121a232e | 1035 | } |
| pcercuei | 0:03b5121a232e | 1036 | } |
| pcercuei | 0:03b5121a232e | 1037 | |
| pcercuei | 0:03b5121a232e | 1038 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 1039 | xmlRegisterNodeDefaultValue((xmlNodePtr)cur); |
| pcercuei | 0:03b5121a232e | 1040 | return(cur); |
| pcercuei | 0:03b5121a232e | 1041 | } |
| pcercuei | 0:03b5121a232e | 1042 | |
| pcercuei | 0:03b5121a232e | 1043 | /** |
| pcercuei | 0:03b5121a232e | 1044 | * DICT_FREE: |
| pcercuei | 0:03b5121a232e | 1045 | * @str: a string |
| pcercuei | 0:03b5121a232e | 1046 | * |
| pcercuei | 0:03b5121a232e | 1047 | * Free a string if it is not owned by the "dict" dictionnary in the |
| pcercuei | 0:03b5121a232e | 1048 | * current scope |
| pcercuei | 0:03b5121a232e | 1049 | */ |
| pcercuei | 0:03b5121a232e | 1050 | #define DICT_FREE(str) \ |
| pcercuei | 0:03b5121a232e | 1051 | if ((str) && ((!dict) || \ |
| pcercuei | 0:03b5121a232e | 1052 | (xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \ |
| pcercuei | 0:03b5121a232e | 1053 | xmlFree((char *)(str)); |
| pcercuei | 0:03b5121a232e | 1054 | |
| pcercuei | 0:03b5121a232e | 1055 | |
| pcercuei | 0:03b5121a232e | 1056 | /** |
| pcercuei | 0:03b5121a232e | 1057 | * DICT_COPY: |
| pcercuei | 0:03b5121a232e | 1058 | * @str: a string |
| pcercuei | 0:03b5121a232e | 1059 | * |
| pcercuei | 0:03b5121a232e | 1060 | * Copy a string using a "dict" dictionnary in the current scope, |
| pcercuei | 0:03b5121a232e | 1061 | * if availabe. |
| pcercuei | 0:03b5121a232e | 1062 | */ |
| pcercuei | 0:03b5121a232e | 1063 | #define DICT_COPY(str, cpy) \ |
| pcercuei | 0:03b5121a232e | 1064 | if (str) { \ |
| pcercuei | 0:03b5121a232e | 1065 | if (dict) { \ |
| pcercuei | 0:03b5121a232e | 1066 | if (xmlDictOwns(dict, (const xmlChar *)(str))) \ |
| pcercuei | 0:03b5121a232e | 1067 | cpy = (xmlChar *) (str); \ |
| pcercuei | 0:03b5121a232e | 1068 | else \ |
| pcercuei | 0:03b5121a232e | 1069 | cpy = (xmlChar *) xmlDictLookup((dict), (const xmlChar *)(str), -1); \ |
| pcercuei | 0:03b5121a232e | 1070 | } else \ |
| pcercuei | 0:03b5121a232e | 1071 | cpy = xmlStrdup((const xmlChar *)(str)); } |
| pcercuei | 0:03b5121a232e | 1072 | |
| pcercuei | 0:03b5121a232e | 1073 | /** |
| pcercuei | 0:03b5121a232e | 1074 | * DICT_CONST_COPY: |
| pcercuei | 0:03b5121a232e | 1075 | * @str: a string |
| pcercuei | 0:03b5121a232e | 1076 | * |
| pcercuei | 0:03b5121a232e | 1077 | * Copy a string using a "dict" dictionnary in the current scope, |
| pcercuei | 0:03b5121a232e | 1078 | * if availabe. |
| pcercuei | 0:03b5121a232e | 1079 | */ |
| pcercuei | 0:03b5121a232e | 1080 | #define DICT_CONST_COPY(str, cpy) \ |
| pcercuei | 0:03b5121a232e | 1081 | if (str) { \ |
| pcercuei | 0:03b5121a232e | 1082 | if (dict) { \ |
| pcercuei | 0:03b5121a232e | 1083 | if (xmlDictOwns(dict, (const xmlChar *)(str))) \ |
| pcercuei | 0:03b5121a232e | 1084 | cpy = (const xmlChar *) (str); \ |
| pcercuei | 0:03b5121a232e | 1085 | else \ |
| pcercuei | 0:03b5121a232e | 1086 | cpy = xmlDictLookup((dict), (const xmlChar *)(str), -1); \ |
| pcercuei | 0:03b5121a232e | 1087 | } else \ |
| pcercuei | 0:03b5121a232e | 1088 | cpy = (const xmlChar *) xmlStrdup((const xmlChar *)(str)); } |
| pcercuei | 0:03b5121a232e | 1089 | |
| pcercuei | 0:03b5121a232e | 1090 | |
| pcercuei | 0:03b5121a232e | 1091 | /** |
| pcercuei | 0:03b5121a232e | 1092 | * xmlFreeDtd: |
| pcercuei | 0:03b5121a232e | 1093 | * @cur: the DTD structure to free up |
| pcercuei | 0:03b5121a232e | 1094 | * |
| pcercuei | 0:03b5121a232e | 1095 | * Free a DTD structure. |
| pcercuei | 0:03b5121a232e | 1096 | */ |
| pcercuei | 0:03b5121a232e | 1097 | void |
| pcercuei | 0:03b5121a232e | 1098 | xmlFreeDtd(xmlDtdPtr cur) { |
| pcercuei | 0:03b5121a232e | 1099 | xmlDictPtr dict = NULL; |
| pcercuei | 0:03b5121a232e | 1100 | |
| pcercuei | 0:03b5121a232e | 1101 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 1102 | return; |
| pcercuei | 0:03b5121a232e | 1103 | } |
| pcercuei | 0:03b5121a232e | 1104 | if (cur->doc != NULL) dict = cur->doc->dict; |
| pcercuei | 0:03b5121a232e | 1105 | |
| pcercuei | 0:03b5121a232e | 1106 | if ((__xmlRegisterCallbacks) && (xmlDeregisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 1107 | xmlDeregisterNodeDefaultValue((xmlNodePtr)cur); |
| pcercuei | 0:03b5121a232e | 1108 | |
| pcercuei | 0:03b5121a232e | 1109 | if (cur->children != NULL) { |
| pcercuei | 0:03b5121a232e | 1110 | xmlNodePtr next, c = cur->children; |
| pcercuei | 0:03b5121a232e | 1111 | |
| pcercuei | 0:03b5121a232e | 1112 | /* |
| pcercuei | 0:03b5121a232e | 1113 | * Cleanup all nodes which are not part of the specific lists |
| pcercuei | 0:03b5121a232e | 1114 | * of notations, elements, attributes and entities. |
| pcercuei | 0:03b5121a232e | 1115 | */ |
| pcercuei | 0:03b5121a232e | 1116 | while (c != NULL) { |
| pcercuei | 0:03b5121a232e | 1117 | next = c->next; |
| pcercuei | 0:03b5121a232e | 1118 | if ((c->type != XML_NOTATION_NODE) && |
| pcercuei | 0:03b5121a232e | 1119 | (c->type != XML_ELEMENT_DECL) && |
| pcercuei | 0:03b5121a232e | 1120 | (c->type != XML_ATTRIBUTE_DECL) && |
| pcercuei | 0:03b5121a232e | 1121 | (c->type != XML_ENTITY_DECL)) { |
| pcercuei | 0:03b5121a232e | 1122 | xmlUnlinkNode(c); |
| pcercuei | 0:03b5121a232e | 1123 | xmlFreeNode(c); |
| pcercuei | 0:03b5121a232e | 1124 | } |
| pcercuei | 0:03b5121a232e | 1125 | c = next; |
| pcercuei | 0:03b5121a232e | 1126 | } |
| pcercuei | 0:03b5121a232e | 1127 | } |
| pcercuei | 0:03b5121a232e | 1128 | DICT_FREE(cur->name) |
| pcercuei | 0:03b5121a232e | 1129 | DICT_FREE(cur->SystemID) |
| pcercuei | 0:03b5121a232e | 1130 | DICT_FREE(cur->ExternalID) |
| pcercuei | 0:03b5121a232e | 1131 | /* TODO !!! */ |
| pcercuei | 0:03b5121a232e | 1132 | if (cur->notations != NULL) |
| pcercuei | 0:03b5121a232e | 1133 | xmlFreeNotationTable((xmlNotationTablePtr) cur->notations); |
| pcercuei | 0:03b5121a232e | 1134 | |
| pcercuei | 0:03b5121a232e | 1135 | if (cur->elements != NULL) |
| pcercuei | 0:03b5121a232e | 1136 | xmlFreeElementTable((xmlElementTablePtr) cur->elements); |
| pcercuei | 0:03b5121a232e | 1137 | if (cur->attributes != NULL) |
| pcercuei | 0:03b5121a232e | 1138 | xmlFreeAttributeTable((xmlAttributeTablePtr) cur->attributes); |
| pcercuei | 0:03b5121a232e | 1139 | if (cur->entities != NULL) |
| pcercuei | 0:03b5121a232e | 1140 | xmlFreeEntitiesTable((xmlEntitiesTablePtr) cur->entities); |
| pcercuei | 0:03b5121a232e | 1141 | if (cur->pentities != NULL) |
| pcercuei | 0:03b5121a232e | 1142 | xmlFreeEntitiesTable((xmlEntitiesTablePtr) cur->pentities); |
| pcercuei | 0:03b5121a232e | 1143 | |
| pcercuei | 0:03b5121a232e | 1144 | xmlFree(cur); |
| pcercuei | 0:03b5121a232e | 1145 | } |
| pcercuei | 0:03b5121a232e | 1146 | |
| pcercuei | 0:03b5121a232e | 1147 | /** |
| pcercuei | 0:03b5121a232e | 1148 | * xmlNewDoc: |
| pcercuei | 0:03b5121a232e | 1149 | * @version: xmlChar string giving the version of XML "1.0" |
| pcercuei | 0:03b5121a232e | 1150 | * |
| pcercuei | 0:03b5121a232e | 1151 | * Creates a new XML document |
| pcercuei | 0:03b5121a232e | 1152 | * |
| pcercuei | 0:03b5121a232e | 1153 | * Returns a new document |
| pcercuei | 0:03b5121a232e | 1154 | */ |
| pcercuei | 0:03b5121a232e | 1155 | xmlDocPtr |
| pcercuei | 0:03b5121a232e | 1156 | xmlNewDoc(const xmlChar *version) { |
| pcercuei | 0:03b5121a232e | 1157 | xmlDocPtr cur; |
| pcercuei | 0:03b5121a232e | 1158 | |
| pcercuei | 0:03b5121a232e | 1159 | if (version == NULL) |
| pcercuei | 0:03b5121a232e | 1160 | version = (const xmlChar *) "1.0"; |
| pcercuei | 0:03b5121a232e | 1161 | |
| pcercuei | 0:03b5121a232e | 1162 | /* |
| pcercuei | 0:03b5121a232e | 1163 | * Allocate a new document and fill the fields. |
| pcercuei | 0:03b5121a232e | 1164 | */ |
| pcercuei | 0:03b5121a232e | 1165 | cur = (xmlDocPtr) xmlMalloc(sizeof(xmlDoc)); |
| pcercuei | 0:03b5121a232e | 1166 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 1167 | xmlTreeErrMemory("building doc"); |
| pcercuei | 0:03b5121a232e | 1168 | return(NULL); |
| pcercuei | 0:03b5121a232e | 1169 | } |
| pcercuei | 0:03b5121a232e | 1170 | memset(cur, 0, sizeof(xmlDoc)); |
| pcercuei | 0:03b5121a232e | 1171 | cur->type = XML_DOCUMENT_NODE; |
| pcercuei | 0:03b5121a232e | 1172 | |
| pcercuei | 0:03b5121a232e | 1173 | cur->version = xmlStrdup(version); |
| pcercuei | 0:03b5121a232e | 1174 | if (cur->version == NULL) { |
| pcercuei | 0:03b5121a232e | 1175 | xmlTreeErrMemory("building doc"); |
| pcercuei | 0:03b5121a232e | 1176 | xmlFree(cur); |
| pcercuei | 0:03b5121a232e | 1177 | return(NULL); |
| pcercuei | 0:03b5121a232e | 1178 | } |
| pcercuei | 0:03b5121a232e | 1179 | cur->standalone = -1; |
| pcercuei | 0:03b5121a232e | 1180 | cur->compression = -1; /* not initialized */ |
| pcercuei | 0:03b5121a232e | 1181 | cur->doc = cur; |
| pcercuei | 0:03b5121a232e | 1182 | cur->parseFlags = 0; |
| pcercuei | 0:03b5121a232e | 1183 | cur->properties = XML_DOC_USERBUILT; |
| pcercuei | 0:03b5121a232e | 1184 | /* |
| pcercuei | 0:03b5121a232e | 1185 | * The in memory encoding is always UTF8 |
| pcercuei | 0:03b5121a232e | 1186 | * This field will never change and would |
| pcercuei | 0:03b5121a232e | 1187 | * be obsolete if not for binary compatibility. |
| pcercuei | 0:03b5121a232e | 1188 | */ |
| pcercuei | 0:03b5121a232e | 1189 | cur->charset = XML_CHAR_ENCODING_UTF8; |
| pcercuei | 0:03b5121a232e | 1190 | |
| pcercuei | 0:03b5121a232e | 1191 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 1192 | xmlRegisterNodeDefaultValue((xmlNodePtr)cur); |
| pcercuei | 0:03b5121a232e | 1193 | return(cur); |
| pcercuei | 0:03b5121a232e | 1194 | } |
| pcercuei | 0:03b5121a232e | 1195 | |
| pcercuei | 0:03b5121a232e | 1196 | /** |
| pcercuei | 0:03b5121a232e | 1197 | * xmlFreeDoc: |
| pcercuei | 0:03b5121a232e | 1198 | * @cur: pointer to the document |
| pcercuei | 0:03b5121a232e | 1199 | * |
| pcercuei | 0:03b5121a232e | 1200 | * Free up all the structures used by a document, tree included. |
| pcercuei | 0:03b5121a232e | 1201 | */ |
| pcercuei | 0:03b5121a232e | 1202 | void |
| pcercuei | 0:03b5121a232e | 1203 | xmlFreeDoc(xmlDocPtr cur) { |
| pcercuei | 0:03b5121a232e | 1204 | xmlDtdPtr extSubset, intSubset; |
| pcercuei | 0:03b5121a232e | 1205 | xmlDictPtr dict = NULL; |
| pcercuei | 0:03b5121a232e | 1206 | |
| pcercuei | 0:03b5121a232e | 1207 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 1208 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 1209 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 1210 | "xmlFreeDoc : document == NULL\n"); |
| pcercuei | 0:03b5121a232e | 1211 | #endif |
| pcercuei | 0:03b5121a232e | 1212 | return; |
| pcercuei | 0:03b5121a232e | 1213 | } |
| pcercuei | 0:03b5121a232e | 1214 | #ifdef LIBXML_DEBUG_RUNTIME |
| pcercuei | 0:03b5121a232e | 1215 | #ifdef LIBXML_DEBUG_ENABLED |
| pcercuei | 0:03b5121a232e | 1216 | xmlDebugCheckDocument(stderr, cur); |
| pcercuei | 0:03b5121a232e | 1217 | #endif |
| pcercuei | 0:03b5121a232e | 1218 | #endif |
| pcercuei | 0:03b5121a232e | 1219 | |
| pcercuei | 0:03b5121a232e | 1220 | if (cur != NULL) dict = cur->dict; |
| pcercuei | 0:03b5121a232e | 1221 | |
| pcercuei | 0:03b5121a232e | 1222 | if ((__xmlRegisterCallbacks) && (xmlDeregisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 1223 | xmlDeregisterNodeDefaultValue((xmlNodePtr)cur); |
| pcercuei | 0:03b5121a232e | 1224 | |
| pcercuei | 0:03b5121a232e | 1225 | /* |
| pcercuei | 0:03b5121a232e | 1226 | * Do this before freeing the children list to avoid ID lookups |
| pcercuei | 0:03b5121a232e | 1227 | */ |
| pcercuei | 0:03b5121a232e | 1228 | if (cur->ids != NULL) xmlFreeIDTable((xmlIDTablePtr) cur->ids); |
| pcercuei | 0:03b5121a232e | 1229 | cur->ids = NULL; |
| pcercuei | 0:03b5121a232e | 1230 | if (cur->refs != NULL) xmlFreeRefTable((xmlRefTablePtr) cur->refs); |
| pcercuei | 0:03b5121a232e | 1231 | cur->refs = NULL; |
| pcercuei | 0:03b5121a232e | 1232 | extSubset = cur->extSubset; |
| pcercuei | 0:03b5121a232e | 1233 | intSubset = cur->intSubset; |
| pcercuei | 0:03b5121a232e | 1234 | if (intSubset == extSubset) |
| pcercuei | 0:03b5121a232e | 1235 | extSubset = NULL; |
| pcercuei | 0:03b5121a232e | 1236 | if (extSubset != NULL) { |
| pcercuei | 0:03b5121a232e | 1237 | xmlUnlinkNode((xmlNodePtr) cur->extSubset); |
| pcercuei | 0:03b5121a232e | 1238 | cur->extSubset = NULL; |
| pcercuei | 0:03b5121a232e | 1239 | xmlFreeDtd(extSubset); |
| pcercuei | 0:03b5121a232e | 1240 | } |
| pcercuei | 0:03b5121a232e | 1241 | if (intSubset != NULL) { |
| pcercuei | 0:03b5121a232e | 1242 | xmlUnlinkNode((xmlNodePtr) cur->intSubset); |
| pcercuei | 0:03b5121a232e | 1243 | cur->intSubset = NULL; |
| pcercuei | 0:03b5121a232e | 1244 | xmlFreeDtd(intSubset); |
| pcercuei | 0:03b5121a232e | 1245 | } |
| pcercuei | 0:03b5121a232e | 1246 | |
| pcercuei | 0:03b5121a232e | 1247 | if (cur->children != NULL) xmlFreeNodeList(cur->children); |
| pcercuei | 0:03b5121a232e | 1248 | if (cur->oldNs != NULL) xmlFreeNsList(cur->oldNs); |
| pcercuei | 0:03b5121a232e | 1249 | |
| pcercuei | 0:03b5121a232e | 1250 | DICT_FREE(cur->version) |
| pcercuei | 0:03b5121a232e | 1251 | DICT_FREE(cur->name) |
| pcercuei | 0:03b5121a232e | 1252 | DICT_FREE(cur->encoding) |
| pcercuei | 0:03b5121a232e | 1253 | DICT_FREE(cur->URL) |
| pcercuei | 0:03b5121a232e | 1254 | xmlFree(cur); |
| pcercuei | 0:03b5121a232e | 1255 | if (dict) xmlDictFree(dict); |
| pcercuei | 0:03b5121a232e | 1256 | } |
| pcercuei | 0:03b5121a232e | 1257 | |
| pcercuei | 0:03b5121a232e | 1258 | /** |
| pcercuei | 0:03b5121a232e | 1259 | * xmlStringLenGetNodeList: |
| pcercuei | 0:03b5121a232e | 1260 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 1261 | * @value: the value of the text |
| pcercuei | 0:03b5121a232e | 1262 | * @len: the length of the string value |
| pcercuei | 0:03b5121a232e | 1263 | * |
| pcercuei | 0:03b5121a232e | 1264 | * Parse the value string and build the node list associated. Should |
| pcercuei | 0:03b5121a232e | 1265 | * produce a flat tree with only TEXTs and ENTITY_REFs. |
| pcercuei | 0:03b5121a232e | 1266 | * Returns a pointer to the first child |
| pcercuei | 0:03b5121a232e | 1267 | */ |
| pcercuei | 0:03b5121a232e | 1268 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 1269 | xmlStringLenGetNodeList(const xmlDoc *doc, const xmlChar *value, int len) { |
| pcercuei | 0:03b5121a232e | 1270 | xmlNodePtr ret = NULL, last = NULL; |
| pcercuei | 0:03b5121a232e | 1271 | xmlNodePtr node; |
| pcercuei | 0:03b5121a232e | 1272 | xmlChar *val; |
| pcercuei | 0:03b5121a232e | 1273 | const xmlChar *cur = value, *end = cur + len; |
| pcercuei | 0:03b5121a232e | 1274 | const xmlChar *q; |
| pcercuei | 0:03b5121a232e | 1275 | xmlEntityPtr ent; |
| pcercuei | 0:03b5121a232e | 1276 | xmlBufPtr buf; |
| pcercuei | 0:03b5121a232e | 1277 | |
| pcercuei | 0:03b5121a232e | 1278 | if (value == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 1279 | |
| pcercuei | 0:03b5121a232e | 1280 | buf = xmlBufCreateSize(0); |
| pcercuei | 0:03b5121a232e | 1281 | if (buf == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 1282 | xmlBufSetAllocationScheme(buf, XML_BUFFER_ALLOC_HYBRID); |
| pcercuei | 0:03b5121a232e | 1283 | |
| pcercuei | 0:03b5121a232e | 1284 | q = cur; |
| pcercuei | 0:03b5121a232e | 1285 | while ((cur < end) && (*cur != 0)) { |
| pcercuei | 0:03b5121a232e | 1286 | if (cur[0] == '&') { |
| pcercuei | 0:03b5121a232e | 1287 | int charval = 0; |
| pcercuei | 0:03b5121a232e | 1288 | xmlChar tmp; |
| pcercuei | 0:03b5121a232e | 1289 | |
| pcercuei | 0:03b5121a232e | 1290 | /* |
| pcercuei | 0:03b5121a232e | 1291 | * Save the current text. |
| pcercuei | 0:03b5121a232e | 1292 | */ |
| pcercuei | 0:03b5121a232e | 1293 | if (cur != q) { |
| pcercuei | 0:03b5121a232e | 1294 | if (xmlBufAdd(buf, q, cur - q)) |
| pcercuei | 0:03b5121a232e | 1295 | goto out; |
| pcercuei | 0:03b5121a232e | 1296 | } |
| pcercuei | 0:03b5121a232e | 1297 | q = cur; |
| pcercuei | 0:03b5121a232e | 1298 | if ((cur + 2 < end) && (cur[1] == '#') && (cur[2] == 'x')) { |
| pcercuei | 0:03b5121a232e | 1299 | cur += 3; |
| pcercuei | 0:03b5121a232e | 1300 | if (cur < end) |
| pcercuei | 0:03b5121a232e | 1301 | tmp = *cur; |
| pcercuei | 0:03b5121a232e | 1302 | else |
| pcercuei | 0:03b5121a232e | 1303 | tmp = 0; |
| pcercuei | 0:03b5121a232e | 1304 | while (tmp != ';') { /* Non input consuming loop */ |
| pcercuei | 0:03b5121a232e | 1305 | if ((tmp >= '0') && (tmp <= '9')) |
| pcercuei | 0:03b5121a232e | 1306 | charval = charval * 16 + (tmp - '0'); |
| pcercuei | 0:03b5121a232e | 1307 | else if ((tmp >= 'a') && (tmp <= 'f')) |
| pcercuei | 0:03b5121a232e | 1308 | charval = charval * 16 + (tmp - 'a') + 10; |
| pcercuei | 0:03b5121a232e | 1309 | else if ((tmp >= 'A') && (tmp <= 'F')) |
| pcercuei | 0:03b5121a232e | 1310 | charval = charval * 16 + (tmp - 'A') + 10; |
| pcercuei | 0:03b5121a232e | 1311 | else { |
| pcercuei | 0:03b5121a232e | 1312 | xmlTreeErr(XML_TREE_INVALID_HEX, (xmlNodePtr) doc, |
| pcercuei | 0:03b5121a232e | 1313 | NULL); |
| pcercuei | 0:03b5121a232e | 1314 | charval = 0; |
| pcercuei | 0:03b5121a232e | 1315 | break; |
| pcercuei | 0:03b5121a232e | 1316 | } |
| pcercuei | 0:03b5121a232e | 1317 | cur++; |
| pcercuei | 0:03b5121a232e | 1318 | if (cur < end) |
| pcercuei | 0:03b5121a232e | 1319 | tmp = *cur; |
| pcercuei | 0:03b5121a232e | 1320 | else |
| pcercuei | 0:03b5121a232e | 1321 | tmp = 0; |
| pcercuei | 0:03b5121a232e | 1322 | } |
| pcercuei | 0:03b5121a232e | 1323 | if (tmp == ';') |
| pcercuei | 0:03b5121a232e | 1324 | cur++; |
| pcercuei | 0:03b5121a232e | 1325 | q = cur; |
| pcercuei | 0:03b5121a232e | 1326 | } else if ((cur + 1 < end) && (cur[1] == '#')) { |
| pcercuei | 0:03b5121a232e | 1327 | cur += 2; |
| pcercuei | 0:03b5121a232e | 1328 | if (cur < end) |
| pcercuei | 0:03b5121a232e | 1329 | tmp = *cur; |
| pcercuei | 0:03b5121a232e | 1330 | else |
| pcercuei | 0:03b5121a232e | 1331 | tmp = 0; |
| pcercuei | 0:03b5121a232e | 1332 | while (tmp != ';') { /* Non input consuming loops */ |
| pcercuei | 0:03b5121a232e | 1333 | if ((tmp >= '0') && (tmp <= '9')) |
| pcercuei | 0:03b5121a232e | 1334 | charval = charval * 10 + (tmp - '0'); |
| pcercuei | 0:03b5121a232e | 1335 | else { |
| pcercuei | 0:03b5121a232e | 1336 | xmlTreeErr(XML_TREE_INVALID_DEC, (xmlNodePtr) doc, |
| pcercuei | 0:03b5121a232e | 1337 | NULL); |
| pcercuei | 0:03b5121a232e | 1338 | charval = 0; |
| pcercuei | 0:03b5121a232e | 1339 | break; |
| pcercuei | 0:03b5121a232e | 1340 | } |
| pcercuei | 0:03b5121a232e | 1341 | cur++; |
| pcercuei | 0:03b5121a232e | 1342 | if (cur < end) |
| pcercuei | 0:03b5121a232e | 1343 | tmp = *cur; |
| pcercuei | 0:03b5121a232e | 1344 | else |
| pcercuei | 0:03b5121a232e | 1345 | tmp = 0; |
| pcercuei | 0:03b5121a232e | 1346 | } |
| pcercuei | 0:03b5121a232e | 1347 | if (tmp == ';') |
| pcercuei | 0:03b5121a232e | 1348 | cur++; |
| pcercuei | 0:03b5121a232e | 1349 | q = cur; |
| pcercuei | 0:03b5121a232e | 1350 | } else { |
| pcercuei | 0:03b5121a232e | 1351 | /* |
| pcercuei | 0:03b5121a232e | 1352 | * Read the entity string |
| pcercuei | 0:03b5121a232e | 1353 | */ |
| pcercuei | 0:03b5121a232e | 1354 | cur++; |
| pcercuei | 0:03b5121a232e | 1355 | q = cur; |
| pcercuei | 0:03b5121a232e | 1356 | while ((cur < end) && (*cur != 0) && (*cur != ';')) cur++; |
| pcercuei | 0:03b5121a232e | 1357 | if ((cur >= end) || (*cur == 0)) { |
| pcercuei | 0:03b5121a232e | 1358 | xmlTreeErr(XML_TREE_UNTERMINATED_ENTITY, (xmlNodePtr) doc, |
| pcercuei | 0:03b5121a232e | 1359 | (const char *) q); |
| pcercuei | 0:03b5121a232e | 1360 | goto out; |
| pcercuei | 0:03b5121a232e | 1361 | } |
| pcercuei | 0:03b5121a232e | 1362 | if (cur != q) { |
| pcercuei | 0:03b5121a232e | 1363 | /* |
| pcercuei | 0:03b5121a232e | 1364 | * Predefined entities don't generate nodes |
| pcercuei | 0:03b5121a232e | 1365 | */ |
| pcercuei | 0:03b5121a232e | 1366 | val = xmlStrndup(q, cur - q); |
| pcercuei | 0:03b5121a232e | 1367 | ent = xmlGetDocEntity(doc, val); |
| pcercuei | 0:03b5121a232e | 1368 | if ((ent != NULL) && |
| pcercuei | 0:03b5121a232e | 1369 | (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { |
| pcercuei | 0:03b5121a232e | 1370 | |
| pcercuei | 0:03b5121a232e | 1371 | if (xmlBufCat(buf, ent->content)) |
| pcercuei | 0:03b5121a232e | 1372 | goto out; |
| pcercuei | 0:03b5121a232e | 1373 | |
| pcercuei | 0:03b5121a232e | 1374 | } else { |
| pcercuei | 0:03b5121a232e | 1375 | /* |
| pcercuei | 0:03b5121a232e | 1376 | * Flush buffer so far |
| pcercuei | 0:03b5121a232e | 1377 | */ |
| pcercuei | 0:03b5121a232e | 1378 | if (!xmlBufIsEmpty(buf)) { |
| pcercuei | 0:03b5121a232e | 1379 | node = xmlNewDocText(doc, NULL); |
| pcercuei | 0:03b5121a232e | 1380 | if (node == NULL) { |
| pcercuei | 0:03b5121a232e | 1381 | if (val != NULL) xmlFree(val); |
| pcercuei | 0:03b5121a232e | 1382 | goto out; |
| pcercuei | 0:03b5121a232e | 1383 | } |
| pcercuei | 0:03b5121a232e | 1384 | node->content = xmlBufDetach(buf); |
| pcercuei | 0:03b5121a232e | 1385 | |
| pcercuei | 0:03b5121a232e | 1386 | if (last == NULL) { |
| pcercuei | 0:03b5121a232e | 1387 | last = ret = node; |
| pcercuei | 0:03b5121a232e | 1388 | } else { |
| pcercuei | 0:03b5121a232e | 1389 | last = xmlAddNextSibling(last, node); |
| pcercuei | 0:03b5121a232e | 1390 | } |
| pcercuei | 0:03b5121a232e | 1391 | } |
| pcercuei | 0:03b5121a232e | 1392 | |
| pcercuei | 0:03b5121a232e | 1393 | /* |
| pcercuei | 0:03b5121a232e | 1394 | * Create a new REFERENCE_REF node |
| pcercuei | 0:03b5121a232e | 1395 | */ |
| pcercuei | 0:03b5121a232e | 1396 | node = xmlNewReference(doc, val); |
| pcercuei | 0:03b5121a232e | 1397 | if (node == NULL) { |
| pcercuei | 0:03b5121a232e | 1398 | if (val != NULL) xmlFree(val); |
| pcercuei | 0:03b5121a232e | 1399 | goto out; |
| pcercuei | 0:03b5121a232e | 1400 | } |
| pcercuei | 0:03b5121a232e | 1401 | else if ((ent != NULL) && (ent->children == NULL)) { |
| pcercuei | 0:03b5121a232e | 1402 | xmlNodePtr temp; |
| pcercuei | 0:03b5121a232e | 1403 | |
| pcercuei | 0:03b5121a232e | 1404 | ent->children = xmlStringGetNodeList(doc, |
| pcercuei | 0:03b5121a232e | 1405 | (const xmlChar*)node->content); |
| pcercuei | 0:03b5121a232e | 1406 | ent->owner = 1; |
| pcercuei | 0:03b5121a232e | 1407 | temp = ent->children; |
| pcercuei | 0:03b5121a232e | 1408 | while (temp) { |
| pcercuei | 0:03b5121a232e | 1409 | temp->parent = (xmlNodePtr)ent; |
| pcercuei | 0:03b5121a232e | 1410 | ent->last = temp; |
| pcercuei | 0:03b5121a232e | 1411 | temp = temp->next; |
| pcercuei | 0:03b5121a232e | 1412 | } |
| pcercuei | 0:03b5121a232e | 1413 | } |
| pcercuei | 0:03b5121a232e | 1414 | if (last == NULL) { |
| pcercuei | 0:03b5121a232e | 1415 | last = ret = node; |
| pcercuei | 0:03b5121a232e | 1416 | } else { |
| pcercuei | 0:03b5121a232e | 1417 | last = xmlAddNextSibling(last, node); |
| pcercuei | 0:03b5121a232e | 1418 | } |
| pcercuei | 0:03b5121a232e | 1419 | } |
| pcercuei | 0:03b5121a232e | 1420 | xmlFree(val); |
| pcercuei | 0:03b5121a232e | 1421 | } |
| pcercuei | 0:03b5121a232e | 1422 | cur++; |
| pcercuei | 0:03b5121a232e | 1423 | q = cur; |
| pcercuei | 0:03b5121a232e | 1424 | } |
| pcercuei | 0:03b5121a232e | 1425 | if (charval != 0) { |
| pcercuei | 0:03b5121a232e | 1426 | xmlChar buffer[10]; |
| pcercuei | 0:03b5121a232e | 1427 | int l; |
| pcercuei | 0:03b5121a232e | 1428 | |
| pcercuei | 0:03b5121a232e | 1429 | l = xmlCopyCharMultiByte(buffer, charval); |
| pcercuei | 0:03b5121a232e | 1430 | buffer[l] = 0; |
| pcercuei | 0:03b5121a232e | 1431 | |
| pcercuei | 0:03b5121a232e | 1432 | if (xmlBufCat(buf, buffer)) |
| pcercuei | 0:03b5121a232e | 1433 | goto out; |
| pcercuei | 0:03b5121a232e | 1434 | charval = 0; |
| pcercuei | 0:03b5121a232e | 1435 | } |
| pcercuei | 0:03b5121a232e | 1436 | } else |
| pcercuei | 0:03b5121a232e | 1437 | cur++; |
| pcercuei | 0:03b5121a232e | 1438 | } |
| pcercuei | 0:03b5121a232e | 1439 | |
| pcercuei | 0:03b5121a232e | 1440 | if (cur != q) { |
| pcercuei | 0:03b5121a232e | 1441 | /* |
| pcercuei | 0:03b5121a232e | 1442 | * Handle the last piece of text. |
| pcercuei | 0:03b5121a232e | 1443 | */ |
| pcercuei | 0:03b5121a232e | 1444 | if (xmlBufAdd(buf, q, cur - q)) |
| pcercuei | 0:03b5121a232e | 1445 | goto out; |
| pcercuei | 0:03b5121a232e | 1446 | } |
| pcercuei | 0:03b5121a232e | 1447 | |
| pcercuei | 0:03b5121a232e | 1448 | if (!xmlBufIsEmpty(buf)) { |
| pcercuei | 0:03b5121a232e | 1449 | node = xmlNewDocText(doc, NULL); |
| pcercuei | 0:03b5121a232e | 1450 | if (node == NULL) goto out; |
| pcercuei | 0:03b5121a232e | 1451 | node->content = xmlBufDetach(buf); |
| pcercuei | 0:03b5121a232e | 1452 | |
| pcercuei | 0:03b5121a232e | 1453 | if (last == NULL) { |
| pcercuei | 0:03b5121a232e | 1454 | ret = node; |
| pcercuei | 0:03b5121a232e | 1455 | } else { |
| pcercuei | 0:03b5121a232e | 1456 | xmlAddNextSibling(last, node); |
| pcercuei | 0:03b5121a232e | 1457 | } |
| pcercuei | 0:03b5121a232e | 1458 | } else if (ret == NULL) { |
| pcercuei | 0:03b5121a232e | 1459 | ret = xmlNewDocText(doc, BAD_CAST ""); |
| pcercuei | 0:03b5121a232e | 1460 | } |
| pcercuei | 0:03b5121a232e | 1461 | |
| pcercuei | 0:03b5121a232e | 1462 | out: |
| pcercuei | 0:03b5121a232e | 1463 | xmlBufFree(buf); |
| pcercuei | 0:03b5121a232e | 1464 | return(ret); |
| pcercuei | 0:03b5121a232e | 1465 | } |
| pcercuei | 0:03b5121a232e | 1466 | |
| pcercuei | 0:03b5121a232e | 1467 | /** |
| pcercuei | 0:03b5121a232e | 1468 | * xmlStringGetNodeList: |
| pcercuei | 0:03b5121a232e | 1469 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 1470 | * @value: the value of the attribute |
| pcercuei | 0:03b5121a232e | 1471 | * |
| pcercuei | 0:03b5121a232e | 1472 | * Parse the value string and build the node list associated. Should |
| pcercuei | 0:03b5121a232e | 1473 | * produce a flat tree with only TEXTs and ENTITY_REFs. |
| pcercuei | 0:03b5121a232e | 1474 | * Returns a pointer to the first child |
| pcercuei | 0:03b5121a232e | 1475 | */ |
| pcercuei | 0:03b5121a232e | 1476 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 1477 | xmlStringGetNodeList(const xmlDoc *doc, const xmlChar *value) { |
| pcercuei | 0:03b5121a232e | 1478 | xmlNodePtr ret = NULL, last = NULL; |
| pcercuei | 0:03b5121a232e | 1479 | xmlNodePtr node; |
| pcercuei | 0:03b5121a232e | 1480 | xmlChar *val; |
| pcercuei | 0:03b5121a232e | 1481 | const xmlChar *cur = value; |
| pcercuei | 0:03b5121a232e | 1482 | const xmlChar *q; |
| pcercuei | 0:03b5121a232e | 1483 | xmlEntityPtr ent; |
| pcercuei | 0:03b5121a232e | 1484 | xmlBufPtr buf; |
| pcercuei | 0:03b5121a232e | 1485 | |
| pcercuei | 0:03b5121a232e | 1486 | if (value == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 1487 | |
| pcercuei | 0:03b5121a232e | 1488 | buf = xmlBufCreateSize(0); |
| pcercuei | 0:03b5121a232e | 1489 | if (buf == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 1490 | xmlBufSetAllocationScheme(buf, XML_BUFFER_ALLOC_HYBRID); |
| pcercuei | 0:03b5121a232e | 1491 | |
| pcercuei | 0:03b5121a232e | 1492 | q = cur; |
| pcercuei | 0:03b5121a232e | 1493 | while (*cur != 0) { |
| pcercuei | 0:03b5121a232e | 1494 | if (cur[0] == '&') { |
| pcercuei | 0:03b5121a232e | 1495 | int charval = 0; |
| pcercuei | 0:03b5121a232e | 1496 | xmlChar tmp; |
| pcercuei | 0:03b5121a232e | 1497 | |
| pcercuei | 0:03b5121a232e | 1498 | /* |
| pcercuei | 0:03b5121a232e | 1499 | * Save the current text. |
| pcercuei | 0:03b5121a232e | 1500 | */ |
| pcercuei | 0:03b5121a232e | 1501 | if (cur != q) { |
| pcercuei | 0:03b5121a232e | 1502 | if (xmlBufAdd(buf, q, cur - q)) |
| pcercuei | 0:03b5121a232e | 1503 | goto out; |
| pcercuei | 0:03b5121a232e | 1504 | } |
| pcercuei | 0:03b5121a232e | 1505 | q = cur; |
| pcercuei | 0:03b5121a232e | 1506 | if ((cur[1] == '#') && (cur[2] == 'x')) { |
| pcercuei | 0:03b5121a232e | 1507 | cur += 3; |
| pcercuei | 0:03b5121a232e | 1508 | tmp = *cur; |
| pcercuei | 0:03b5121a232e | 1509 | while (tmp != ';') { /* Non input consuming loop */ |
| pcercuei | 0:03b5121a232e | 1510 | if ((tmp >= '0') && (tmp <= '9')) |
| pcercuei | 0:03b5121a232e | 1511 | charval = charval * 16 + (tmp - '0'); |
| pcercuei | 0:03b5121a232e | 1512 | else if ((tmp >= 'a') && (tmp <= 'f')) |
| pcercuei | 0:03b5121a232e | 1513 | charval = charval * 16 + (tmp - 'a') + 10; |
| pcercuei | 0:03b5121a232e | 1514 | else if ((tmp >= 'A') && (tmp <= 'F')) |
| pcercuei | 0:03b5121a232e | 1515 | charval = charval * 16 + (tmp - 'A') + 10; |
| pcercuei | 0:03b5121a232e | 1516 | else { |
| pcercuei | 0:03b5121a232e | 1517 | xmlTreeErr(XML_TREE_INVALID_HEX, (xmlNodePtr) doc, |
| pcercuei | 0:03b5121a232e | 1518 | NULL); |
| pcercuei | 0:03b5121a232e | 1519 | charval = 0; |
| pcercuei | 0:03b5121a232e | 1520 | break; |
| pcercuei | 0:03b5121a232e | 1521 | } |
| pcercuei | 0:03b5121a232e | 1522 | cur++; |
| pcercuei | 0:03b5121a232e | 1523 | tmp = *cur; |
| pcercuei | 0:03b5121a232e | 1524 | } |
| pcercuei | 0:03b5121a232e | 1525 | if (tmp == ';') |
| pcercuei | 0:03b5121a232e | 1526 | cur++; |
| pcercuei | 0:03b5121a232e | 1527 | q = cur; |
| pcercuei | 0:03b5121a232e | 1528 | } else if (cur[1] == '#') { |
| pcercuei | 0:03b5121a232e | 1529 | cur += 2; |
| pcercuei | 0:03b5121a232e | 1530 | tmp = *cur; |
| pcercuei | 0:03b5121a232e | 1531 | while (tmp != ';') { /* Non input consuming loops */ |
| pcercuei | 0:03b5121a232e | 1532 | if ((tmp >= '0') && (tmp <= '9')) |
| pcercuei | 0:03b5121a232e | 1533 | charval = charval * 10 + (tmp - '0'); |
| pcercuei | 0:03b5121a232e | 1534 | else { |
| pcercuei | 0:03b5121a232e | 1535 | xmlTreeErr(XML_TREE_INVALID_DEC, (xmlNodePtr) doc, |
| pcercuei | 0:03b5121a232e | 1536 | NULL); |
| pcercuei | 0:03b5121a232e | 1537 | charval = 0; |
| pcercuei | 0:03b5121a232e | 1538 | break; |
| pcercuei | 0:03b5121a232e | 1539 | } |
| pcercuei | 0:03b5121a232e | 1540 | cur++; |
| pcercuei | 0:03b5121a232e | 1541 | tmp = *cur; |
| pcercuei | 0:03b5121a232e | 1542 | } |
| pcercuei | 0:03b5121a232e | 1543 | if (tmp == ';') |
| pcercuei | 0:03b5121a232e | 1544 | cur++; |
| pcercuei | 0:03b5121a232e | 1545 | q = cur; |
| pcercuei | 0:03b5121a232e | 1546 | } else { |
| pcercuei | 0:03b5121a232e | 1547 | /* |
| pcercuei | 0:03b5121a232e | 1548 | * Read the entity string |
| pcercuei | 0:03b5121a232e | 1549 | */ |
| pcercuei | 0:03b5121a232e | 1550 | cur++; |
| pcercuei | 0:03b5121a232e | 1551 | q = cur; |
| pcercuei | 0:03b5121a232e | 1552 | while ((*cur != 0) && (*cur != ';')) cur++; |
| pcercuei | 0:03b5121a232e | 1553 | if (*cur == 0) { |
| pcercuei | 0:03b5121a232e | 1554 | xmlTreeErr(XML_TREE_UNTERMINATED_ENTITY, |
| pcercuei | 0:03b5121a232e | 1555 | (xmlNodePtr) doc, (const char *) q); |
| pcercuei | 0:03b5121a232e | 1556 | goto out; |
| pcercuei | 0:03b5121a232e | 1557 | } |
| pcercuei | 0:03b5121a232e | 1558 | if (cur != q) { |
| pcercuei | 0:03b5121a232e | 1559 | /* |
| pcercuei | 0:03b5121a232e | 1560 | * Predefined entities don't generate nodes |
| pcercuei | 0:03b5121a232e | 1561 | */ |
| pcercuei | 0:03b5121a232e | 1562 | val = xmlStrndup(q, cur - q); |
| pcercuei | 0:03b5121a232e | 1563 | ent = xmlGetDocEntity(doc, val); |
| pcercuei | 0:03b5121a232e | 1564 | if ((ent != NULL) && |
| pcercuei | 0:03b5121a232e | 1565 | (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { |
| pcercuei | 0:03b5121a232e | 1566 | |
| pcercuei | 0:03b5121a232e | 1567 | if (xmlBufCat(buf, ent->content)) |
| pcercuei | 0:03b5121a232e | 1568 | goto out; |
| pcercuei | 0:03b5121a232e | 1569 | |
| pcercuei | 0:03b5121a232e | 1570 | } else { |
| pcercuei | 0:03b5121a232e | 1571 | /* |
| pcercuei | 0:03b5121a232e | 1572 | * Flush buffer so far |
| pcercuei | 0:03b5121a232e | 1573 | */ |
| pcercuei | 0:03b5121a232e | 1574 | if (!xmlBufIsEmpty(buf)) { |
| pcercuei | 0:03b5121a232e | 1575 | node = xmlNewDocText(doc, NULL); |
| pcercuei | 0:03b5121a232e | 1576 | node->content = xmlBufDetach(buf); |
| pcercuei | 0:03b5121a232e | 1577 | |
| pcercuei | 0:03b5121a232e | 1578 | if (last == NULL) { |
| pcercuei | 0:03b5121a232e | 1579 | last = ret = node; |
| pcercuei | 0:03b5121a232e | 1580 | } else { |
| pcercuei | 0:03b5121a232e | 1581 | last = xmlAddNextSibling(last, node); |
| pcercuei | 0:03b5121a232e | 1582 | } |
| pcercuei | 0:03b5121a232e | 1583 | } |
| pcercuei | 0:03b5121a232e | 1584 | |
| pcercuei | 0:03b5121a232e | 1585 | /* |
| pcercuei | 0:03b5121a232e | 1586 | * Create a new REFERENCE_REF node |
| pcercuei | 0:03b5121a232e | 1587 | */ |
| pcercuei | 0:03b5121a232e | 1588 | node = xmlNewReference(doc, val); |
| pcercuei | 0:03b5121a232e | 1589 | if (node == NULL) { |
| pcercuei | 0:03b5121a232e | 1590 | if (val != NULL) xmlFree(val); |
| pcercuei | 0:03b5121a232e | 1591 | goto out; |
| pcercuei | 0:03b5121a232e | 1592 | } |
| pcercuei | 0:03b5121a232e | 1593 | else if ((ent != NULL) && (ent->children == NULL)) { |
| pcercuei | 0:03b5121a232e | 1594 | xmlNodePtr temp; |
| pcercuei | 0:03b5121a232e | 1595 | |
| pcercuei | 0:03b5121a232e | 1596 | ent->children = xmlStringGetNodeList(doc, |
| pcercuei | 0:03b5121a232e | 1597 | (const xmlChar*)node->content); |
| pcercuei | 0:03b5121a232e | 1598 | ent->owner = 1; |
| pcercuei | 0:03b5121a232e | 1599 | temp = ent->children; |
| pcercuei | 0:03b5121a232e | 1600 | while (temp) { |
| pcercuei | 0:03b5121a232e | 1601 | temp->parent = (xmlNodePtr)ent; |
| pcercuei | 0:03b5121a232e | 1602 | temp = temp->next; |
| pcercuei | 0:03b5121a232e | 1603 | } |
| pcercuei | 0:03b5121a232e | 1604 | } |
| pcercuei | 0:03b5121a232e | 1605 | if (last == NULL) { |
| pcercuei | 0:03b5121a232e | 1606 | last = ret = node; |
| pcercuei | 0:03b5121a232e | 1607 | } else { |
| pcercuei | 0:03b5121a232e | 1608 | last = xmlAddNextSibling(last, node); |
| pcercuei | 0:03b5121a232e | 1609 | } |
| pcercuei | 0:03b5121a232e | 1610 | } |
| pcercuei | 0:03b5121a232e | 1611 | xmlFree(val); |
| pcercuei | 0:03b5121a232e | 1612 | } |
| pcercuei | 0:03b5121a232e | 1613 | cur++; |
| pcercuei | 0:03b5121a232e | 1614 | q = cur; |
| pcercuei | 0:03b5121a232e | 1615 | } |
| pcercuei | 0:03b5121a232e | 1616 | if (charval != 0) { |
| pcercuei | 0:03b5121a232e | 1617 | xmlChar buffer[10]; |
| pcercuei | 0:03b5121a232e | 1618 | int len; |
| pcercuei | 0:03b5121a232e | 1619 | |
| pcercuei | 0:03b5121a232e | 1620 | len = xmlCopyCharMultiByte(buffer, charval); |
| pcercuei | 0:03b5121a232e | 1621 | buffer[len] = 0; |
| pcercuei | 0:03b5121a232e | 1622 | |
| pcercuei | 0:03b5121a232e | 1623 | if (xmlBufCat(buf, buffer)) |
| pcercuei | 0:03b5121a232e | 1624 | goto out; |
| pcercuei | 0:03b5121a232e | 1625 | charval = 0; |
| pcercuei | 0:03b5121a232e | 1626 | } |
| pcercuei | 0:03b5121a232e | 1627 | } else |
| pcercuei | 0:03b5121a232e | 1628 | cur++; |
| pcercuei | 0:03b5121a232e | 1629 | } |
| pcercuei | 0:03b5121a232e | 1630 | if ((cur != q) || (ret == NULL)) { |
| pcercuei | 0:03b5121a232e | 1631 | /* |
| pcercuei | 0:03b5121a232e | 1632 | * Handle the last piece of text. |
| pcercuei | 0:03b5121a232e | 1633 | */ |
| pcercuei | 0:03b5121a232e | 1634 | xmlBufAdd(buf, q, cur - q); |
| pcercuei | 0:03b5121a232e | 1635 | } |
| pcercuei | 0:03b5121a232e | 1636 | |
| pcercuei | 0:03b5121a232e | 1637 | if (!xmlBufIsEmpty(buf)) { |
| pcercuei | 0:03b5121a232e | 1638 | node = xmlNewDocText(doc, NULL); |
| pcercuei | 0:03b5121a232e | 1639 | node->content = xmlBufDetach(buf); |
| pcercuei | 0:03b5121a232e | 1640 | |
| pcercuei | 0:03b5121a232e | 1641 | if (last == NULL) { |
| pcercuei | 0:03b5121a232e | 1642 | ret = node; |
| pcercuei | 0:03b5121a232e | 1643 | } else { |
| pcercuei | 0:03b5121a232e | 1644 | xmlAddNextSibling(last, node); |
| pcercuei | 0:03b5121a232e | 1645 | } |
| pcercuei | 0:03b5121a232e | 1646 | } |
| pcercuei | 0:03b5121a232e | 1647 | |
| pcercuei | 0:03b5121a232e | 1648 | out: |
| pcercuei | 0:03b5121a232e | 1649 | xmlBufFree(buf); |
| pcercuei | 0:03b5121a232e | 1650 | return(ret); |
| pcercuei | 0:03b5121a232e | 1651 | } |
| pcercuei | 0:03b5121a232e | 1652 | |
| pcercuei | 0:03b5121a232e | 1653 | /** |
| pcercuei | 0:03b5121a232e | 1654 | * xmlNodeListGetString: |
| pcercuei | 0:03b5121a232e | 1655 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 1656 | * @list: a Node list |
| pcercuei | 0:03b5121a232e | 1657 | * @inLine: should we replace entity contents or show their external form |
| pcercuei | 0:03b5121a232e | 1658 | * |
| pcercuei | 0:03b5121a232e | 1659 | * Build the string equivalent to the text contained in the Node list |
| pcercuei | 0:03b5121a232e | 1660 | * made of TEXTs and ENTITY_REFs |
| pcercuei | 0:03b5121a232e | 1661 | * |
| pcercuei | 0:03b5121a232e | 1662 | * Returns a pointer to the string copy, the caller must free it with xmlFree(). |
| pcercuei | 0:03b5121a232e | 1663 | */ |
| pcercuei | 0:03b5121a232e | 1664 | xmlChar * |
| pcercuei | 0:03b5121a232e | 1665 | xmlNodeListGetString(xmlDocPtr doc, const xmlNode *list, int inLine) |
| pcercuei | 0:03b5121a232e | 1666 | { |
| pcercuei | 0:03b5121a232e | 1667 | const xmlNode *node = list; |
| pcercuei | 0:03b5121a232e | 1668 | xmlChar *ret = NULL; |
| pcercuei | 0:03b5121a232e | 1669 | xmlEntityPtr ent; |
| pcercuei | 0:03b5121a232e | 1670 | int attr; |
| pcercuei | 0:03b5121a232e | 1671 | |
| pcercuei | 0:03b5121a232e | 1672 | if (list == NULL) |
| pcercuei | 0:03b5121a232e | 1673 | return (NULL); |
| pcercuei | 0:03b5121a232e | 1674 | if ((list->parent != NULL) && (list->parent->type == XML_ATTRIBUTE_NODE)) |
| pcercuei | 0:03b5121a232e | 1675 | attr = 1; |
| pcercuei | 0:03b5121a232e | 1676 | else |
| pcercuei | 0:03b5121a232e | 1677 | attr = 0; |
| pcercuei | 0:03b5121a232e | 1678 | |
| pcercuei | 0:03b5121a232e | 1679 | while (node != NULL) { |
| pcercuei | 0:03b5121a232e | 1680 | if ((node->type == XML_TEXT_NODE) || |
| pcercuei | 0:03b5121a232e | 1681 | (node->type == XML_CDATA_SECTION_NODE)) { |
| pcercuei | 0:03b5121a232e | 1682 | if (inLine) { |
| pcercuei | 0:03b5121a232e | 1683 | ret = xmlStrcat(ret, node->content); |
| pcercuei | 0:03b5121a232e | 1684 | } else { |
| pcercuei | 0:03b5121a232e | 1685 | xmlChar *buffer; |
| pcercuei | 0:03b5121a232e | 1686 | |
| pcercuei | 0:03b5121a232e | 1687 | if (attr) |
| pcercuei | 0:03b5121a232e | 1688 | buffer = xmlEncodeAttributeEntities(doc, node->content); |
| pcercuei | 0:03b5121a232e | 1689 | else |
| pcercuei | 0:03b5121a232e | 1690 | buffer = xmlEncodeEntitiesReentrant(doc, node->content); |
| pcercuei | 0:03b5121a232e | 1691 | if (buffer != NULL) { |
| pcercuei | 0:03b5121a232e | 1692 | ret = xmlStrcat(ret, buffer); |
| pcercuei | 0:03b5121a232e | 1693 | xmlFree(buffer); |
| pcercuei | 0:03b5121a232e | 1694 | } |
| pcercuei | 0:03b5121a232e | 1695 | } |
| pcercuei | 0:03b5121a232e | 1696 | } else if (node->type == XML_ENTITY_REF_NODE) { |
| pcercuei | 0:03b5121a232e | 1697 | if (inLine) { |
| pcercuei | 0:03b5121a232e | 1698 | ent = xmlGetDocEntity(doc, node->name); |
| pcercuei | 0:03b5121a232e | 1699 | if (ent != NULL) { |
| pcercuei | 0:03b5121a232e | 1700 | xmlChar *buffer; |
| pcercuei | 0:03b5121a232e | 1701 | |
| pcercuei | 0:03b5121a232e | 1702 | /* an entity content can be any "well balanced chunk", |
| pcercuei | 0:03b5121a232e | 1703 | * i.e. the result of the content [43] production: |
| pcercuei | 0:03b5121a232e | 1704 | * http://www.w3.org/TR/REC-xml#NT-content. |
| pcercuei | 0:03b5121a232e | 1705 | * So it can contain text, CDATA section or nested |
| pcercuei | 0:03b5121a232e | 1706 | * entity reference nodes (among others). |
| pcercuei | 0:03b5121a232e | 1707 | * -> we recursive call xmlNodeListGetString() |
| pcercuei | 0:03b5121a232e | 1708 | * which handles these types */ |
| pcercuei | 0:03b5121a232e | 1709 | buffer = xmlNodeListGetString(doc, ent->children, 1); |
| pcercuei | 0:03b5121a232e | 1710 | if (buffer != NULL) { |
| pcercuei | 0:03b5121a232e | 1711 | ret = xmlStrcat(ret, buffer); |
| pcercuei | 0:03b5121a232e | 1712 | xmlFree(buffer); |
| pcercuei | 0:03b5121a232e | 1713 | } |
| pcercuei | 0:03b5121a232e | 1714 | } else { |
| pcercuei | 0:03b5121a232e | 1715 | ret = xmlStrcat(ret, node->content); |
| pcercuei | 0:03b5121a232e | 1716 | } |
| pcercuei | 0:03b5121a232e | 1717 | } else { |
| pcercuei | 0:03b5121a232e | 1718 | xmlChar buf[2]; |
| pcercuei | 0:03b5121a232e | 1719 | |
| pcercuei | 0:03b5121a232e | 1720 | buf[0] = '&'; |
| pcercuei | 0:03b5121a232e | 1721 | buf[1] = 0; |
| pcercuei | 0:03b5121a232e | 1722 | ret = xmlStrncat(ret, buf, 1); |
| pcercuei | 0:03b5121a232e | 1723 | ret = xmlStrcat(ret, node->name); |
| pcercuei | 0:03b5121a232e | 1724 | buf[0] = ';'; |
| pcercuei | 0:03b5121a232e | 1725 | buf[1] = 0; |
| pcercuei | 0:03b5121a232e | 1726 | ret = xmlStrncat(ret, buf, 1); |
| pcercuei | 0:03b5121a232e | 1727 | } |
| pcercuei | 0:03b5121a232e | 1728 | } |
| pcercuei | 0:03b5121a232e | 1729 | #if 0 |
| pcercuei | 0:03b5121a232e | 1730 | else { |
| pcercuei | 0:03b5121a232e | 1731 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 1732 | "xmlGetNodeListString : invalid node type %d\n", |
| pcercuei | 0:03b5121a232e | 1733 | node->type); |
| pcercuei | 0:03b5121a232e | 1734 | } |
| pcercuei | 0:03b5121a232e | 1735 | #endif |
| pcercuei | 0:03b5121a232e | 1736 | node = node->next; |
| pcercuei | 0:03b5121a232e | 1737 | } |
| pcercuei | 0:03b5121a232e | 1738 | return (ret); |
| pcercuei | 0:03b5121a232e | 1739 | } |
| pcercuei | 0:03b5121a232e | 1740 | |
| pcercuei | 0:03b5121a232e | 1741 | #ifdef LIBXML_TREE_ENABLED |
| pcercuei | 0:03b5121a232e | 1742 | /** |
| pcercuei | 0:03b5121a232e | 1743 | * xmlNodeListGetRawString: |
| pcercuei | 0:03b5121a232e | 1744 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 1745 | * @list: a Node list |
| pcercuei | 0:03b5121a232e | 1746 | * @inLine: should we replace entity contents or show their external form |
| pcercuei | 0:03b5121a232e | 1747 | * |
| pcercuei | 0:03b5121a232e | 1748 | * Builds the string equivalent to the text contained in the Node list |
| pcercuei | 0:03b5121a232e | 1749 | * made of TEXTs and ENTITY_REFs, contrary to xmlNodeListGetString() |
| pcercuei | 0:03b5121a232e | 1750 | * this function doesn't do any character encoding handling. |
| pcercuei | 0:03b5121a232e | 1751 | * |
| pcercuei | 0:03b5121a232e | 1752 | * Returns a pointer to the string copy, the caller must free it with xmlFree(). |
| pcercuei | 0:03b5121a232e | 1753 | */ |
| pcercuei | 0:03b5121a232e | 1754 | xmlChar * |
| pcercuei | 0:03b5121a232e | 1755 | xmlNodeListGetRawString(const xmlDoc *doc, const xmlNode *list, int inLine) |
| pcercuei | 0:03b5121a232e | 1756 | { |
| pcercuei | 0:03b5121a232e | 1757 | const xmlNode *node = list; |
| pcercuei | 0:03b5121a232e | 1758 | xmlChar *ret = NULL; |
| pcercuei | 0:03b5121a232e | 1759 | xmlEntityPtr ent; |
| pcercuei | 0:03b5121a232e | 1760 | |
| pcercuei | 0:03b5121a232e | 1761 | if (list == NULL) |
| pcercuei | 0:03b5121a232e | 1762 | return (NULL); |
| pcercuei | 0:03b5121a232e | 1763 | |
| pcercuei | 0:03b5121a232e | 1764 | while (node != NULL) { |
| pcercuei | 0:03b5121a232e | 1765 | if ((node->type == XML_TEXT_NODE) || |
| pcercuei | 0:03b5121a232e | 1766 | (node->type == XML_CDATA_SECTION_NODE)) { |
| pcercuei | 0:03b5121a232e | 1767 | if (inLine) { |
| pcercuei | 0:03b5121a232e | 1768 | ret = xmlStrcat(ret, node->content); |
| pcercuei | 0:03b5121a232e | 1769 | } else { |
| pcercuei | 0:03b5121a232e | 1770 | xmlChar *buffer; |
| pcercuei | 0:03b5121a232e | 1771 | |
| pcercuei | 0:03b5121a232e | 1772 | buffer = xmlEncodeSpecialChars(doc, node->content); |
| pcercuei | 0:03b5121a232e | 1773 | if (buffer != NULL) { |
| pcercuei | 0:03b5121a232e | 1774 | ret = xmlStrcat(ret, buffer); |
| pcercuei | 0:03b5121a232e | 1775 | xmlFree(buffer); |
| pcercuei | 0:03b5121a232e | 1776 | } |
| pcercuei | 0:03b5121a232e | 1777 | } |
| pcercuei | 0:03b5121a232e | 1778 | } else if (node->type == XML_ENTITY_REF_NODE) { |
| pcercuei | 0:03b5121a232e | 1779 | if (inLine) { |
| pcercuei | 0:03b5121a232e | 1780 | ent = xmlGetDocEntity(doc, node->name); |
| pcercuei | 0:03b5121a232e | 1781 | if (ent != NULL) { |
| pcercuei | 0:03b5121a232e | 1782 | xmlChar *buffer; |
| pcercuei | 0:03b5121a232e | 1783 | |
| pcercuei | 0:03b5121a232e | 1784 | /* an entity content can be any "well balanced chunk", |
| pcercuei | 0:03b5121a232e | 1785 | * i.e. the result of the content [43] production: |
| pcercuei | 0:03b5121a232e | 1786 | * http://www.w3.org/TR/REC-xml#NT-content. |
| pcercuei | 0:03b5121a232e | 1787 | * So it can contain text, CDATA section or nested |
| pcercuei | 0:03b5121a232e | 1788 | * entity reference nodes (among others). |
| pcercuei | 0:03b5121a232e | 1789 | * -> we recursive call xmlNodeListGetRawString() |
| pcercuei | 0:03b5121a232e | 1790 | * which handles these types */ |
| pcercuei | 0:03b5121a232e | 1791 | buffer = |
| pcercuei | 0:03b5121a232e | 1792 | xmlNodeListGetRawString(doc, ent->children, 1); |
| pcercuei | 0:03b5121a232e | 1793 | if (buffer != NULL) { |
| pcercuei | 0:03b5121a232e | 1794 | ret = xmlStrcat(ret, buffer); |
| pcercuei | 0:03b5121a232e | 1795 | xmlFree(buffer); |
| pcercuei | 0:03b5121a232e | 1796 | } |
| pcercuei | 0:03b5121a232e | 1797 | } else { |
| pcercuei | 0:03b5121a232e | 1798 | ret = xmlStrcat(ret, node->content); |
| pcercuei | 0:03b5121a232e | 1799 | } |
| pcercuei | 0:03b5121a232e | 1800 | } else { |
| pcercuei | 0:03b5121a232e | 1801 | xmlChar buf[2]; |
| pcercuei | 0:03b5121a232e | 1802 | |
| pcercuei | 0:03b5121a232e | 1803 | buf[0] = '&'; |
| pcercuei | 0:03b5121a232e | 1804 | buf[1] = 0; |
| pcercuei | 0:03b5121a232e | 1805 | ret = xmlStrncat(ret, buf, 1); |
| pcercuei | 0:03b5121a232e | 1806 | ret = xmlStrcat(ret, node->name); |
| pcercuei | 0:03b5121a232e | 1807 | buf[0] = ';'; |
| pcercuei | 0:03b5121a232e | 1808 | buf[1] = 0; |
| pcercuei | 0:03b5121a232e | 1809 | ret = xmlStrncat(ret, buf, 1); |
| pcercuei | 0:03b5121a232e | 1810 | } |
| pcercuei | 0:03b5121a232e | 1811 | } |
| pcercuei | 0:03b5121a232e | 1812 | #if 0 |
| pcercuei | 0:03b5121a232e | 1813 | else { |
| pcercuei | 0:03b5121a232e | 1814 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 1815 | "xmlGetNodeListString : invalid node type %d\n", |
| pcercuei | 0:03b5121a232e | 1816 | node->type); |
| pcercuei | 0:03b5121a232e | 1817 | } |
| pcercuei | 0:03b5121a232e | 1818 | #endif |
| pcercuei | 0:03b5121a232e | 1819 | node = node->next; |
| pcercuei | 0:03b5121a232e | 1820 | } |
| pcercuei | 0:03b5121a232e | 1821 | return (ret); |
| pcercuei | 0:03b5121a232e | 1822 | } |
| pcercuei | 0:03b5121a232e | 1823 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 1824 | |
| pcercuei | 0:03b5121a232e | 1825 | static xmlAttrPtr |
| pcercuei | 0:03b5121a232e | 1826 | xmlNewPropInternal(xmlNodePtr node, xmlNsPtr ns, |
| pcercuei | 0:03b5121a232e | 1827 | const xmlChar * name, const xmlChar * value, |
| pcercuei | 0:03b5121a232e | 1828 | int eatname) |
| pcercuei | 0:03b5121a232e | 1829 | { |
| pcercuei | 0:03b5121a232e | 1830 | xmlAttrPtr cur; |
| pcercuei | 0:03b5121a232e | 1831 | xmlDocPtr doc = NULL; |
| pcercuei | 0:03b5121a232e | 1832 | |
| pcercuei | 0:03b5121a232e | 1833 | if ((node != NULL) && (node->type != XML_ELEMENT_NODE)) { |
| pcercuei | 0:03b5121a232e | 1834 | if ((eatname == 1) && |
| pcercuei | 0:03b5121a232e | 1835 | ((node->doc == NULL) || |
| pcercuei | 0:03b5121a232e | 1836 | (!(xmlDictOwns(node->doc->dict, name))))) |
| pcercuei | 0:03b5121a232e | 1837 | xmlFree((xmlChar *) name); |
| pcercuei | 0:03b5121a232e | 1838 | return (NULL); |
| pcercuei | 0:03b5121a232e | 1839 | } |
| pcercuei | 0:03b5121a232e | 1840 | |
| pcercuei | 0:03b5121a232e | 1841 | /* |
| pcercuei | 0:03b5121a232e | 1842 | * Allocate a new property and fill the fields. |
| pcercuei | 0:03b5121a232e | 1843 | */ |
| pcercuei | 0:03b5121a232e | 1844 | cur = (xmlAttrPtr) xmlMalloc(sizeof(xmlAttr)); |
| pcercuei | 0:03b5121a232e | 1845 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 1846 | if ((eatname == 1) && |
| pcercuei | 0:03b5121a232e | 1847 | ((node == NULL) || (node->doc == NULL) || |
| pcercuei | 0:03b5121a232e | 1848 | (!(xmlDictOwns(node->doc->dict, name))))) |
| pcercuei | 0:03b5121a232e | 1849 | xmlFree((xmlChar *) name); |
| pcercuei | 0:03b5121a232e | 1850 | xmlTreeErrMemory("building attribute"); |
| pcercuei | 0:03b5121a232e | 1851 | return (NULL); |
| pcercuei | 0:03b5121a232e | 1852 | } |
| pcercuei | 0:03b5121a232e | 1853 | memset(cur, 0, sizeof(xmlAttr)); |
| pcercuei | 0:03b5121a232e | 1854 | cur->type = XML_ATTRIBUTE_NODE; |
| pcercuei | 0:03b5121a232e | 1855 | |
| pcercuei | 0:03b5121a232e | 1856 | cur->parent = node; |
| pcercuei | 0:03b5121a232e | 1857 | if (node != NULL) { |
| pcercuei | 0:03b5121a232e | 1858 | doc = node->doc; |
| pcercuei | 0:03b5121a232e | 1859 | cur->doc = doc; |
| pcercuei | 0:03b5121a232e | 1860 | } |
| pcercuei | 0:03b5121a232e | 1861 | cur->ns = ns; |
| pcercuei | 0:03b5121a232e | 1862 | |
| pcercuei | 0:03b5121a232e | 1863 | if (eatname == 0) { |
| pcercuei | 0:03b5121a232e | 1864 | if ((doc != NULL) && (doc->dict != NULL)) |
| pcercuei | 0:03b5121a232e | 1865 | cur->name = (xmlChar *) xmlDictLookup(doc->dict, name, -1); |
| pcercuei | 0:03b5121a232e | 1866 | else |
| pcercuei | 0:03b5121a232e | 1867 | cur->name = xmlStrdup(name); |
| pcercuei | 0:03b5121a232e | 1868 | } else |
| pcercuei | 0:03b5121a232e | 1869 | cur->name = name; |
| pcercuei | 0:03b5121a232e | 1870 | |
| pcercuei | 0:03b5121a232e | 1871 | if (value != NULL) { |
| pcercuei | 0:03b5121a232e | 1872 | xmlNodePtr tmp; |
| pcercuei | 0:03b5121a232e | 1873 | |
| pcercuei | 0:03b5121a232e | 1874 | if(!xmlCheckUTF8(value)) { |
| pcercuei | 0:03b5121a232e | 1875 | xmlTreeErr(XML_TREE_NOT_UTF8, (xmlNodePtr) doc, |
| pcercuei | 0:03b5121a232e | 1876 | NULL); |
| pcercuei | 0:03b5121a232e | 1877 | if (doc != NULL) |
| pcercuei | 0:03b5121a232e | 1878 | doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); |
| pcercuei | 0:03b5121a232e | 1879 | } |
| pcercuei | 0:03b5121a232e | 1880 | cur->children = xmlNewDocText(doc, value); |
| pcercuei | 0:03b5121a232e | 1881 | cur->last = NULL; |
| pcercuei | 0:03b5121a232e | 1882 | tmp = cur->children; |
| pcercuei | 0:03b5121a232e | 1883 | while (tmp != NULL) { |
| pcercuei | 0:03b5121a232e | 1884 | tmp->parent = (xmlNodePtr) cur; |
| pcercuei | 0:03b5121a232e | 1885 | if (tmp->next == NULL) |
| pcercuei | 0:03b5121a232e | 1886 | cur->last = tmp; |
| pcercuei | 0:03b5121a232e | 1887 | tmp = tmp->next; |
| pcercuei | 0:03b5121a232e | 1888 | } |
| pcercuei | 0:03b5121a232e | 1889 | } |
| pcercuei | 0:03b5121a232e | 1890 | |
| pcercuei | 0:03b5121a232e | 1891 | /* |
| pcercuei | 0:03b5121a232e | 1892 | * Add it at the end to preserve parsing order ... |
| pcercuei | 0:03b5121a232e | 1893 | */ |
| pcercuei | 0:03b5121a232e | 1894 | if (node != NULL) { |
| pcercuei | 0:03b5121a232e | 1895 | if (node->properties == NULL) { |
| pcercuei | 0:03b5121a232e | 1896 | node->properties = cur; |
| pcercuei | 0:03b5121a232e | 1897 | } else { |
| pcercuei | 0:03b5121a232e | 1898 | xmlAttrPtr prev = node->properties; |
| pcercuei | 0:03b5121a232e | 1899 | |
| pcercuei | 0:03b5121a232e | 1900 | while (prev->next != NULL) |
| pcercuei | 0:03b5121a232e | 1901 | prev = prev->next; |
| pcercuei | 0:03b5121a232e | 1902 | prev->next = cur; |
| pcercuei | 0:03b5121a232e | 1903 | cur->prev = prev; |
| pcercuei | 0:03b5121a232e | 1904 | } |
| pcercuei | 0:03b5121a232e | 1905 | } |
| pcercuei | 0:03b5121a232e | 1906 | |
| pcercuei | 0:03b5121a232e | 1907 | if ((value != NULL) && (node != NULL) && |
| pcercuei | 0:03b5121a232e | 1908 | (xmlIsID(node->doc, node, cur) == 1)) |
| pcercuei | 0:03b5121a232e | 1909 | xmlAddID(NULL, node->doc, value, cur); |
| pcercuei | 0:03b5121a232e | 1910 | |
| pcercuei | 0:03b5121a232e | 1911 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 1912 | xmlRegisterNodeDefaultValue((xmlNodePtr) cur); |
| pcercuei | 0:03b5121a232e | 1913 | return (cur); |
| pcercuei | 0:03b5121a232e | 1914 | } |
| pcercuei | 0:03b5121a232e | 1915 | |
| pcercuei | 0:03b5121a232e | 1916 | #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_HTML_ENABLED) || \ |
| pcercuei | 0:03b5121a232e | 1917 | defined(LIBXML_SCHEMAS_ENABLED) |
| pcercuei | 0:03b5121a232e | 1918 | /** |
| pcercuei | 0:03b5121a232e | 1919 | * xmlNewProp: |
| pcercuei | 0:03b5121a232e | 1920 | * @node: the holding node |
| pcercuei | 0:03b5121a232e | 1921 | * @name: the name of the attribute |
| pcercuei | 0:03b5121a232e | 1922 | * @value: the value of the attribute |
| pcercuei | 0:03b5121a232e | 1923 | * |
| pcercuei | 0:03b5121a232e | 1924 | * Create a new property carried by a node. |
| pcercuei | 0:03b5121a232e | 1925 | * Returns a pointer to the attribute |
| pcercuei | 0:03b5121a232e | 1926 | */ |
| pcercuei | 0:03b5121a232e | 1927 | xmlAttrPtr |
| pcercuei | 0:03b5121a232e | 1928 | xmlNewProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { |
| pcercuei | 0:03b5121a232e | 1929 | |
| pcercuei | 0:03b5121a232e | 1930 | if (name == NULL) { |
| pcercuei | 0:03b5121a232e | 1931 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 1932 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 1933 | "xmlNewProp : name == NULL\n"); |
| pcercuei | 0:03b5121a232e | 1934 | #endif |
| pcercuei | 0:03b5121a232e | 1935 | return(NULL); |
| pcercuei | 0:03b5121a232e | 1936 | } |
| pcercuei | 0:03b5121a232e | 1937 | |
| pcercuei | 0:03b5121a232e | 1938 | return xmlNewPropInternal(node, NULL, name, value, 0); |
| pcercuei | 0:03b5121a232e | 1939 | } |
| pcercuei | 0:03b5121a232e | 1940 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 1941 | |
| pcercuei | 0:03b5121a232e | 1942 | /** |
| pcercuei | 0:03b5121a232e | 1943 | * xmlNewNsProp: |
| pcercuei | 0:03b5121a232e | 1944 | * @node: the holding node |
| pcercuei | 0:03b5121a232e | 1945 | * @ns: the namespace |
| pcercuei | 0:03b5121a232e | 1946 | * @name: the name of the attribute |
| pcercuei | 0:03b5121a232e | 1947 | * @value: the value of the attribute |
| pcercuei | 0:03b5121a232e | 1948 | * |
| pcercuei | 0:03b5121a232e | 1949 | * Create a new property tagged with a namespace and carried by a node. |
| pcercuei | 0:03b5121a232e | 1950 | * Returns a pointer to the attribute |
| pcercuei | 0:03b5121a232e | 1951 | */ |
| pcercuei | 0:03b5121a232e | 1952 | xmlAttrPtr |
| pcercuei | 0:03b5121a232e | 1953 | xmlNewNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name, |
| pcercuei | 0:03b5121a232e | 1954 | const xmlChar *value) { |
| pcercuei | 0:03b5121a232e | 1955 | |
| pcercuei | 0:03b5121a232e | 1956 | if (name == NULL) { |
| pcercuei | 0:03b5121a232e | 1957 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 1958 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 1959 | "xmlNewNsProp : name == NULL\n"); |
| pcercuei | 0:03b5121a232e | 1960 | #endif |
| pcercuei | 0:03b5121a232e | 1961 | return(NULL); |
| pcercuei | 0:03b5121a232e | 1962 | } |
| pcercuei | 0:03b5121a232e | 1963 | |
| pcercuei | 0:03b5121a232e | 1964 | return xmlNewPropInternal(node, ns, name, value, 0); |
| pcercuei | 0:03b5121a232e | 1965 | } |
| pcercuei | 0:03b5121a232e | 1966 | |
| pcercuei | 0:03b5121a232e | 1967 | /** |
| pcercuei | 0:03b5121a232e | 1968 | * xmlNewNsPropEatName: |
| pcercuei | 0:03b5121a232e | 1969 | * @node: the holding node |
| pcercuei | 0:03b5121a232e | 1970 | * @ns: the namespace |
| pcercuei | 0:03b5121a232e | 1971 | * @name: the name of the attribute |
| pcercuei | 0:03b5121a232e | 1972 | * @value: the value of the attribute |
| pcercuei | 0:03b5121a232e | 1973 | * |
| pcercuei | 0:03b5121a232e | 1974 | * Create a new property tagged with a namespace and carried by a node. |
| pcercuei | 0:03b5121a232e | 1975 | * Returns a pointer to the attribute |
| pcercuei | 0:03b5121a232e | 1976 | */ |
| pcercuei | 0:03b5121a232e | 1977 | xmlAttrPtr |
| pcercuei | 0:03b5121a232e | 1978 | xmlNewNsPropEatName(xmlNodePtr node, xmlNsPtr ns, xmlChar *name, |
| pcercuei | 0:03b5121a232e | 1979 | const xmlChar *value) { |
| pcercuei | 0:03b5121a232e | 1980 | |
| pcercuei | 0:03b5121a232e | 1981 | if (name == NULL) { |
| pcercuei | 0:03b5121a232e | 1982 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 1983 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 1984 | "xmlNewNsPropEatName : name == NULL\n"); |
| pcercuei | 0:03b5121a232e | 1985 | #endif |
| pcercuei | 0:03b5121a232e | 1986 | return(NULL); |
| pcercuei | 0:03b5121a232e | 1987 | } |
| pcercuei | 0:03b5121a232e | 1988 | |
| pcercuei | 0:03b5121a232e | 1989 | return xmlNewPropInternal(node, ns, name, value, 1); |
| pcercuei | 0:03b5121a232e | 1990 | } |
| pcercuei | 0:03b5121a232e | 1991 | |
| pcercuei | 0:03b5121a232e | 1992 | /** |
| pcercuei | 0:03b5121a232e | 1993 | * xmlNewDocProp: |
| pcercuei | 0:03b5121a232e | 1994 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 1995 | * @name: the name of the attribute |
| pcercuei | 0:03b5121a232e | 1996 | * @value: the value of the attribute |
| pcercuei | 0:03b5121a232e | 1997 | * |
| pcercuei | 0:03b5121a232e | 1998 | * Create a new property carried by a document. |
| pcercuei | 0:03b5121a232e | 1999 | * Returns a pointer to the attribute |
| pcercuei | 0:03b5121a232e | 2000 | */ |
| pcercuei | 0:03b5121a232e | 2001 | xmlAttrPtr |
| pcercuei | 0:03b5121a232e | 2002 | xmlNewDocProp(xmlDocPtr doc, const xmlChar *name, const xmlChar *value) { |
| pcercuei | 0:03b5121a232e | 2003 | xmlAttrPtr cur; |
| pcercuei | 0:03b5121a232e | 2004 | |
| pcercuei | 0:03b5121a232e | 2005 | if (name == NULL) { |
| pcercuei | 0:03b5121a232e | 2006 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 2007 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 2008 | "xmlNewDocProp : name == NULL\n"); |
| pcercuei | 0:03b5121a232e | 2009 | #endif |
| pcercuei | 0:03b5121a232e | 2010 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2011 | } |
| pcercuei | 0:03b5121a232e | 2012 | |
| pcercuei | 0:03b5121a232e | 2013 | /* |
| pcercuei | 0:03b5121a232e | 2014 | * Allocate a new property and fill the fields. |
| pcercuei | 0:03b5121a232e | 2015 | */ |
| pcercuei | 0:03b5121a232e | 2016 | cur = (xmlAttrPtr) xmlMalloc(sizeof(xmlAttr)); |
| pcercuei | 0:03b5121a232e | 2017 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 2018 | xmlTreeErrMemory("building attribute"); |
| pcercuei | 0:03b5121a232e | 2019 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2020 | } |
| pcercuei | 0:03b5121a232e | 2021 | memset(cur, 0, sizeof(xmlAttr)); |
| pcercuei | 0:03b5121a232e | 2022 | cur->type = XML_ATTRIBUTE_NODE; |
| pcercuei | 0:03b5121a232e | 2023 | |
| pcercuei | 0:03b5121a232e | 2024 | if ((doc != NULL) && (doc->dict != NULL)) |
| pcercuei | 0:03b5121a232e | 2025 | cur->name = xmlDictLookup(doc->dict, name, -1); |
| pcercuei | 0:03b5121a232e | 2026 | else |
| pcercuei | 0:03b5121a232e | 2027 | cur->name = xmlStrdup(name); |
| pcercuei | 0:03b5121a232e | 2028 | cur->doc = doc; |
| pcercuei | 0:03b5121a232e | 2029 | if (value != NULL) { |
| pcercuei | 0:03b5121a232e | 2030 | xmlNodePtr tmp; |
| pcercuei | 0:03b5121a232e | 2031 | |
| pcercuei | 0:03b5121a232e | 2032 | cur->children = xmlStringGetNodeList(doc, value); |
| pcercuei | 0:03b5121a232e | 2033 | cur->last = NULL; |
| pcercuei | 0:03b5121a232e | 2034 | |
| pcercuei | 0:03b5121a232e | 2035 | tmp = cur->children; |
| pcercuei | 0:03b5121a232e | 2036 | while (tmp != NULL) { |
| pcercuei | 0:03b5121a232e | 2037 | tmp->parent = (xmlNodePtr) cur; |
| pcercuei | 0:03b5121a232e | 2038 | if (tmp->next == NULL) |
| pcercuei | 0:03b5121a232e | 2039 | cur->last = tmp; |
| pcercuei | 0:03b5121a232e | 2040 | tmp = tmp->next; |
| pcercuei | 0:03b5121a232e | 2041 | } |
| pcercuei | 0:03b5121a232e | 2042 | } |
| pcercuei | 0:03b5121a232e | 2043 | |
| pcercuei | 0:03b5121a232e | 2044 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 2045 | xmlRegisterNodeDefaultValue((xmlNodePtr)cur); |
| pcercuei | 0:03b5121a232e | 2046 | return(cur); |
| pcercuei | 0:03b5121a232e | 2047 | } |
| pcercuei | 0:03b5121a232e | 2048 | |
| pcercuei | 0:03b5121a232e | 2049 | /** |
| pcercuei | 0:03b5121a232e | 2050 | * xmlFreePropList: |
| pcercuei | 0:03b5121a232e | 2051 | * @cur: the first property in the list |
| pcercuei | 0:03b5121a232e | 2052 | * |
| pcercuei | 0:03b5121a232e | 2053 | * Free a property and all its siblings, all the children are freed too. |
| pcercuei | 0:03b5121a232e | 2054 | */ |
| pcercuei | 0:03b5121a232e | 2055 | void |
| pcercuei | 0:03b5121a232e | 2056 | xmlFreePropList(xmlAttrPtr cur) { |
| pcercuei | 0:03b5121a232e | 2057 | xmlAttrPtr next; |
| pcercuei | 0:03b5121a232e | 2058 | if (cur == NULL) return; |
| pcercuei | 0:03b5121a232e | 2059 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 2060 | next = cur->next; |
| pcercuei | 0:03b5121a232e | 2061 | xmlFreeProp(cur); |
| pcercuei | 0:03b5121a232e | 2062 | cur = next; |
| pcercuei | 0:03b5121a232e | 2063 | } |
| pcercuei | 0:03b5121a232e | 2064 | } |
| pcercuei | 0:03b5121a232e | 2065 | |
| pcercuei | 0:03b5121a232e | 2066 | /** |
| pcercuei | 0:03b5121a232e | 2067 | * xmlFreeProp: |
| pcercuei | 0:03b5121a232e | 2068 | * @cur: an attribute |
| pcercuei | 0:03b5121a232e | 2069 | * |
| pcercuei | 0:03b5121a232e | 2070 | * Free one attribute, all the content is freed too |
| pcercuei | 0:03b5121a232e | 2071 | */ |
| pcercuei | 0:03b5121a232e | 2072 | void |
| pcercuei | 0:03b5121a232e | 2073 | xmlFreeProp(xmlAttrPtr cur) { |
| pcercuei | 0:03b5121a232e | 2074 | xmlDictPtr dict = NULL; |
| pcercuei | 0:03b5121a232e | 2075 | if (cur == NULL) return; |
| pcercuei | 0:03b5121a232e | 2076 | |
| pcercuei | 0:03b5121a232e | 2077 | if (cur->doc != NULL) dict = cur->doc->dict; |
| pcercuei | 0:03b5121a232e | 2078 | |
| pcercuei | 0:03b5121a232e | 2079 | if ((__xmlRegisterCallbacks) && (xmlDeregisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 2080 | xmlDeregisterNodeDefaultValue((xmlNodePtr)cur); |
| pcercuei | 0:03b5121a232e | 2081 | |
| pcercuei | 0:03b5121a232e | 2082 | /* Check for ID removal -> leading to invalid references ! */ |
| pcercuei | 0:03b5121a232e | 2083 | if ((cur->doc != NULL) && (cur->atype == XML_ATTRIBUTE_ID)) { |
| pcercuei | 0:03b5121a232e | 2084 | xmlRemoveID(cur->doc, cur); |
| pcercuei | 0:03b5121a232e | 2085 | } |
| pcercuei | 0:03b5121a232e | 2086 | if (cur->children != NULL) xmlFreeNodeList(cur->children); |
| pcercuei | 0:03b5121a232e | 2087 | DICT_FREE(cur->name) |
| pcercuei | 0:03b5121a232e | 2088 | xmlFree(cur); |
| pcercuei | 0:03b5121a232e | 2089 | } |
| pcercuei | 0:03b5121a232e | 2090 | |
| pcercuei | 0:03b5121a232e | 2091 | /** |
| pcercuei | 0:03b5121a232e | 2092 | * xmlRemoveProp: |
| pcercuei | 0:03b5121a232e | 2093 | * @cur: an attribute |
| pcercuei | 0:03b5121a232e | 2094 | * |
| pcercuei | 0:03b5121a232e | 2095 | * Unlink and free one attribute, all the content is freed too |
| pcercuei | 0:03b5121a232e | 2096 | * Note this doesn't work for namespace definition attributes |
| pcercuei | 0:03b5121a232e | 2097 | * |
| pcercuei | 0:03b5121a232e | 2098 | * Returns 0 if success and -1 in case of error. |
| pcercuei | 0:03b5121a232e | 2099 | */ |
| pcercuei | 0:03b5121a232e | 2100 | int |
| pcercuei | 0:03b5121a232e | 2101 | xmlRemoveProp(xmlAttrPtr cur) { |
| pcercuei | 0:03b5121a232e | 2102 | xmlAttrPtr tmp; |
| pcercuei | 0:03b5121a232e | 2103 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 2104 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 2105 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 2106 | "xmlRemoveProp : cur == NULL\n"); |
| pcercuei | 0:03b5121a232e | 2107 | #endif |
| pcercuei | 0:03b5121a232e | 2108 | return(-1); |
| pcercuei | 0:03b5121a232e | 2109 | } |
| pcercuei | 0:03b5121a232e | 2110 | if (cur->parent == NULL) { |
| pcercuei | 0:03b5121a232e | 2111 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 2112 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 2113 | "xmlRemoveProp : cur->parent == NULL\n"); |
| pcercuei | 0:03b5121a232e | 2114 | #endif |
| pcercuei | 0:03b5121a232e | 2115 | return(-1); |
| pcercuei | 0:03b5121a232e | 2116 | } |
| pcercuei | 0:03b5121a232e | 2117 | tmp = cur->parent->properties; |
| pcercuei | 0:03b5121a232e | 2118 | if (tmp == cur) { |
| pcercuei | 0:03b5121a232e | 2119 | cur->parent->properties = cur->next; |
| pcercuei | 0:03b5121a232e | 2120 | if (cur->next != NULL) |
| pcercuei | 0:03b5121a232e | 2121 | cur->next->prev = NULL; |
| pcercuei | 0:03b5121a232e | 2122 | xmlFreeProp(cur); |
| pcercuei | 0:03b5121a232e | 2123 | return(0); |
| pcercuei | 0:03b5121a232e | 2124 | } |
| pcercuei | 0:03b5121a232e | 2125 | while (tmp != NULL) { |
| pcercuei | 0:03b5121a232e | 2126 | if (tmp->next == cur) { |
| pcercuei | 0:03b5121a232e | 2127 | tmp->next = cur->next; |
| pcercuei | 0:03b5121a232e | 2128 | if (tmp->next != NULL) |
| pcercuei | 0:03b5121a232e | 2129 | tmp->next->prev = tmp; |
| pcercuei | 0:03b5121a232e | 2130 | xmlFreeProp(cur); |
| pcercuei | 0:03b5121a232e | 2131 | return(0); |
| pcercuei | 0:03b5121a232e | 2132 | } |
| pcercuei | 0:03b5121a232e | 2133 | tmp = tmp->next; |
| pcercuei | 0:03b5121a232e | 2134 | } |
| pcercuei | 0:03b5121a232e | 2135 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 2136 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 2137 | "xmlRemoveProp : attribute not owned by its node\n"); |
| pcercuei | 0:03b5121a232e | 2138 | #endif |
| pcercuei | 0:03b5121a232e | 2139 | return(-1); |
| pcercuei | 0:03b5121a232e | 2140 | } |
| pcercuei | 0:03b5121a232e | 2141 | |
| pcercuei | 0:03b5121a232e | 2142 | /** |
| pcercuei | 0:03b5121a232e | 2143 | * xmlNewDocPI: |
| pcercuei | 0:03b5121a232e | 2144 | * @doc: the target document |
| pcercuei | 0:03b5121a232e | 2145 | * @name: the processing instruction name |
| pcercuei | 0:03b5121a232e | 2146 | * @content: the PI content |
| pcercuei | 0:03b5121a232e | 2147 | * |
| pcercuei | 0:03b5121a232e | 2148 | * Creation of a processing instruction element. |
| pcercuei | 0:03b5121a232e | 2149 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2150 | */ |
| pcercuei | 0:03b5121a232e | 2151 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2152 | xmlNewDocPI(xmlDocPtr doc, const xmlChar *name, const xmlChar *content) { |
| pcercuei | 0:03b5121a232e | 2153 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2154 | |
| pcercuei | 0:03b5121a232e | 2155 | if (name == NULL) { |
| pcercuei | 0:03b5121a232e | 2156 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 2157 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 2158 | "xmlNewPI : name == NULL\n"); |
| pcercuei | 0:03b5121a232e | 2159 | #endif |
| pcercuei | 0:03b5121a232e | 2160 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2161 | } |
| pcercuei | 0:03b5121a232e | 2162 | |
| pcercuei | 0:03b5121a232e | 2163 | /* |
| pcercuei | 0:03b5121a232e | 2164 | * Allocate a new node and fill the fields. |
| pcercuei | 0:03b5121a232e | 2165 | */ |
| pcercuei | 0:03b5121a232e | 2166 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2167 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 2168 | xmlTreeErrMemory("building PI"); |
| pcercuei | 0:03b5121a232e | 2169 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2170 | } |
| pcercuei | 0:03b5121a232e | 2171 | memset(cur, 0, sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2172 | cur->type = XML_PI_NODE; |
| pcercuei | 0:03b5121a232e | 2173 | |
| pcercuei | 0:03b5121a232e | 2174 | if ((doc != NULL) && (doc->dict != NULL)) |
| pcercuei | 0:03b5121a232e | 2175 | cur->name = xmlDictLookup(doc->dict, name, -1); |
| pcercuei | 0:03b5121a232e | 2176 | else |
| pcercuei | 0:03b5121a232e | 2177 | cur->name = xmlStrdup(name); |
| pcercuei | 0:03b5121a232e | 2178 | if (content != NULL) { |
| pcercuei | 0:03b5121a232e | 2179 | cur->content = xmlStrdup(content); |
| pcercuei | 0:03b5121a232e | 2180 | } |
| pcercuei | 0:03b5121a232e | 2181 | cur->doc = doc; |
| pcercuei | 0:03b5121a232e | 2182 | |
| pcercuei | 0:03b5121a232e | 2183 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 2184 | xmlRegisterNodeDefaultValue((xmlNodePtr)cur); |
| pcercuei | 0:03b5121a232e | 2185 | return(cur); |
| pcercuei | 0:03b5121a232e | 2186 | } |
| pcercuei | 0:03b5121a232e | 2187 | |
| pcercuei | 0:03b5121a232e | 2188 | /** |
| pcercuei | 0:03b5121a232e | 2189 | * xmlNewPI: |
| pcercuei | 0:03b5121a232e | 2190 | * @name: the processing instruction name |
| pcercuei | 0:03b5121a232e | 2191 | * @content: the PI content |
| pcercuei | 0:03b5121a232e | 2192 | * |
| pcercuei | 0:03b5121a232e | 2193 | * Creation of a processing instruction element. |
| pcercuei | 0:03b5121a232e | 2194 | * Use xmlDocNewPI preferably to get string interning |
| pcercuei | 0:03b5121a232e | 2195 | * |
| pcercuei | 0:03b5121a232e | 2196 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2197 | */ |
| pcercuei | 0:03b5121a232e | 2198 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2199 | xmlNewPI(const xmlChar *name, const xmlChar *content) { |
| pcercuei | 0:03b5121a232e | 2200 | return(xmlNewDocPI(NULL, name, content)); |
| pcercuei | 0:03b5121a232e | 2201 | } |
| pcercuei | 0:03b5121a232e | 2202 | |
| pcercuei | 0:03b5121a232e | 2203 | /** |
| pcercuei | 0:03b5121a232e | 2204 | * xmlNewNode: |
| pcercuei | 0:03b5121a232e | 2205 | * @ns: namespace if any |
| pcercuei | 0:03b5121a232e | 2206 | * @name: the node name |
| pcercuei | 0:03b5121a232e | 2207 | * |
| pcercuei | 0:03b5121a232e | 2208 | * Creation of a new node element. @ns is optional (NULL). |
| pcercuei | 0:03b5121a232e | 2209 | * |
| pcercuei | 0:03b5121a232e | 2210 | * Returns a pointer to the new node object. Uses xmlStrdup() to make |
| pcercuei | 0:03b5121a232e | 2211 | * copy of @name. |
| pcercuei | 0:03b5121a232e | 2212 | */ |
| pcercuei | 0:03b5121a232e | 2213 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2214 | xmlNewNode(xmlNsPtr ns, const xmlChar *name) { |
| pcercuei | 0:03b5121a232e | 2215 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2216 | |
| pcercuei | 0:03b5121a232e | 2217 | if (name == NULL) { |
| pcercuei | 0:03b5121a232e | 2218 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 2219 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 2220 | "xmlNewNode : name == NULL\n"); |
| pcercuei | 0:03b5121a232e | 2221 | #endif |
| pcercuei | 0:03b5121a232e | 2222 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2223 | } |
| pcercuei | 0:03b5121a232e | 2224 | |
| pcercuei | 0:03b5121a232e | 2225 | /* |
| pcercuei | 0:03b5121a232e | 2226 | * Allocate a new node and fill the fields. |
| pcercuei | 0:03b5121a232e | 2227 | */ |
| pcercuei | 0:03b5121a232e | 2228 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2229 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 2230 | xmlTreeErrMemory("building node"); |
| pcercuei | 0:03b5121a232e | 2231 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2232 | } |
| pcercuei | 0:03b5121a232e | 2233 | memset(cur, 0, sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2234 | cur->type = XML_ELEMENT_NODE; |
| pcercuei | 0:03b5121a232e | 2235 | |
| pcercuei | 0:03b5121a232e | 2236 | cur->name = xmlStrdup(name); |
| pcercuei | 0:03b5121a232e | 2237 | cur->ns = ns; |
| pcercuei | 0:03b5121a232e | 2238 | |
| pcercuei | 0:03b5121a232e | 2239 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 2240 | xmlRegisterNodeDefaultValue(cur); |
| pcercuei | 0:03b5121a232e | 2241 | return(cur); |
| pcercuei | 0:03b5121a232e | 2242 | } |
| pcercuei | 0:03b5121a232e | 2243 | |
| pcercuei | 0:03b5121a232e | 2244 | /** |
| pcercuei | 0:03b5121a232e | 2245 | * xmlNewNodeEatName: |
| pcercuei | 0:03b5121a232e | 2246 | * @ns: namespace if any |
| pcercuei | 0:03b5121a232e | 2247 | * @name: the node name |
| pcercuei | 0:03b5121a232e | 2248 | * |
| pcercuei | 0:03b5121a232e | 2249 | * Creation of a new node element. @ns is optional (NULL). |
| pcercuei | 0:03b5121a232e | 2250 | * |
| pcercuei | 0:03b5121a232e | 2251 | * Returns a pointer to the new node object, with pointer @name as |
| pcercuei | 0:03b5121a232e | 2252 | * new node's name. Use xmlNewNode() if a copy of @name string is |
| pcercuei | 0:03b5121a232e | 2253 | * is needed as new node's name. |
| pcercuei | 0:03b5121a232e | 2254 | */ |
| pcercuei | 0:03b5121a232e | 2255 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2256 | xmlNewNodeEatName(xmlNsPtr ns, xmlChar *name) { |
| pcercuei | 0:03b5121a232e | 2257 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2258 | |
| pcercuei | 0:03b5121a232e | 2259 | if (name == NULL) { |
| pcercuei | 0:03b5121a232e | 2260 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 2261 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 2262 | "xmlNewNode : name == NULL\n"); |
| pcercuei | 0:03b5121a232e | 2263 | #endif |
| pcercuei | 0:03b5121a232e | 2264 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2265 | } |
| pcercuei | 0:03b5121a232e | 2266 | |
| pcercuei | 0:03b5121a232e | 2267 | /* |
| pcercuei | 0:03b5121a232e | 2268 | * Allocate a new node and fill the fields. |
| pcercuei | 0:03b5121a232e | 2269 | */ |
| pcercuei | 0:03b5121a232e | 2270 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2271 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 2272 | xmlTreeErrMemory("building node"); |
| pcercuei | 0:03b5121a232e | 2273 | /* we can't check here that name comes from the doc dictionnary */ |
| pcercuei | 0:03b5121a232e | 2274 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2275 | } |
| pcercuei | 0:03b5121a232e | 2276 | memset(cur, 0, sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2277 | cur->type = XML_ELEMENT_NODE; |
| pcercuei | 0:03b5121a232e | 2278 | |
| pcercuei | 0:03b5121a232e | 2279 | cur->name = name; |
| pcercuei | 0:03b5121a232e | 2280 | cur->ns = ns; |
| pcercuei | 0:03b5121a232e | 2281 | |
| pcercuei | 0:03b5121a232e | 2282 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 2283 | xmlRegisterNodeDefaultValue((xmlNodePtr)cur); |
| pcercuei | 0:03b5121a232e | 2284 | return(cur); |
| pcercuei | 0:03b5121a232e | 2285 | } |
| pcercuei | 0:03b5121a232e | 2286 | |
| pcercuei | 0:03b5121a232e | 2287 | /** |
| pcercuei | 0:03b5121a232e | 2288 | * xmlNewDocNode: |
| pcercuei | 0:03b5121a232e | 2289 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 2290 | * @ns: namespace if any |
| pcercuei | 0:03b5121a232e | 2291 | * @name: the node name |
| pcercuei | 0:03b5121a232e | 2292 | * @content: the XML text content if any |
| pcercuei | 0:03b5121a232e | 2293 | * |
| pcercuei | 0:03b5121a232e | 2294 | * Creation of a new node element within a document. @ns and @content |
| pcercuei | 0:03b5121a232e | 2295 | * are optional (NULL). |
| pcercuei | 0:03b5121a232e | 2296 | * NOTE: @content is supposed to be a piece of XML CDATA, so it allow entities |
| pcercuei | 0:03b5121a232e | 2297 | * references, but XML special chars need to be escaped first by using |
| pcercuei | 0:03b5121a232e | 2298 | * xmlEncodeEntitiesReentrant(). Use xmlNewDocRawNode() if you don't |
| pcercuei | 0:03b5121a232e | 2299 | * need entities support. |
| pcercuei | 0:03b5121a232e | 2300 | * |
| pcercuei | 0:03b5121a232e | 2301 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2302 | */ |
| pcercuei | 0:03b5121a232e | 2303 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2304 | xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns, |
| pcercuei | 0:03b5121a232e | 2305 | const xmlChar *name, const xmlChar *content) { |
| pcercuei | 0:03b5121a232e | 2306 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2307 | |
| pcercuei | 0:03b5121a232e | 2308 | if ((doc != NULL) && (doc->dict != NULL)) |
| pcercuei | 0:03b5121a232e | 2309 | cur = xmlNewNodeEatName(ns, (xmlChar *) |
| pcercuei | 0:03b5121a232e | 2310 | xmlDictLookup(doc->dict, name, -1)); |
| pcercuei | 0:03b5121a232e | 2311 | else |
| pcercuei | 0:03b5121a232e | 2312 | cur = xmlNewNode(ns, name); |
| pcercuei | 0:03b5121a232e | 2313 | if (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 2314 | cur->doc = doc; |
| pcercuei | 0:03b5121a232e | 2315 | if (content != NULL) { |
| pcercuei | 0:03b5121a232e | 2316 | cur->children = xmlStringGetNodeList(doc, content); |
| pcercuei | 0:03b5121a232e | 2317 | UPDATE_LAST_CHILD_AND_PARENT(cur) |
| pcercuei | 0:03b5121a232e | 2318 | } |
| pcercuei | 0:03b5121a232e | 2319 | } |
| pcercuei | 0:03b5121a232e | 2320 | |
| pcercuei | 0:03b5121a232e | 2321 | return(cur); |
| pcercuei | 0:03b5121a232e | 2322 | } |
| pcercuei | 0:03b5121a232e | 2323 | |
| pcercuei | 0:03b5121a232e | 2324 | /** |
| pcercuei | 0:03b5121a232e | 2325 | * xmlNewDocNodeEatName: |
| pcercuei | 0:03b5121a232e | 2326 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 2327 | * @ns: namespace if any |
| pcercuei | 0:03b5121a232e | 2328 | * @name: the node name |
| pcercuei | 0:03b5121a232e | 2329 | * @content: the XML text content if any |
| pcercuei | 0:03b5121a232e | 2330 | * |
| pcercuei | 0:03b5121a232e | 2331 | * Creation of a new node element within a document. @ns and @content |
| pcercuei | 0:03b5121a232e | 2332 | * are optional (NULL). |
| pcercuei | 0:03b5121a232e | 2333 | * NOTE: @content is supposed to be a piece of XML CDATA, so it allow entities |
| pcercuei | 0:03b5121a232e | 2334 | * references, but XML special chars need to be escaped first by using |
| pcercuei | 0:03b5121a232e | 2335 | * xmlEncodeEntitiesReentrant(). Use xmlNewDocRawNode() if you don't |
| pcercuei | 0:03b5121a232e | 2336 | * need entities support. |
| pcercuei | 0:03b5121a232e | 2337 | * |
| pcercuei | 0:03b5121a232e | 2338 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2339 | */ |
| pcercuei | 0:03b5121a232e | 2340 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2341 | xmlNewDocNodeEatName(xmlDocPtr doc, xmlNsPtr ns, |
| pcercuei | 0:03b5121a232e | 2342 | xmlChar *name, const xmlChar *content) { |
| pcercuei | 0:03b5121a232e | 2343 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2344 | |
| pcercuei | 0:03b5121a232e | 2345 | cur = xmlNewNodeEatName(ns, name); |
| pcercuei | 0:03b5121a232e | 2346 | if (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 2347 | cur->doc = doc; |
| pcercuei | 0:03b5121a232e | 2348 | if (content != NULL) { |
| pcercuei | 0:03b5121a232e | 2349 | cur->children = xmlStringGetNodeList(doc, content); |
| pcercuei | 0:03b5121a232e | 2350 | UPDATE_LAST_CHILD_AND_PARENT(cur) |
| pcercuei | 0:03b5121a232e | 2351 | } |
| pcercuei | 0:03b5121a232e | 2352 | } else { |
| pcercuei | 0:03b5121a232e | 2353 | /* if name don't come from the doc dictionnary free it here */ |
| pcercuei | 0:03b5121a232e | 2354 | if ((name != NULL) && (doc != NULL) && |
| pcercuei | 0:03b5121a232e | 2355 | (!(xmlDictOwns(doc->dict, name)))) |
| pcercuei | 0:03b5121a232e | 2356 | xmlFree(name); |
| pcercuei | 0:03b5121a232e | 2357 | } |
| pcercuei | 0:03b5121a232e | 2358 | return(cur); |
| pcercuei | 0:03b5121a232e | 2359 | } |
| pcercuei | 0:03b5121a232e | 2360 | |
| pcercuei | 0:03b5121a232e | 2361 | #ifdef LIBXML_TREE_ENABLED |
| pcercuei | 0:03b5121a232e | 2362 | /** |
| pcercuei | 0:03b5121a232e | 2363 | * xmlNewDocRawNode: |
| pcercuei | 0:03b5121a232e | 2364 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 2365 | * @ns: namespace if any |
| pcercuei | 0:03b5121a232e | 2366 | * @name: the node name |
| pcercuei | 0:03b5121a232e | 2367 | * @content: the text content if any |
| pcercuei | 0:03b5121a232e | 2368 | * |
| pcercuei | 0:03b5121a232e | 2369 | * Creation of a new node element within a document. @ns and @content |
| pcercuei | 0:03b5121a232e | 2370 | * are optional (NULL). |
| pcercuei | 0:03b5121a232e | 2371 | * |
| pcercuei | 0:03b5121a232e | 2372 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2373 | */ |
| pcercuei | 0:03b5121a232e | 2374 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2375 | xmlNewDocRawNode(xmlDocPtr doc, xmlNsPtr ns, |
| pcercuei | 0:03b5121a232e | 2376 | const xmlChar *name, const xmlChar *content) { |
| pcercuei | 0:03b5121a232e | 2377 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2378 | |
| pcercuei | 0:03b5121a232e | 2379 | cur = xmlNewDocNode(doc, ns, name, NULL); |
| pcercuei | 0:03b5121a232e | 2380 | if (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 2381 | cur->doc = doc; |
| pcercuei | 0:03b5121a232e | 2382 | if (content != NULL) { |
| pcercuei | 0:03b5121a232e | 2383 | cur->children = xmlNewDocText(doc, content); |
| pcercuei | 0:03b5121a232e | 2384 | UPDATE_LAST_CHILD_AND_PARENT(cur) |
| pcercuei | 0:03b5121a232e | 2385 | } |
| pcercuei | 0:03b5121a232e | 2386 | } |
| pcercuei | 0:03b5121a232e | 2387 | return(cur); |
| pcercuei | 0:03b5121a232e | 2388 | } |
| pcercuei | 0:03b5121a232e | 2389 | |
| pcercuei | 0:03b5121a232e | 2390 | /** |
| pcercuei | 0:03b5121a232e | 2391 | * xmlNewDocFragment: |
| pcercuei | 0:03b5121a232e | 2392 | * @doc: the document owning the fragment |
| pcercuei | 0:03b5121a232e | 2393 | * |
| pcercuei | 0:03b5121a232e | 2394 | * Creation of a new Fragment node. |
| pcercuei | 0:03b5121a232e | 2395 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2396 | */ |
| pcercuei | 0:03b5121a232e | 2397 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2398 | xmlNewDocFragment(xmlDocPtr doc) { |
| pcercuei | 0:03b5121a232e | 2399 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2400 | |
| pcercuei | 0:03b5121a232e | 2401 | /* |
| pcercuei | 0:03b5121a232e | 2402 | * Allocate a new DocumentFragment node and fill the fields. |
| pcercuei | 0:03b5121a232e | 2403 | */ |
| pcercuei | 0:03b5121a232e | 2404 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2405 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 2406 | xmlTreeErrMemory("building fragment"); |
| pcercuei | 0:03b5121a232e | 2407 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2408 | } |
| pcercuei | 0:03b5121a232e | 2409 | memset(cur, 0, sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2410 | cur->type = XML_DOCUMENT_FRAG_NODE; |
| pcercuei | 0:03b5121a232e | 2411 | |
| pcercuei | 0:03b5121a232e | 2412 | cur->doc = doc; |
| pcercuei | 0:03b5121a232e | 2413 | |
| pcercuei | 0:03b5121a232e | 2414 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 2415 | xmlRegisterNodeDefaultValue(cur); |
| pcercuei | 0:03b5121a232e | 2416 | return(cur); |
| pcercuei | 0:03b5121a232e | 2417 | } |
| pcercuei | 0:03b5121a232e | 2418 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 2419 | |
| pcercuei | 0:03b5121a232e | 2420 | /** |
| pcercuei | 0:03b5121a232e | 2421 | * xmlNewText: |
| pcercuei | 0:03b5121a232e | 2422 | * @content: the text content |
| pcercuei | 0:03b5121a232e | 2423 | * |
| pcercuei | 0:03b5121a232e | 2424 | * Creation of a new text node. |
| pcercuei | 0:03b5121a232e | 2425 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2426 | */ |
| pcercuei | 0:03b5121a232e | 2427 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2428 | xmlNewText(const xmlChar *content) { |
| pcercuei | 0:03b5121a232e | 2429 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2430 | |
| pcercuei | 0:03b5121a232e | 2431 | /* |
| pcercuei | 0:03b5121a232e | 2432 | * Allocate a new node and fill the fields. |
| pcercuei | 0:03b5121a232e | 2433 | */ |
| pcercuei | 0:03b5121a232e | 2434 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2435 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 2436 | xmlTreeErrMemory("building text"); |
| pcercuei | 0:03b5121a232e | 2437 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2438 | } |
| pcercuei | 0:03b5121a232e | 2439 | memset(cur, 0, sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2440 | cur->type = XML_TEXT_NODE; |
| pcercuei | 0:03b5121a232e | 2441 | |
| pcercuei | 0:03b5121a232e | 2442 | cur->name = xmlStringText; |
| pcercuei | 0:03b5121a232e | 2443 | if (content != NULL) { |
| pcercuei | 0:03b5121a232e | 2444 | cur->content = xmlStrdup(content); |
| pcercuei | 0:03b5121a232e | 2445 | } |
| pcercuei | 0:03b5121a232e | 2446 | |
| pcercuei | 0:03b5121a232e | 2447 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 2448 | xmlRegisterNodeDefaultValue(cur); |
| pcercuei | 0:03b5121a232e | 2449 | return(cur); |
| pcercuei | 0:03b5121a232e | 2450 | } |
| pcercuei | 0:03b5121a232e | 2451 | |
| pcercuei | 0:03b5121a232e | 2452 | #ifdef LIBXML_TREE_ENABLED |
| pcercuei | 0:03b5121a232e | 2453 | /** |
| pcercuei | 0:03b5121a232e | 2454 | * xmlNewTextChild: |
| pcercuei | 0:03b5121a232e | 2455 | * @parent: the parent node |
| pcercuei | 0:03b5121a232e | 2456 | * @ns: a namespace if any |
| pcercuei | 0:03b5121a232e | 2457 | * @name: the name of the child |
| pcercuei | 0:03b5121a232e | 2458 | * @content: the text content of the child if any. |
| pcercuei | 0:03b5121a232e | 2459 | * |
| pcercuei | 0:03b5121a232e | 2460 | * Creation of a new child element, added at the end of @parent children list. |
| pcercuei | 0:03b5121a232e | 2461 | * @ns and @content parameters are optional (NULL). If @ns is NULL, the newly |
| pcercuei | 0:03b5121a232e | 2462 | * created element inherits the namespace of @parent. If @content is non NULL, |
| pcercuei | 0:03b5121a232e | 2463 | * a child TEXT node will be created containing the string @content. |
| pcercuei | 0:03b5121a232e | 2464 | * NOTE: Use xmlNewChild() if @content will contain entities that need to be |
| pcercuei | 0:03b5121a232e | 2465 | * preserved. Use this function, xmlNewTextChild(), if you need to ensure that |
| pcercuei | 0:03b5121a232e | 2466 | * reserved XML chars that might appear in @content, such as the ampersand, |
| pcercuei | 0:03b5121a232e | 2467 | * greater-than or less-than signs, are automatically replaced by their XML |
| pcercuei | 0:03b5121a232e | 2468 | * escaped entity representations. |
| pcercuei | 0:03b5121a232e | 2469 | * |
| pcercuei | 0:03b5121a232e | 2470 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2471 | */ |
| pcercuei | 0:03b5121a232e | 2472 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2473 | xmlNewTextChild(xmlNodePtr parent, xmlNsPtr ns, |
| pcercuei | 0:03b5121a232e | 2474 | const xmlChar *name, const xmlChar *content) { |
| pcercuei | 0:03b5121a232e | 2475 | xmlNodePtr cur, prev; |
| pcercuei | 0:03b5121a232e | 2476 | |
| pcercuei | 0:03b5121a232e | 2477 | if (parent == NULL) { |
| pcercuei | 0:03b5121a232e | 2478 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 2479 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 2480 | "xmlNewTextChild : parent == NULL\n"); |
| pcercuei | 0:03b5121a232e | 2481 | #endif |
| pcercuei | 0:03b5121a232e | 2482 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2483 | } |
| pcercuei | 0:03b5121a232e | 2484 | |
| pcercuei | 0:03b5121a232e | 2485 | if (name == NULL) { |
| pcercuei | 0:03b5121a232e | 2486 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 2487 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 2488 | "xmlNewTextChild : name == NULL\n"); |
| pcercuei | 0:03b5121a232e | 2489 | #endif |
| pcercuei | 0:03b5121a232e | 2490 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2491 | } |
| pcercuei | 0:03b5121a232e | 2492 | |
| pcercuei | 0:03b5121a232e | 2493 | /* |
| pcercuei | 0:03b5121a232e | 2494 | * Allocate a new node |
| pcercuei | 0:03b5121a232e | 2495 | */ |
| pcercuei | 0:03b5121a232e | 2496 | if (parent->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 2497 | if (ns == NULL) |
| pcercuei | 0:03b5121a232e | 2498 | cur = xmlNewDocRawNode(parent->doc, parent->ns, name, content); |
| pcercuei | 0:03b5121a232e | 2499 | else |
| pcercuei | 0:03b5121a232e | 2500 | cur = xmlNewDocRawNode(parent->doc, ns, name, content); |
| pcercuei | 0:03b5121a232e | 2501 | } else if ((parent->type == XML_DOCUMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 2502 | (parent->type == XML_HTML_DOCUMENT_NODE)) { |
| pcercuei | 0:03b5121a232e | 2503 | if (ns == NULL) |
| pcercuei | 0:03b5121a232e | 2504 | cur = xmlNewDocRawNode((xmlDocPtr) parent, NULL, name, content); |
| pcercuei | 0:03b5121a232e | 2505 | else |
| pcercuei | 0:03b5121a232e | 2506 | cur = xmlNewDocRawNode((xmlDocPtr) parent, ns, name, content); |
| pcercuei | 0:03b5121a232e | 2507 | } else if (parent->type == XML_DOCUMENT_FRAG_NODE) { |
| pcercuei | 0:03b5121a232e | 2508 | cur = xmlNewDocRawNode( parent->doc, ns, name, content); |
| pcercuei | 0:03b5121a232e | 2509 | } else { |
| pcercuei | 0:03b5121a232e | 2510 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2511 | } |
| pcercuei | 0:03b5121a232e | 2512 | if (cur == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 2513 | |
| pcercuei | 0:03b5121a232e | 2514 | /* |
| pcercuei | 0:03b5121a232e | 2515 | * add the new element at the end of the children list. |
| pcercuei | 0:03b5121a232e | 2516 | */ |
| pcercuei | 0:03b5121a232e | 2517 | cur->type = XML_ELEMENT_NODE; |
| pcercuei | 0:03b5121a232e | 2518 | cur->parent = parent; |
| pcercuei | 0:03b5121a232e | 2519 | cur->doc = parent->doc; |
| pcercuei | 0:03b5121a232e | 2520 | if (parent->children == NULL) { |
| pcercuei | 0:03b5121a232e | 2521 | parent->children = cur; |
| pcercuei | 0:03b5121a232e | 2522 | parent->last = cur; |
| pcercuei | 0:03b5121a232e | 2523 | } else { |
| pcercuei | 0:03b5121a232e | 2524 | prev = parent->last; |
| pcercuei | 0:03b5121a232e | 2525 | prev->next = cur; |
| pcercuei | 0:03b5121a232e | 2526 | cur->prev = prev; |
| pcercuei | 0:03b5121a232e | 2527 | parent->last = cur; |
| pcercuei | 0:03b5121a232e | 2528 | } |
| pcercuei | 0:03b5121a232e | 2529 | |
| pcercuei | 0:03b5121a232e | 2530 | return(cur); |
| pcercuei | 0:03b5121a232e | 2531 | } |
| pcercuei | 0:03b5121a232e | 2532 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 2533 | |
| pcercuei | 0:03b5121a232e | 2534 | /** |
| pcercuei | 0:03b5121a232e | 2535 | * xmlNewCharRef: |
| pcercuei | 0:03b5121a232e | 2536 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 2537 | * @name: the char ref string, starting with # or "&# ... ;" |
| pcercuei | 0:03b5121a232e | 2538 | * |
| pcercuei | 0:03b5121a232e | 2539 | * Creation of a new character reference node. |
| pcercuei | 0:03b5121a232e | 2540 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2541 | */ |
| pcercuei | 0:03b5121a232e | 2542 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2543 | xmlNewCharRef(xmlDocPtr doc, const xmlChar *name) { |
| pcercuei | 0:03b5121a232e | 2544 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2545 | |
| pcercuei | 0:03b5121a232e | 2546 | if (name == NULL) |
| pcercuei | 0:03b5121a232e | 2547 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2548 | |
| pcercuei | 0:03b5121a232e | 2549 | /* |
| pcercuei | 0:03b5121a232e | 2550 | * Allocate a new node and fill the fields. |
| pcercuei | 0:03b5121a232e | 2551 | */ |
| pcercuei | 0:03b5121a232e | 2552 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2553 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 2554 | xmlTreeErrMemory("building character reference"); |
| pcercuei | 0:03b5121a232e | 2555 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2556 | } |
| pcercuei | 0:03b5121a232e | 2557 | memset(cur, 0, sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2558 | cur->type = XML_ENTITY_REF_NODE; |
| pcercuei | 0:03b5121a232e | 2559 | |
| pcercuei | 0:03b5121a232e | 2560 | cur->doc = doc; |
| pcercuei | 0:03b5121a232e | 2561 | if (name[0] == '&') { |
| pcercuei | 0:03b5121a232e | 2562 | int len; |
| pcercuei | 0:03b5121a232e | 2563 | name++; |
| pcercuei | 0:03b5121a232e | 2564 | len = xmlStrlen(name); |
| pcercuei | 0:03b5121a232e | 2565 | if (name[len - 1] == ';') |
| pcercuei | 0:03b5121a232e | 2566 | cur->name = xmlStrndup(name, len - 1); |
| pcercuei | 0:03b5121a232e | 2567 | else |
| pcercuei | 0:03b5121a232e | 2568 | cur->name = xmlStrndup(name, len); |
| pcercuei | 0:03b5121a232e | 2569 | } else |
| pcercuei | 0:03b5121a232e | 2570 | cur->name = xmlStrdup(name); |
| pcercuei | 0:03b5121a232e | 2571 | |
| pcercuei | 0:03b5121a232e | 2572 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 2573 | xmlRegisterNodeDefaultValue(cur); |
| pcercuei | 0:03b5121a232e | 2574 | return(cur); |
| pcercuei | 0:03b5121a232e | 2575 | } |
| pcercuei | 0:03b5121a232e | 2576 | |
| pcercuei | 0:03b5121a232e | 2577 | /** |
| pcercuei | 0:03b5121a232e | 2578 | * xmlNewReference: |
| pcercuei | 0:03b5121a232e | 2579 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 2580 | * @name: the reference name, or the reference string with & and ; |
| pcercuei | 0:03b5121a232e | 2581 | * |
| pcercuei | 0:03b5121a232e | 2582 | * Creation of a new reference node. |
| pcercuei | 0:03b5121a232e | 2583 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2584 | */ |
| pcercuei | 0:03b5121a232e | 2585 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2586 | xmlNewReference(const xmlDoc *doc, const xmlChar *name) { |
| pcercuei | 0:03b5121a232e | 2587 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2588 | xmlEntityPtr ent; |
| pcercuei | 0:03b5121a232e | 2589 | |
| pcercuei | 0:03b5121a232e | 2590 | if (name == NULL) |
| pcercuei | 0:03b5121a232e | 2591 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2592 | |
| pcercuei | 0:03b5121a232e | 2593 | /* |
| pcercuei | 0:03b5121a232e | 2594 | * Allocate a new node and fill the fields. |
| pcercuei | 0:03b5121a232e | 2595 | */ |
| pcercuei | 0:03b5121a232e | 2596 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2597 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 2598 | xmlTreeErrMemory("building reference"); |
| pcercuei | 0:03b5121a232e | 2599 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2600 | } |
| pcercuei | 0:03b5121a232e | 2601 | memset(cur, 0, sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2602 | cur->type = XML_ENTITY_REF_NODE; |
| pcercuei | 0:03b5121a232e | 2603 | |
| pcercuei | 0:03b5121a232e | 2604 | cur->doc = (xmlDoc *)doc; |
| pcercuei | 0:03b5121a232e | 2605 | if (name[0] == '&') { |
| pcercuei | 0:03b5121a232e | 2606 | int len; |
| pcercuei | 0:03b5121a232e | 2607 | name++; |
| pcercuei | 0:03b5121a232e | 2608 | len = xmlStrlen(name); |
| pcercuei | 0:03b5121a232e | 2609 | if (name[len - 1] == ';') |
| pcercuei | 0:03b5121a232e | 2610 | cur->name = xmlStrndup(name, len - 1); |
| pcercuei | 0:03b5121a232e | 2611 | else |
| pcercuei | 0:03b5121a232e | 2612 | cur->name = xmlStrndup(name, len); |
| pcercuei | 0:03b5121a232e | 2613 | } else |
| pcercuei | 0:03b5121a232e | 2614 | cur->name = xmlStrdup(name); |
| pcercuei | 0:03b5121a232e | 2615 | |
| pcercuei | 0:03b5121a232e | 2616 | ent = xmlGetDocEntity(doc, cur->name); |
| pcercuei | 0:03b5121a232e | 2617 | if (ent != NULL) { |
| pcercuei | 0:03b5121a232e | 2618 | cur->content = ent->content; |
| pcercuei | 0:03b5121a232e | 2619 | /* |
| pcercuei | 0:03b5121a232e | 2620 | * The parent pointer in entity is a DTD pointer and thus is NOT |
| pcercuei | 0:03b5121a232e | 2621 | * updated. Not sure if this is 100% correct. |
| pcercuei | 0:03b5121a232e | 2622 | * -George |
| pcercuei | 0:03b5121a232e | 2623 | */ |
| pcercuei | 0:03b5121a232e | 2624 | cur->children = (xmlNodePtr) ent; |
| pcercuei | 0:03b5121a232e | 2625 | cur->last = (xmlNodePtr) ent; |
| pcercuei | 0:03b5121a232e | 2626 | } |
| pcercuei | 0:03b5121a232e | 2627 | |
| pcercuei | 0:03b5121a232e | 2628 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 2629 | xmlRegisterNodeDefaultValue(cur); |
| pcercuei | 0:03b5121a232e | 2630 | return(cur); |
| pcercuei | 0:03b5121a232e | 2631 | } |
| pcercuei | 0:03b5121a232e | 2632 | |
| pcercuei | 0:03b5121a232e | 2633 | /** |
| pcercuei | 0:03b5121a232e | 2634 | * xmlNewDocText: |
| pcercuei | 0:03b5121a232e | 2635 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 2636 | * @content: the text content |
| pcercuei | 0:03b5121a232e | 2637 | * |
| pcercuei | 0:03b5121a232e | 2638 | * Creation of a new text node within a document. |
| pcercuei | 0:03b5121a232e | 2639 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2640 | */ |
| pcercuei | 0:03b5121a232e | 2641 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2642 | xmlNewDocText(const xmlDoc *doc, const xmlChar *content) { |
| pcercuei | 0:03b5121a232e | 2643 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2644 | |
| pcercuei | 0:03b5121a232e | 2645 | cur = xmlNewText(content); |
| pcercuei | 0:03b5121a232e | 2646 | if (cur != NULL) cur->doc = (xmlDoc *)doc; |
| pcercuei | 0:03b5121a232e | 2647 | return(cur); |
| pcercuei | 0:03b5121a232e | 2648 | } |
| pcercuei | 0:03b5121a232e | 2649 | |
| pcercuei | 0:03b5121a232e | 2650 | /** |
| pcercuei | 0:03b5121a232e | 2651 | * xmlNewTextLen: |
| pcercuei | 0:03b5121a232e | 2652 | * @content: the text content |
| pcercuei | 0:03b5121a232e | 2653 | * @len: the text len. |
| pcercuei | 0:03b5121a232e | 2654 | * |
| pcercuei | 0:03b5121a232e | 2655 | * Creation of a new text node with an extra parameter for the content's length |
| pcercuei | 0:03b5121a232e | 2656 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2657 | */ |
| pcercuei | 0:03b5121a232e | 2658 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2659 | xmlNewTextLen(const xmlChar *content, int len) { |
| pcercuei | 0:03b5121a232e | 2660 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2661 | |
| pcercuei | 0:03b5121a232e | 2662 | /* |
| pcercuei | 0:03b5121a232e | 2663 | * Allocate a new node and fill the fields. |
| pcercuei | 0:03b5121a232e | 2664 | */ |
| pcercuei | 0:03b5121a232e | 2665 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2666 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 2667 | xmlTreeErrMemory("building text"); |
| pcercuei | 0:03b5121a232e | 2668 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2669 | } |
| pcercuei | 0:03b5121a232e | 2670 | memset(cur, 0, sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2671 | cur->type = XML_TEXT_NODE; |
| pcercuei | 0:03b5121a232e | 2672 | |
| pcercuei | 0:03b5121a232e | 2673 | cur->name = xmlStringText; |
| pcercuei | 0:03b5121a232e | 2674 | if (content != NULL) { |
| pcercuei | 0:03b5121a232e | 2675 | cur->content = xmlStrndup(content, len); |
| pcercuei | 0:03b5121a232e | 2676 | } |
| pcercuei | 0:03b5121a232e | 2677 | |
| pcercuei | 0:03b5121a232e | 2678 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 2679 | xmlRegisterNodeDefaultValue(cur); |
| pcercuei | 0:03b5121a232e | 2680 | return(cur); |
| pcercuei | 0:03b5121a232e | 2681 | } |
| pcercuei | 0:03b5121a232e | 2682 | |
| pcercuei | 0:03b5121a232e | 2683 | /** |
| pcercuei | 0:03b5121a232e | 2684 | * xmlNewDocTextLen: |
| pcercuei | 0:03b5121a232e | 2685 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 2686 | * @content: the text content |
| pcercuei | 0:03b5121a232e | 2687 | * @len: the text len. |
| pcercuei | 0:03b5121a232e | 2688 | * |
| pcercuei | 0:03b5121a232e | 2689 | * Creation of a new text node with an extra content length parameter. The |
| pcercuei | 0:03b5121a232e | 2690 | * text node pertain to a given document. |
| pcercuei | 0:03b5121a232e | 2691 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2692 | */ |
| pcercuei | 0:03b5121a232e | 2693 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2694 | xmlNewDocTextLen(xmlDocPtr doc, const xmlChar *content, int len) { |
| pcercuei | 0:03b5121a232e | 2695 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2696 | |
| pcercuei | 0:03b5121a232e | 2697 | cur = xmlNewTextLen(content, len); |
| pcercuei | 0:03b5121a232e | 2698 | if (cur != NULL) cur->doc = doc; |
| pcercuei | 0:03b5121a232e | 2699 | return(cur); |
| pcercuei | 0:03b5121a232e | 2700 | } |
| pcercuei | 0:03b5121a232e | 2701 | |
| pcercuei | 0:03b5121a232e | 2702 | /** |
| pcercuei | 0:03b5121a232e | 2703 | * xmlNewComment: |
| pcercuei | 0:03b5121a232e | 2704 | * @content: the comment content |
| pcercuei | 0:03b5121a232e | 2705 | * |
| pcercuei | 0:03b5121a232e | 2706 | * Creation of a new node containing a comment. |
| pcercuei | 0:03b5121a232e | 2707 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2708 | */ |
| pcercuei | 0:03b5121a232e | 2709 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2710 | xmlNewComment(const xmlChar *content) { |
| pcercuei | 0:03b5121a232e | 2711 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2712 | |
| pcercuei | 0:03b5121a232e | 2713 | /* |
| pcercuei | 0:03b5121a232e | 2714 | * Allocate a new node and fill the fields. |
| pcercuei | 0:03b5121a232e | 2715 | */ |
| pcercuei | 0:03b5121a232e | 2716 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2717 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 2718 | xmlTreeErrMemory("building comment"); |
| pcercuei | 0:03b5121a232e | 2719 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2720 | } |
| pcercuei | 0:03b5121a232e | 2721 | memset(cur, 0, sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2722 | cur->type = XML_COMMENT_NODE; |
| pcercuei | 0:03b5121a232e | 2723 | |
| pcercuei | 0:03b5121a232e | 2724 | cur->name = xmlStringComment; |
| pcercuei | 0:03b5121a232e | 2725 | if (content != NULL) { |
| pcercuei | 0:03b5121a232e | 2726 | cur->content = xmlStrdup(content); |
| pcercuei | 0:03b5121a232e | 2727 | } |
| pcercuei | 0:03b5121a232e | 2728 | |
| pcercuei | 0:03b5121a232e | 2729 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 2730 | xmlRegisterNodeDefaultValue(cur); |
| pcercuei | 0:03b5121a232e | 2731 | return(cur); |
| pcercuei | 0:03b5121a232e | 2732 | } |
| pcercuei | 0:03b5121a232e | 2733 | |
| pcercuei | 0:03b5121a232e | 2734 | /** |
| pcercuei | 0:03b5121a232e | 2735 | * xmlNewCDataBlock: |
| pcercuei | 0:03b5121a232e | 2736 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 2737 | * @content: the CDATA block content content |
| pcercuei | 0:03b5121a232e | 2738 | * @len: the length of the block |
| pcercuei | 0:03b5121a232e | 2739 | * |
| pcercuei | 0:03b5121a232e | 2740 | * Creation of a new node containing a CDATA block. |
| pcercuei | 0:03b5121a232e | 2741 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2742 | */ |
| pcercuei | 0:03b5121a232e | 2743 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2744 | xmlNewCDataBlock(xmlDocPtr doc, const xmlChar *content, int len) { |
| pcercuei | 0:03b5121a232e | 2745 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2746 | |
| pcercuei | 0:03b5121a232e | 2747 | /* |
| pcercuei | 0:03b5121a232e | 2748 | * Allocate a new node and fill the fields. |
| pcercuei | 0:03b5121a232e | 2749 | */ |
| pcercuei | 0:03b5121a232e | 2750 | cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2751 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 2752 | xmlTreeErrMemory("building CDATA"); |
| pcercuei | 0:03b5121a232e | 2753 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2754 | } |
| pcercuei | 0:03b5121a232e | 2755 | memset(cur, 0, sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 2756 | cur->type = XML_CDATA_SECTION_NODE; |
| pcercuei | 0:03b5121a232e | 2757 | cur->doc = doc; |
| pcercuei | 0:03b5121a232e | 2758 | |
| pcercuei | 0:03b5121a232e | 2759 | if (content != NULL) { |
| pcercuei | 0:03b5121a232e | 2760 | cur->content = xmlStrndup(content, len); |
| pcercuei | 0:03b5121a232e | 2761 | } |
| pcercuei | 0:03b5121a232e | 2762 | |
| pcercuei | 0:03b5121a232e | 2763 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 2764 | xmlRegisterNodeDefaultValue(cur); |
| pcercuei | 0:03b5121a232e | 2765 | return(cur); |
| pcercuei | 0:03b5121a232e | 2766 | } |
| pcercuei | 0:03b5121a232e | 2767 | |
| pcercuei | 0:03b5121a232e | 2768 | /** |
| pcercuei | 0:03b5121a232e | 2769 | * xmlNewDocComment: |
| pcercuei | 0:03b5121a232e | 2770 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 2771 | * @content: the comment content |
| pcercuei | 0:03b5121a232e | 2772 | * |
| pcercuei | 0:03b5121a232e | 2773 | * Creation of a new node containing a comment within a document. |
| pcercuei | 0:03b5121a232e | 2774 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2775 | */ |
| pcercuei | 0:03b5121a232e | 2776 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2777 | xmlNewDocComment(xmlDocPtr doc, const xmlChar *content) { |
| pcercuei | 0:03b5121a232e | 2778 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2779 | |
| pcercuei | 0:03b5121a232e | 2780 | cur = xmlNewComment(content); |
| pcercuei | 0:03b5121a232e | 2781 | if (cur != NULL) cur->doc = doc; |
| pcercuei | 0:03b5121a232e | 2782 | return(cur); |
| pcercuei | 0:03b5121a232e | 2783 | } |
| pcercuei | 0:03b5121a232e | 2784 | |
| pcercuei | 0:03b5121a232e | 2785 | /** |
| pcercuei | 0:03b5121a232e | 2786 | * xmlSetTreeDoc: |
| pcercuei | 0:03b5121a232e | 2787 | * @tree: the top element |
| pcercuei | 0:03b5121a232e | 2788 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 2789 | * |
| pcercuei | 0:03b5121a232e | 2790 | * update all nodes under the tree to point to the right document |
| pcercuei | 0:03b5121a232e | 2791 | */ |
| pcercuei | 0:03b5121a232e | 2792 | void |
| pcercuei | 0:03b5121a232e | 2793 | xmlSetTreeDoc(xmlNodePtr tree, xmlDocPtr doc) { |
| pcercuei | 0:03b5121a232e | 2794 | xmlAttrPtr prop; |
| pcercuei | 0:03b5121a232e | 2795 | |
| pcercuei | 0:03b5121a232e | 2796 | if ((tree == NULL) || (tree->type == XML_NAMESPACE_DECL)) |
| pcercuei | 0:03b5121a232e | 2797 | return; |
| pcercuei | 0:03b5121a232e | 2798 | if (tree->doc != doc) { |
| pcercuei | 0:03b5121a232e | 2799 | if(tree->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 2800 | prop = tree->properties; |
| pcercuei | 0:03b5121a232e | 2801 | while (prop != NULL) { |
| pcercuei | 0:03b5121a232e | 2802 | if (prop->atype == XML_ATTRIBUTE_ID) { |
| pcercuei | 0:03b5121a232e | 2803 | xmlRemoveID(tree->doc, prop); |
| pcercuei | 0:03b5121a232e | 2804 | } |
| pcercuei | 0:03b5121a232e | 2805 | |
| pcercuei | 0:03b5121a232e | 2806 | prop->doc = doc; |
| pcercuei | 0:03b5121a232e | 2807 | xmlSetListDoc(prop->children, doc); |
| pcercuei | 0:03b5121a232e | 2808 | |
| pcercuei | 0:03b5121a232e | 2809 | /* |
| pcercuei | 0:03b5121a232e | 2810 | * TODO: ID attributes should be also added to the new |
| pcercuei | 0:03b5121a232e | 2811 | * document, but this breaks things like xmlReplaceNode. |
| pcercuei | 0:03b5121a232e | 2812 | * The underlying problem is that xmlRemoveID is only called |
| pcercuei | 0:03b5121a232e | 2813 | * if a node is destroyed, not if it's unlinked. |
| pcercuei | 0:03b5121a232e | 2814 | */ |
| pcercuei | 0:03b5121a232e | 2815 | #if 0 |
| pcercuei | 0:03b5121a232e | 2816 | if (xmlIsID(doc, tree, prop)) { |
| pcercuei | 0:03b5121a232e | 2817 | xmlChar *idVal = xmlNodeListGetString(doc, prop->children, |
| pcercuei | 0:03b5121a232e | 2818 | 1); |
| pcercuei | 0:03b5121a232e | 2819 | xmlAddID(NULL, doc, idVal, prop); |
| pcercuei | 0:03b5121a232e | 2820 | } |
| pcercuei | 0:03b5121a232e | 2821 | #endif |
| pcercuei | 0:03b5121a232e | 2822 | |
| pcercuei | 0:03b5121a232e | 2823 | prop = prop->next; |
| pcercuei | 0:03b5121a232e | 2824 | } |
| pcercuei | 0:03b5121a232e | 2825 | } |
| pcercuei | 0:03b5121a232e | 2826 | if (tree->children != NULL) |
| pcercuei | 0:03b5121a232e | 2827 | xmlSetListDoc(tree->children, doc); |
| pcercuei | 0:03b5121a232e | 2828 | tree->doc = doc; |
| pcercuei | 0:03b5121a232e | 2829 | } |
| pcercuei | 0:03b5121a232e | 2830 | } |
| pcercuei | 0:03b5121a232e | 2831 | |
| pcercuei | 0:03b5121a232e | 2832 | /** |
| pcercuei | 0:03b5121a232e | 2833 | * xmlSetListDoc: |
| pcercuei | 0:03b5121a232e | 2834 | * @list: the first element |
| pcercuei | 0:03b5121a232e | 2835 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 2836 | * |
| pcercuei | 0:03b5121a232e | 2837 | * update all nodes in the list to point to the right document |
| pcercuei | 0:03b5121a232e | 2838 | */ |
| pcercuei | 0:03b5121a232e | 2839 | void |
| pcercuei | 0:03b5121a232e | 2840 | xmlSetListDoc(xmlNodePtr list, xmlDocPtr doc) { |
| pcercuei | 0:03b5121a232e | 2841 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 2842 | |
| pcercuei | 0:03b5121a232e | 2843 | if ((list == NULL) || (list->type == XML_NAMESPACE_DECL)) |
| pcercuei | 0:03b5121a232e | 2844 | return; |
| pcercuei | 0:03b5121a232e | 2845 | cur = list; |
| pcercuei | 0:03b5121a232e | 2846 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 2847 | if (cur->doc != doc) |
| pcercuei | 0:03b5121a232e | 2848 | xmlSetTreeDoc(cur, doc); |
| pcercuei | 0:03b5121a232e | 2849 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 2850 | } |
| pcercuei | 0:03b5121a232e | 2851 | } |
| pcercuei | 0:03b5121a232e | 2852 | |
| pcercuei | 0:03b5121a232e | 2853 | #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) |
| pcercuei | 0:03b5121a232e | 2854 | /** |
| pcercuei | 0:03b5121a232e | 2855 | * xmlNewChild: |
| pcercuei | 0:03b5121a232e | 2856 | * @parent: the parent node |
| pcercuei | 0:03b5121a232e | 2857 | * @ns: a namespace if any |
| pcercuei | 0:03b5121a232e | 2858 | * @name: the name of the child |
| pcercuei | 0:03b5121a232e | 2859 | * @content: the XML content of the child if any. |
| pcercuei | 0:03b5121a232e | 2860 | * |
| pcercuei | 0:03b5121a232e | 2861 | * Creation of a new child element, added at the end of @parent children list. |
| pcercuei | 0:03b5121a232e | 2862 | * @ns and @content parameters are optional (NULL). If @ns is NULL, the newly |
| pcercuei | 0:03b5121a232e | 2863 | * created element inherits the namespace of @parent. If @content is non NULL, |
| pcercuei | 0:03b5121a232e | 2864 | * a child list containing the TEXTs and ENTITY_REFs node will be created. |
| pcercuei | 0:03b5121a232e | 2865 | * NOTE: @content is supposed to be a piece of XML CDATA, so it allows entity |
| pcercuei | 0:03b5121a232e | 2866 | * references. XML special chars must be escaped first by using |
| pcercuei | 0:03b5121a232e | 2867 | * xmlEncodeEntitiesReentrant(), or xmlNewTextChild() should be used. |
| pcercuei | 0:03b5121a232e | 2868 | * |
| pcercuei | 0:03b5121a232e | 2869 | * Returns a pointer to the new node object. |
| pcercuei | 0:03b5121a232e | 2870 | */ |
| pcercuei | 0:03b5121a232e | 2871 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2872 | xmlNewChild(xmlNodePtr parent, xmlNsPtr ns, |
| pcercuei | 0:03b5121a232e | 2873 | const xmlChar *name, const xmlChar *content) { |
| pcercuei | 0:03b5121a232e | 2874 | xmlNodePtr cur, prev; |
| pcercuei | 0:03b5121a232e | 2875 | |
| pcercuei | 0:03b5121a232e | 2876 | if (parent == NULL) { |
| pcercuei | 0:03b5121a232e | 2877 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 2878 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 2879 | "xmlNewChild : parent == NULL\n"); |
| pcercuei | 0:03b5121a232e | 2880 | #endif |
| pcercuei | 0:03b5121a232e | 2881 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2882 | } |
| pcercuei | 0:03b5121a232e | 2883 | |
| pcercuei | 0:03b5121a232e | 2884 | if (name == NULL) { |
| pcercuei | 0:03b5121a232e | 2885 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 2886 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 2887 | "xmlNewChild : name == NULL\n"); |
| pcercuei | 0:03b5121a232e | 2888 | #endif |
| pcercuei | 0:03b5121a232e | 2889 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2890 | } |
| pcercuei | 0:03b5121a232e | 2891 | |
| pcercuei | 0:03b5121a232e | 2892 | /* |
| pcercuei | 0:03b5121a232e | 2893 | * Allocate a new node |
| pcercuei | 0:03b5121a232e | 2894 | */ |
| pcercuei | 0:03b5121a232e | 2895 | if (parent->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 2896 | if (ns == NULL) |
| pcercuei | 0:03b5121a232e | 2897 | cur = xmlNewDocNode(parent->doc, parent->ns, name, content); |
| pcercuei | 0:03b5121a232e | 2898 | else |
| pcercuei | 0:03b5121a232e | 2899 | cur = xmlNewDocNode(parent->doc, ns, name, content); |
| pcercuei | 0:03b5121a232e | 2900 | } else if ((parent->type == XML_DOCUMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 2901 | (parent->type == XML_HTML_DOCUMENT_NODE)) { |
| pcercuei | 0:03b5121a232e | 2902 | if (ns == NULL) |
| pcercuei | 0:03b5121a232e | 2903 | cur = xmlNewDocNode((xmlDocPtr) parent, NULL, name, content); |
| pcercuei | 0:03b5121a232e | 2904 | else |
| pcercuei | 0:03b5121a232e | 2905 | cur = xmlNewDocNode((xmlDocPtr) parent, ns, name, content); |
| pcercuei | 0:03b5121a232e | 2906 | } else if (parent->type == XML_DOCUMENT_FRAG_NODE) { |
| pcercuei | 0:03b5121a232e | 2907 | cur = xmlNewDocNode( parent->doc, ns, name, content); |
| pcercuei | 0:03b5121a232e | 2908 | } else { |
| pcercuei | 0:03b5121a232e | 2909 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2910 | } |
| pcercuei | 0:03b5121a232e | 2911 | if (cur == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 2912 | |
| pcercuei | 0:03b5121a232e | 2913 | /* |
| pcercuei | 0:03b5121a232e | 2914 | * add the new element at the end of the children list. |
| pcercuei | 0:03b5121a232e | 2915 | */ |
| pcercuei | 0:03b5121a232e | 2916 | cur->type = XML_ELEMENT_NODE; |
| pcercuei | 0:03b5121a232e | 2917 | cur->parent = parent; |
| pcercuei | 0:03b5121a232e | 2918 | cur->doc = parent->doc; |
| pcercuei | 0:03b5121a232e | 2919 | if (parent->children == NULL) { |
| pcercuei | 0:03b5121a232e | 2920 | parent->children = cur; |
| pcercuei | 0:03b5121a232e | 2921 | parent->last = cur; |
| pcercuei | 0:03b5121a232e | 2922 | } else { |
| pcercuei | 0:03b5121a232e | 2923 | prev = parent->last; |
| pcercuei | 0:03b5121a232e | 2924 | prev->next = cur; |
| pcercuei | 0:03b5121a232e | 2925 | cur->prev = prev; |
| pcercuei | 0:03b5121a232e | 2926 | parent->last = cur; |
| pcercuei | 0:03b5121a232e | 2927 | } |
| pcercuei | 0:03b5121a232e | 2928 | |
| pcercuei | 0:03b5121a232e | 2929 | return(cur); |
| pcercuei | 0:03b5121a232e | 2930 | } |
| pcercuei | 0:03b5121a232e | 2931 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 2932 | |
| pcercuei | 0:03b5121a232e | 2933 | /** |
| pcercuei | 0:03b5121a232e | 2934 | * xmlAddPropSibling: |
| pcercuei | 0:03b5121a232e | 2935 | * @prev: the attribute to which @prop is added after |
| pcercuei | 0:03b5121a232e | 2936 | * @cur: the base attribute passed to calling function |
| pcercuei | 0:03b5121a232e | 2937 | * @prop: the new attribute |
| pcercuei | 0:03b5121a232e | 2938 | * |
| pcercuei | 0:03b5121a232e | 2939 | * Add a new attribute after @prev using @cur as base attribute. |
| pcercuei | 0:03b5121a232e | 2940 | * When inserting before @cur, @prev is passed as @cur->prev. |
| pcercuei | 0:03b5121a232e | 2941 | * When inserting after @cur, @prev is passed as @cur. |
| pcercuei | 0:03b5121a232e | 2942 | * If an existing attribute is found it is detroyed prior to adding @prop. |
| pcercuei | 0:03b5121a232e | 2943 | * |
| pcercuei | 0:03b5121a232e | 2944 | * Returns the attribute being inserted or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 2945 | */ |
| pcercuei | 0:03b5121a232e | 2946 | static xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2947 | xmlAddPropSibling(xmlNodePtr prev, xmlNodePtr cur, xmlNodePtr prop) { |
| pcercuei | 0:03b5121a232e | 2948 | xmlAttrPtr attr; |
| pcercuei | 0:03b5121a232e | 2949 | |
| pcercuei | 0:03b5121a232e | 2950 | if ((cur == NULL) || (cur->type != XML_ATTRIBUTE_NODE) || |
| pcercuei | 0:03b5121a232e | 2951 | (prop == NULL) || (prop->type != XML_ATTRIBUTE_NODE) || |
| pcercuei | 0:03b5121a232e | 2952 | ((prev != NULL) && (prev->type != XML_ATTRIBUTE_NODE))) |
| pcercuei | 0:03b5121a232e | 2953 | return(NULL); |
| pcercuei | 0:03b5121a232e | 2954 | |
| pcercuei | 0:03b5121a232e | 2955 | /* check if an attribute with the same name exists */ |
| pcercuei | 0:03b5121a232e | 2956 | if (prop->ns == NULL) |
| pcercuei | 0:03b5121a232e | 2957 | attr = xmlHasNsProp(cur->parent, prop->name, NULL); |
| pcercuei | 0:03b5121a232e | 2958 | else |
| pcercuei | 0:03b5121a232e | 2959 | attr = xmlHasNsProp(cur->parent, prop->name, prop->ns->href); |
| pcercuei | 0:03b5121a232e | 2960 | |
| pcercuei | 0:03b5121a232e | 2961 | if (prop->doc != cur->doc) { |
| pcercuei | 0:03b5121a232e | 2962 | xmlSetTreeDoc(prop, cur->doc); |
| pcercuei | 0:03b5121a232e | 2963 | } |
| pcercuei | 0:03b5121a232e | 2964 | prop->parent = cur->parent; |
| pcercuei | 0:03b5121a232e | 2965 | prop->prev = prev; |
| pcercuei | 0:03b5121a232e | 2966 | if (prev != NULL) { |
| pcercuei | 0:03b5121a232e | 2967 | prop->next = prev->next; |
| pcercuei | 0:03b5121a232e | 2968 | prev->next = prop; |
| pcercuei | 0:03b5121a232e | 2969 | if (prop->next) |
| pcercuei | 0:03b5121a232e | 2970 | prop->next->prev = prop; |
| pcercuei | 0:03b5121a232e | 2971 | } else { |
| pcercuei | 0:03b5121a232e | 2972 | prop->next = cur; |
| pcercuei | 0:03b5121a232e | 2973 | cur->prev = prop; |
| pcercuei | 0:03b5121a232e | 2974 | } |
| pcercuei | 0:03b5121a232e | 2975 | if (prop->prev == NULL && prop->parent != NULL) |
| pcercuei | 0:03b5121a232e | 2976 | prop->parent->properties = (xmlAttrPtr) prop; |
| pcercuei | 0:03b5121a232e | 2977 | if ((attr != NULL) && (attr->type != XML_ATTRIBUTE_DECL)) { |
| pcercuei | 0:03b5121a232e | 2978 | /* different instance, destroy it (attributes must be unique) */ |
| pcercuei | 0:03b5121a232e | 2979 | xmlRemoveProp((xmlAttrPtr) attr); |
| pcercuei | 0:03b5121a232e | 2980 | } |
| pcercuei | 0:03b5121a232e | 2981 | return prop; |
| pcercuei | 0:03b5121a232e | 2982 | } |
| pcercuei | 0:03b5121a232e | 2983 | |
| pcercuei | 0:03b5121a232e | 2984 | /** |
| pcercuei | 0:03b5121a232e | 2985 | * xmlAddNextSibling: |
| pcercuei | 0:03b5121a232e | 2986 | * @cur: the child node |
| pcercuei | 0:03b5121a232e | 2987 | * @elem: the new node |
| pcercuei | 0:03b5121a232e | 2988 | * |
| pcercuei | 0:03b5121a232e | 2989 | * Add a new node @elem as the next sibling of @cur |
| pcercuei | 0:03b5121a232e | 2990 | * If the new node was already inserted in a document it is |
| pcercuei | 0:03b5121a232e | 2991 | * first unlinked from its existing context. |
| pcercuei | 0:03b5121a232e | 2992 | * As a result of text merging @elem may be freed. |
| pcercuei | 0:03b5121a232e | 2993 | * If the new node is ATTRIBUTE, it is added into properties instead of children. |
| pcercuei | 0:03b5121a232e | 2994 | * If there is an attribute with equal name, it is first destroyed. |
| pcercuei | 0:03b5121a232e | 2995 | * |
| pcercuei | 0:03b5121a232e | 2996 | * Returns the new node or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 2997 | */ |
| pcercuei | 0:03b5121a232e | 2998 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 2999 | xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) { |
| pcercuei | 0:03b5121a232e | 3000 | if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { |
| pcercuei | 0:03b5121a232e | 3001 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3002 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3003 | "xmlAddNextSibling : cur == NULL\n"); |
| pcercuei | 0:03b5121a232e | 3004 | #endif |
| pcercuei | 0:03b5121a232e | 3005 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3006 | } |
| pcercuei | 0:03b5121a232e | 3007 | if ((elem == NULL) || (elem->type == XML_NAMESPACE_DECL)) { |
| pcercuei | 0:03b5121a232e | 3008 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3009 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3010 | "xmlAddNextSibling : elem == NULL\n"); |
| pcercuei | 0:03b5121a232e | 3011 | #endif |
| pcercuei | 0:03b5121a232e | 3012 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3013 | } |
| pcercuei | 0:03b5121a232e | 3014 | |
| pcercuei | 0:03b5121a232e | 3015 | if (cur == elem) { |
| pcercuei | 0:03b5121a232e | 3016 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3017 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3018 | "xmlAddNextSibling : cur == elem\n"); |
| pcercuei | 0:03b5121a232e | 3019 | #endif |
| pcercuei | 0:03b5121a232e | 3020 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3021 | } |
| pcercuei | 0:03b5121a232e | 3022 | |
| pcercuei | 0:03b5121a232e | 3023 | xmlUnlinkNode(elem); |
| pcercuei | 0:03b5121a232e | 3024 | |
| pcercuei | 0:03b5121a232e | 3025 | if (elem->type == XML_TEXT_NODE) { |
| pcercuei | 0:03b5121a232e | 3026 | if (cur->type == XML_TEXT_NODE) { |
| pcercuei | 0:03b5121a232e | 3027 | xmlNodeAddContent(cur, elem->content); |
| pcercuei | 0:03b5121a232e | 3028 | xmlFreeNode(elem); |
| pcercuei | 0:03b5121a232e | 3029 | return(cur); |
| pcercuei | 0:03b5121a232e | 3030 | } |
| pcercuei | 0:03b5121a232e | 3031 | if ((cur->next != NULL) && (cur->next->type == XML_TEXT_NODE) && |
| pcercuei | 0:03b5121a232e | 3032 | (cur->name == cur->next->name)) { |
| pcercuei | 0:03b5121a232e | 3033 | xmlChar *tmp; |
| pcercuei | 0:03b5121a232e | 3034 | |
| pcercuei | 0:03b5121a232e | 3035 | tmp = xmlStrdup(elem->content); |
| pcercuei | 0:03b5121a232e | 3036 | tmp = xmlStrcat(tmp, cur->next->content); |
| pcercuei | 0:03b5121a232e | 3037 | xmlNodeSetContent(cur->next, tmp); |
| pcercuei | 0:03b5121a232e | 3038 | xmlFree(tmp); |
| pcercuei | 0:03b5121a232e | 3039 | xmlFreeNode(elem); |
| pcercuei | 0:03b5121a232e | 3040 | return(cur->next); |
| pcercuei | 0:03b5121a232e | 3041 | } |
| pcercuei | 0:03b5121a232e | 3042 | } else if (elem->type == XML_ATTRIBUTE_NODE) { |
| pcercuei | 0:03b5121a232e | 3043 | return xmlAddPropSibling(cur, cur, elem); |
| pcercuei | 0:03b5121a232e | 3044 | } |
| pcercuei | 0:03b5121a232e | 3045 | |
| pcercuei | 0:03b5121a232e | 3046 | if (elem->doc != cur->doc) { |
| pcercuei | 0:03b5121a232e | 3047 | xmlSetTreeDoc(elem, cur->doc); |
| pcercuei | 0:03b5121a232e | 3048 | } |
| pcercuei | 0:03b5121a232e | 3049 | elem->parent = cur->parent; |
| pcercuei | 0:03b5121a232e | 3050 | elem->prev = cur; |
| pcercuei | 0:03b5121a232e | 3051 | elem->next = cur->next; |
| pcercuei | 0:03b5121a232e | 3052 | cur->next = elem; |
| pcercuei | 0:03b5121a232e | 3053 | if (elem->next != NULL) |
| pcercuei | 0:03b5121a232e | 3054 | elem->next->prev = elem; |
| pcercuei | 0:03b5121a232e | 3055 | if ((elem->parent != NULL) && (elem->parent->last == cur)) |
| pcercuei | 0:03b5121a232e | 3056 | elem->parent->last = elem; |
| pcercuei | 0:03b5121a232e | 3057 | return(elem); |
| pcercuei | 0:03b5121a232e | 3058 | } |
| pcercuei | 0:03b5121a232e | 3059 | |
| pcercuei | 0:03b5121a232e | 3060 | #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_HTML_ENABLED) || \ |
| pcercuei | 0:03b5121a232e | 3061 | defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED) |
| pcercuei | 0:03b5121a232e | 3062 | /** |
| pcercuei | 0:03b5121a232e | 3063 | * xmlAddPrevSibling: |
| pcercuei | 0:03b5121a232e | 3064 | * @cur: the child node |
| pcercuei | 0:03b5121a232e | 3065 | * @elem: the new node |
| pcercuei | 0:03b5121a232e | 3066 | * |
| pcercuei | 0:03b5121a232e | 3067 | * Add a new node @elem as the previous sibling of @cur |
| pcercuei | 0:03b5121a232e | 3068 | * merging adjacent TEXT nodes (@elem may be freed) |
| pcercuei | 0:03b5121a232e | 3069 | * If the new node was already inserted in a document it is |
| pcercuei | 0:03b5121a232e | 3070 | * first unlinked from its existing context. |
| pcercuei | 0:03b5121a232e | 3071 | * If the new node is ATTRIBUTE, it is added into properties instead of children. |
| pcercuei | 0:03b5121a232e | 3072 | * If there is an attribute with equal name, it is first destroyed. |
| pcercuei | 0:03b5121a232e | 3073 | * |
| pcercuei | 0:03b5121a232e | 3074 | * Returns the new node or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 3075 | */ |
| pcercuei | 0:03b5121a232e | 3076 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 3077 | xmlAddPrevSibling(xmlNodePtr cur, xmlNodePtr elem) { |
| pcercuei | 0:03b5121a232e | 3078 | if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { |
| pcercuei | 0:03b5121a232e | 3079 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3080 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3081 | "xmlAddPrevSibling : cur == NULL\n"); |
| pcercuei | 0:03b5121a232e | 3082 | #endif |
| pcercuei | 0:03b5121a232e | 3083 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3084 | } |
| pcercuei | 0:03b5121a232e | 3085 | if ((elem == NULL) || (elem->type == XML_NAMESPACE_DECL)) { |
| pcercuei | 0:03b5121a232e | 3086 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3087 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3088 | "xmlAddPrevSibling : elem == NULL\n"); |
| pcercuei | 0:03b5121a232e | 3089 | #endif |
| pcercuei | 0:03b5121a232e | 3090 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3091 | } |
| pcercuei | 0:03b5121a232e | 3092 | |
| pcercuei | 0:03b5121a232e | 3093 | if (cur == elem) { |
| pcercuei | 0:03b5121a232e | 3094 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3095 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3096 | "xmlAddPrevSibling : cur == elem\n"); |
| pcercuei | 0:03b5121a232e | 3097 | #endif |
| pcercuei | 0:03b5121a232e | 3098 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3099 | } |
| pcercuei | 0:03b5121a232e | 3100 | |
| pcercuei | 0:03b5121a232e | 3101 | xmlUnlinkNode(elem); |
| pcercuei | 0:03b5121a232e | 3102 | |
| pcercuei | 0:03b5121a232e | 3103 | if (elem->type == XML_TEXT_NODE) { |
| pcercuei | 0:03b5121a232e | 3104 | if (cur->type == XML_TEXT_NODE) { |
| pcercuei | 0:03b5121a232e | 3105 | xmlChar *tmp; |
| pcercuei | 0:03b5121a232e | 3106 | |
| pcercuei | 0:03b5121a232e | 3107 | tmp = xmlStrdup(elem->content); |
| pcercuei | 0:03b5121a232e | 3108 | tmp = xmlStrcat(tmp, cur->content); |
| pcercuei | 0:03b5121a232e | 3109 | xmlNodeSetContent(cur, tmp); |
| pcercuei | 0:03b5121a232e | 3110 | xmlFree(tmp); |
| pcercuei | 0:03b5121a232e | 3111 | xmlFreeNode(elem); |
| pcercuei | 0:03b5121a232e | 3112 | return(cur); |
| pcercuei | 0:03b5121a232e | 3113 | } |
| pcercuei | 0:03b5121a232e | 3114 | if ((cur->prev != NULL) && (cur->prev->type == XML_TEXT_NODE) && |
| pcercuei | 0:03b5121a232e | 3115 | (cur->name == cur->prev->name)) { |
| pcercuei | 0:03b5121a232e | 3116 | xmlNodeAddContent(cur->prev, elem->content); |
| pcercuei | 0:03b5121a232e | 3117 | xmlFreeNode(elem); |
| pcercuei | 0:03b5121a232e | 3118 | return(cur->prev); |
| pcercuei | 0:03b5121a232e | 3119 | } |
| pcercuei | 0:03b5121a232e | 3120 | } else if (elem->type == XML_ATTRIBUTE_NODE) { |
| pcercuei | 0:03b5121a232e | 3121 | return xmlAddPropSibling(cur->prev, cur, elem); |
| pcercuei | 0:03b5121a232e | 3122 | } |
| pcercuei | 0:03b5121a232e | 3123 | |
| pcercuei | 0:03b5121a232e | 3124 | if (elem->doc != cur->doc) { |
| pcercuei | 0:03b5121a232e | 3125 | xmlSetTreeDoc(elem, cur->doc); |
| pcercuei | 0:03b5121a232e | 3126 | } |
| pcercuei | 0:03b5121a232e | 3127 | elem->parent = cur->parent; |
| pcercuei | 0:03b5121a232e | 3128 | elem->next = cur; |
| pcercuei | 0:03b5121a232e | 3129 | elem->prev = cur->prev; |
| pcercuei | 0:03b5121a232e | 3130 | cur->prev = elem; |
| pcercuei | 0:03b5121a232e | 3131 | if (elem->prev != NULL) |
| pcercuei | 0:03b5121a232e | 3132 | elem->prev->next = elem; |
| pcercuei | 0:03b5121a232e | 3133 | if ((elem->parent != NULL) && (elem->parent->children == cur)) { |
| pcercuei | 0:03b5121a232e | 3134 | elem->parent->children = elem; |
| pcercuei | 0:03b5121a232e | 3135 | } |
| pcercuei | 0:03b5121a232e | 3136 | return(elem); |
| pcercuei | 0:03b5121a232e | 3137 | } |
| pcercuei | 0:03b5121a232e | 3138 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 3139 | |
| pcercuei | 0:03b5121a232e | 3140 | /** |
| pcercuei | 0:03b5121a232e | 3141 | * xmlAddSibling: |
| pcercuei | 0:03b5121a232e | 3142 | * @cur: the child node |
| pcercuei | 0:03b5121a232e | 3143 | * @elem: the new node |
| pcercuei | 0:03b5121a232e | 3144 | * |
| pcercuei | 0:03b5121a232e | 3145 | * Add a new element @elem to the list of siblings of @cur |
| pcercuei | 0:03b5121a232e | 3146 | * merging adjacent TEXT nodes (@elem may be freed) |
| pcercuei | 0:03b5121a232e | 3147 | * If the new element was already inserted in a document it is |
| pcercuei | 0:03b5121a232e | 3148 | * first unlinked from its existing context. |
| pcercuei | 0:03b5121a232e | 3149 | * |
| pcercuei | 0:03b5121a232e | 3150 | * Returns the new element or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 3151 | */ |
| pcercuei | 0:03b5121a232e | 3152 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 3153 | xmlAddSibling(xmlNodePtr cur, xmlNodePtr elem) { |
| pcercuei | 0:03b5121a232e | 3154 | xmlNodePtr parent; |
| pcercuei | 0:03b5121a232e | 3155 | |
| pcercuei | 0:03b5121a232e | 3156 | if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { |
| pcercuei | 0:03b5121a232e | 3157 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3158 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3159 | "xmlAddSibling : cur == NULL\n"); |
| pcercuei | 0:03b5121a232e | 3160 | #endif |
| pcercuei | 0:03b5121a232e | 3161 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3162 | } |
| pcercuei | 0:03b5121a232e | 3163 | |
| pcercuei | 0:03b5121a232e | 3164 | if ((elem == NULL) || (elem->type == XML_NAMESPACE_DECL)) { |
| pcercuei | 0:03b5121a232e | 3165 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3166 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3167 | "xmlAddSibling : elem == NULL\n"); |
| pcercuei | 0:03b5121a232e | 3168 | #endif |
| pcercuei | 0:03b5121a232e | 3169 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3170 | } |
| pcercuei | 0:03b5121a232e | 3171 | |
| pcercuei | 0:03b5121a232e | 3172 | if (cur == elem) { |
| pcercuei | 0:03b5121a232e | 3173 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3174 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3175 | "xmlAddSibling : cur == elem\n"); |
| pcercuei | 0:03b5121a232e | 3176 | #endif |
| pcercuei | 0:03b5121a232e | 3177 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3178 | } |
| pcercuei | 0:03b5121a232e | 3179 | |
| pcercuei | 0:03b5121a232e | 3180 | /* |
| pcercuei | 0:03b5121a232e | 3181 | * Constant time is we can rely on the ->parent->last to find |
| pcercuei | 0:03b5121a232e | 3182 | * the last sibling. |
| pcercuei | 0:03b5121a232e | 3183 | */ |
| pcercuei | 0:03b5121a232e | 3184 | if ((cur->type != XML_ATTRIBUTE_NODE) && (cur->parent != NULL) && |
| pcercuei | 0:03b5121a232e | 3185 | (cur->parent->children != NULL) && |
| pcercuei | 0:03b5121a232e | 3186 | (cur->parent->last != NULL) && |
| pcercuei | 0:03b5121a232e | 3187 | (cur->parent->last->next == NULL)) { |
| pcercuei | 0:03b5121a232e | 3188 | cur = cur->parent->last; |
| pcercuei | 0:03b5121a232e | 3189 | } else { |
| pcercuei | 0:03b5121a232e | 3190 | while (cur->next != NULL) cur = cur->next; |
| pcercuei | 0:03b5121a232e | 3191 | } |
| pcercuei | 0:03b5121a232e | 3192 | |
| pcercuei | 0:03b5121a232e | 3193 | xmlUnlinkNode(elem); |
| pcercuei | 0:03b5121a232e | 3194 | |
| pcercuei | 0:03b5121a232e | 3195 | if ((cur->type == XML_TEXT_NODE) && (elem->type == XML_TEXT_NODE) && |
| pcercuei | 0:03b5121a232e | 3196 | (cur->name == elem->name)) { |
| pcercuei | 0:03b5121a232e | 3197 | xmlNodeAddContent(cur, elem->content); |
| pcercuei | 0:03b5121a232e | 3198 | xmlFreeNode(elem); |
| pcercuei | 0:03b5121a232e | 3199 | return(cur); |
| pcercuei | 0:03b5121a232e | 3200 | } else if (elem->type == XML_ATTRIBUTE_NODE) { |
| pcercuei | 0:03b5121a232e | 3201 | return xmlAddPropSibling(cur, cur, elem); |
| pcercuei | 0:03b5121a232e | 3202 | } |
| pcercuei | 0:03b5121a232e | 3203 | |
| pcercuei | 0:03b5121a232e | 3204 | if (elem->doc != cur->doc) { |
| pcercuei | 0:03b5121a232e | 3205 | xmlSetTreeDoc(elem, cur->doc); |
| pcercuei | 0:03b5121a232e | 3206 | } |
| pcercuei | 0:03b5121a232e | 3207 | parent = cur->parent; |
| pcercuei | 0:03b5121a232e | 3208 | elem->prev = cur; |
| pcercuei | 0:03b5121a232e | 3209 | elem->next = NULL; |
| pcercuei | 0:03b5121a232e | 3210 | elem->parent = parent; |
| pcercuei | 0:03b5121a232e | 3211 | cur->next = elem; |
| pcercuei | 0:03b5121a232e | 3212 | if (parent != NULL) |
| pcercuei | 0:03b5121a232e | 3213 | parent->last = elem; |
| pcercuei | 0:03b5121a232e | 3214 | |
| pcercuei | 0:03b5121a232e | 3215 | return(elem); |
| pcercuei | 0:03b5121a232e | 3216 | } |
| pcercuei | 0:03b5121a232e | 3217 | |
| pcercuei | 0:03b5121a232e | 3218 | /** |
| pcercuei | 0:03b5121a232e | 3219 | * xmlAddChildList: |
| pcercuei | 0:03b5121a232e | 3220 | * @parent: the parent node |
| pcercuei | 0:03b5121a232e | 3221 | * @cur: the first node in the list |
| pcercuei | 0:03b5121a232e | 3222 | * |
| pcercuei | 0:03b5121a232e | 3223 | * Add a list of node at the end of the child list of the parent |
| pcercuei | 0:03b5121a232e | 3224 | * merging adjacent TEXT nodes (@cur may be freed) |
| pcercuei | 0:03b5121a232e | 3225 | * |
| pcercuei | 0:03b5121a232e | 3226 | * Returns the last child or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 3227 | */ |
| pcercuei | 0:03b5121a232e | 3228 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 3229 | xmlAddChildList(xmlNodePtr parent, xmlNodePtr cur) { |
| pcercuei | 0:03b5121a232e | 3230 | xmlNodePtr prev; |
| pcercuei | 0:03b5121a232e | 3231 | |
| pcercuei | 0:03b5121a232e | 3232 | if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) { |
| pcercuei | 0:03b5121a232e | 3233 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3234 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3235 | "xmlAddChildList : parent == NULL\n"); |
| pcercuei | 0:03b5121a232e | 3236 | #endif |
| pcercuei | 0:03b5121a232e | 3237 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3238 | } |
| pcercuei | 0:03b5121a232e | 3239 | |
| pcercuei | 0:03b5121a232e | 3240 | if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { |
| pcercuei | 0:03b5121a232e | 3241 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3242 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3243 | "xmlAddChildList : child == NULL\n"); |
| pcercuei | 0:03b5121a232e | 3244 | #endif |
| pcercuei | 0:03b5121a232e | 3245 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3246 | } |
| pcercuei | 0:03b5121a232e | 3247 | |
| pcercuei | 0:03b5121a232e | 3248 | if ((cur->doc != NULL) && (parent->doc != NULL) && |
| pcercuei | 0:03b5121a232e | 3249 | (cur->doc != parent->doc)) { |
| pcercuei | 0:03b5121a232e | 3250 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3251 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3252 | "Elements moved to a different document\n"); |
| pcercuei | 0:03b5121a232e | 3253 | #endif |
| pcercuei | 0:03b5121a232e | 3254 | } |
| pcercuei | 0:03b5121a232e | 3255 | |
| pcercuei | 0:03b5121a232e | 3256 | /* |
| pcercuei | 0:03b5121a232e | 3257 | * add the first element at the end of the children list. |
| pcercuei | 0:03b5121a232e | 3258 | */ |
| pcercuei | 0:03b5121a232e | 3259 | |
| pcercuei | 0:03b5121a232e | 3260 | if (parent->children == NULL) { |
| pcercuei | 0:03b5121a232e | 3261 | parent->children = cur; |
| pcercuei | 0:03b5121a232e | 3262 | } else { |
| pcercuei | 0:03b5121a232e | 3263 | /* |
| pcercuei | 0:03b5121a232e | 3264 | * If cur and parent->last both are TEXT nodes, then merge them. |
| pcercuei | 0:03b5121a232e | 3265 | */ |
| pcercuei | 0:03b5121a232e | 3266 | if ((cur->type == XML_TEXT_NODE) && |
| pcercuei | 0:03b5121a232e | 3267 | (parent->last->type == XML_TEXT_NODE) && |
| pcercuei | 0:03b5121a232e | 3268 | (cur->name == parent->last->name)) { |
| pcercuei | 0:03b5121a232e | 3269 | xmlNodeAddContent(parent->last, cur->content); |
| pcercuei | 0:03b5121a232e | 3270 | /* |
| pcercuei | 0:03b5121a232e | 3271 | * if it's the only child, nothing more to be done. |
| pcercuei | 0:03b5121a232e | 3272 | */ |
| pcercuei | 0:03b5121a232e | 3273 | if (cur->next == NULL) { |
| pcercuei | 0:03b5121a232e | 3274 | xmlFreeNode(cur); |
| pcercuei | 0:03b5121a232e | 3275 | return(parent->last); |
| pcercuei | 0:03b5121a232e | 3276 | } |
| pcercuei | 0:03b5121a232e | 3277 | prev = cur; |
| pcercuei | 0:03b5121a232e | 3278 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 3279 | xmlFreeNode(prev); |
| pcercuei | 0:03b5121a232e | 3280 | } |
| pcercuei | 0:03b5121a232e | 3281 | prev = parent->last; |
| pcercuei | 0:03b5121a232e | 3282 | prev->next = cur; |
| pcercuei | 0:03b5121a232e | 3283 | cur->prev = prev; |
| pcercuei | 0:03b5121a232e | 3284 | } |
| pcercuei | 0:03b5121a232e | 3285 | while (cur->next != NULL) { |
| pcercuei | 0:03b5121a232e | 3286 | cur->parent = parent; |
| pcercuei | 0:03b5121a232e | 3287 | if (cur->doc != parent->doc) { |
| pcercuei | 0:03b5121a232e | 3288 | xmlSetTreeDoc(cur, parent->doc); |
| pcercuei | 0:03b5121a232e | 3289 | } |
| pcercuei | 0:03b5121a232e | 3290 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 3291 | } |
| pcercuei | 0:03b5121a232e | 3292 | cur->parent = parent; |
| pcercuei | 0:03b5121a232e | 3293 | /* the parent may not be linked to a doc ! */ |
| pcercuei | 0:03b5121a232e | 3294 | if (cur->doc != parent->doc) { |
| pcercuei | 0:03b5121a232e | 3295 | xmlSetTreeDoc(cur, parent->doc); |
| pcercuei | 0:03b5121a232e | 3296 | } |
| pcercuei | 0:03b5121a232e | 3297 | parent->last = cur; |
| pcercuei | 0:03b5121a232e | 3298 | |
| pcercuei | 0:03b5121a232e | 3299 | return(cur); |
| pcercuei | 0:03b5121a232e | 3300 | } |
| pcercuei | 0:03b5121a232e | 3301 | |
| pcercuei | 0:03b5121a232e | 3302 | /** |
| pcercuei | 0:03b5121a232e | 3303 | * xmlAddChild: |
| pcercuei | 0:03b5121a232e | 3304 | * @parent: the parent node |
| pcercuei | 0:03b5121a232e | 3305 | * @cur: the child node |
| pcercuei | 0:03b5121a232e | 3306 | * |
| pcercuei | 0:03b5121a232e | 3307 | * Add a new node to @parent, at the end of the child (or property) list |
| pcercuei | 0:03b5121a232e | 3308 | * merging adjacent TEXT nodes (in which case @cur is freed) |
| pcercuei | 0:03b5121a232e | 3309 | * If the new node is ATTRIBUTE, it is added into properties instead of children. |
| pcercuei | 0:03b5121a232e | 3310 | * If there is an attribute with equal name, it is first destroyed. |
| pcercuei | 0:03b5121a232e | 3311 | * |
| pcercuei | 0:03b5121a232e | 3312 | * Returns the child or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 3313 | */ |
| pcercuei | 0:03b5121a232e | 3314 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 3315 | xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { |
| pcercuei | 0:03b5121a232e | 3316 | xmlNodePtr prev; |
| pcercuei | 0:03b5121a232e | 3317 | |
| pcercuei | 0:03b5121a232e | 3318 | if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) { |
| pcercuei | 0:03b5121a232e | 3319 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3320 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3321 | "xmlAddChild : parent == NULL\n"); |
| pcercuei | 0:03b5121a232e | 3322 | #endif |
| pcercuei | 0:03b5121a232e | 3323 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3324 | } |
| pcercuei | 0:03b5121a232e | 3325 | |
| pcercuei | 0:03b5121a232e | 3326 | if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { |
| pcercuei | 0:03b5121a232e | 3327 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3328 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3329 | "xmlAddChild : child == NULL\n"); |
| pcercuei | 0:03b5121a232e | 3330 | #endif |
| pcercuei | 0:03b5121a232e | 3331 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3332 | } |
| pcercuei | 0:03b5121a232e | 3333 | |
| pcercuei | 0:03b5121a232e | 3334 | if (parent == cur) { |
| pcercuei | 0:03b5121a232e | 3335 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3336 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3337 | "xmlAddChild : parent == cur\n"); |
| pcercuei | 0:03b5121a232e | 3338 | #endif |
| pcercuei | 0:03b5121a232e | 3339 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3340 | } |
| pcercuei | 0:03b5121a232e | 3341 | /* |
| pcercuei | 0:03b5121a232e | 3342 | * If cur is a TEXT node, merge its content with adjacent TEXT nodes |
| pcercuei | 0:03b5121a232e | 3343 | * cur is then freed. |
| pcercuei | 0:03b5121a232e | 3344 | */ |
| pcercuei | 0:03b5121a232e | 3345 | if (cur->type == XML_TEXT_NODE) { |
| pcercuei | 0:03b5121a232e | 3346 | if ((parent->type == XML_TEXT_NODE) && |
| pcercuei | 0:03b5121a232e | 3347 | (parent->content != NULL) && |
| pcercuei | 0:03b5121a232e | 3348 | (parent->name == cur->name)) { |
| pcercuei | 0:03b5121a232e | 3349 | xmlNodeAddContent(parent, cur->content); |
| pcercuei | 0:03b5121a232e | 3350 | xmlFreeNode(cur); |
| pcercuei | 0:03b5121a232e | 3351 | return(parent); |
| pcercuei | 0:03b5121a232e | 3352 | } |
| pcercuei | 0:03b5121a232e | 3353 | if ((parent->last != NULL) && (parent->last->type == XML_TEXT_NODE) && |
| pcercuei | 0:03b5121a232e | 3354 | (parent->last->name == cur->name) && |
| pcercuei | 0:03b5121a232e | 3355 | (parent->last != cur)) { |
| pcercuei | 0:03b5121a232e | 3356 | xmlNodeAddContent(parent->last, cur->content); |
| pcercuei | 0:03b5121a232e | 3357 | xmlFreeNode(cur); |
| pcercuei | 0:03b5121a232e | 3358 | return(parent->last); |
| pcercuei | 0:03b5121a232e | 3359 | } |
| pcercuei | 0:03b5121a232e | 3360 | } |
| pcercuei | 0:03b5121a232e | 3361 | |
| pcercuei | 0:03b5121a232e | 3362 | /* |
| pcercuei | 0:03b5121a232e | 3363 | * add the new element at the end of the children list. |
| pcercuei | 0:03b5121a232e | 3364 | */ |
| pcercuei | 0:03b5121a232e | 3365 | prev = cur->parent; |
| pcercuei | 0:03b5121a232e | 3366 | cur->parent = parent; |
| pcercuei | 0:03b5121a232e | 3367 | if (cur->doc != parent->doc) { |
| pcercuei | 0:03b5121a232e | 3368 | xmlSetTreeDoc(cur, parent->doc); |
| pcercuei | 0:03b5121a232e | 3369 | } |
| pcercuei | 0:03b5121a232e | 3370 | /* this check prevents a loop on tree-traversions if a developer |
| pcercuei | 0:03b5121a232e | 3371 | * tries to add a node to its parent multiple times |
| pcercuei | 0:03b5121a232e | 3372 | */ |
| pcercuei | 0:03b5121a232e | 3373 | if (prev == parent) |
| pcercuei | 0:03b5121a232e | 3374 | return(cur); |
| pcercuei | 0:03b5121a232e | 3375 | |
| pcercuei | 0:03b5121a232e | 3376 | /* |
| pcercuei | 0:03b5121a232e | 3377 | * Coalescing |
| pcercuei | 0:03b5121a232e | 3378 | */ |
| pcercuei | 0:03b5121a232e | 3379 | if ((parent->type == XML_TEXT_NODE) && |
| pcercuei | 0:03b5121a232e | 3380 | (parent->content != NULL) && |
| pcercuei | 0:03b5121a232e | 3381 | (parent != cur)) { |
| pcercuei | 0:03b5121a232e | 3382 | xmlNodeAddContent(parent, cur->content); |
| pcercuei | 0:03b5121a232e | 3383 | xmlFreeNode(cur); |
| pcercuei | 0:03b5121a232e | 3384 | return(parent); |
| pcercuei | 0:03b5121a232e | 3385 | } |
| pcercuei | 0:03b5121a232e | 3386 | if (cur->type == XML_ATTRIBUTE_NODE) { |
| pcercuei | 0:03b5121a232e | 3387 | if (parent->type != XML_ELEMENT_NODE) |
| pcercuei | 0:03b5121a232e | 3388 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3389 | if (parent->properties != NULL) { |
| pcercuei | 0:03b5121a232e | 3390 | /* check if an attribute with the same name exists */ |
| pcercuei | 0:03b5121a232e | 3391 | xmlAttrPtr lastattr; |
| pcercuei | 0:03b5121a232e | 3392 | |
| pcercuei | 0:03b5121a232e | 3393 | if (cur->ns == NULL) |
| pcercuei | 0:03b5121a232e | 3394 | lastattr = xmlHasNsProp(parent, cur->name, NULL); |
| pcercuei | 0:03b5121a232e | 3395 | else |
| pcercuei | 0:03b5121a232e | 3396 | lastattr = xmlHasNsProp(parent, cur->name, cur->ns->href); |
| pcercuei | 0:03b5121a232e | 3397 | if ((lastattr != NULL) && (lastattr != (xmlAttrPtr) cur) && (lastattr->type != XML_ATTRIBUTE_DECL)) { |
| pcercuei | 0:03b5121a232e | 3398 | /* different instance, destroy it (attributes must be unique) */ |
| pcercuei | 0:03b5121a232e | 3399 | xmlUnlinkNode((xmlNodePtr) lastattr); |
| pcercuei | 0:03b5121a232e | 3400 | xmlFreeProp(lastattr); |
| pcercuei | 0:03b5121a232e | 3401 | } |
| pcercuei | 0:03b5121a232e | 3402 | if (lastattr == (xmlAttrPtr) cur) |
| pcercuei | 0:03b5121a232e | 3403 | return(cur); |
| pcercuei | 0:03b5121a232e | 3404 | |
| pcercuei | 0:03b5121a232e | 3405 | } |
| pcercuei | 0:03b5121a232e | 3406 | if (parent->properties == NULL) { |
| pcercuei | 0:03b5121a232e | 3407 | parent->properties = (xmlAttrPtr) cur; |
| pcercuei | 0:03b5121a232e | 3408 | } else { |
| pcercuei | 0:03b5121a232e | 3409 | /* find the end */ |
| pcercuei | 0:03b5121a232e | 3410 | xmlAttrPtr lastattr = parent->properties; |
| pcercuei | 0:03b5121a232e | 3411 | while (lastattr->next != NULL) { |
| pcercuei | 0:03b5121a232e | 3412 | lastattr = lastattr->next; |
| pcercuei | 0:03b5121a232e | 3413 | } |
| pcercuei | 0:03b5121a232e | 3414 | lastattr->next = (xmlAttrPtr) cur; |
| pcercuei | 0:03b5121a232e | 3415 | ((xmlAttrPtr) cur)->prev = lastattr; |
| pcercuei | 0:03b5121a232e | 3416 | } |
| pcercuei | 0:03b5121a232e | 3417 | } else { |
| pcercuei | 0:03b5121a232e | 3418 | if (parent->children == NULL) { |
| pcercuei | 0:03b5121a232e | 3419 | parent->children = cur; |
| pcercuei | 0:03b5121a232e | 3420 | parent->last = cur; |
| pcercuei | 0:03b5121a232e | 3421 | } else { |
| pcercuei | 0:03b5121a232e | 3422 | prev = parent->last; |
| pcercuei | 0:03b5121a232e | 3423 | prev->next = cur; |
| pcercuei | 0:03b5121a232e | 3424 | cur->prev = prev; |
| pcercuei | 0:03b5121a232e | 3425 | parent->last = cur; |
| pcercuei | 0:03b5121a232e | 3426 | } |
| pcercuei | 0:03b5121a232e | 3427 | } |
| pcercuei | 0:03b5121a232e | 3428 | return(cur); |
| pcercuei | 0:03b5121a232e | 3429 | } |
| pcercuei | 0:03b5121a232e | 3430 | |
| pcercuei | 0:03b5121a232e | 3431 | /** |
| pcercuei | 0:03b5121a232e | 3432 | * xmlGetLastChild: |
| pcercuei | 0:03b5121a232e | 3433 | * @parent: the parent node |
| pcercuei | 0:03b5121a232e | 3434 | * |
| pcercuei | 0:03b5121a232e | 3435 | * Search the last child of a node. |
| pcercuei | 0:03b5121a232e | 3436 | * Returns the last child or NULL if none. |
| pcercuei | 0:03b5121a232e | 3437 | */ |
| pcercuei | 0:03b5121a232e | 3438 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 3439 | xmlGetLastChild(const xmlNode *parent) { |
| pcercuei | 0:03b5121a232e | 3440 | if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) { |
| pcercuei | 0:03b5121a232e | 3441 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3442 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3443 | "xmlGetLastChild : parent == NULL\n"); |
| pcercuei | 0:03b5121a232e | 3444 | #endif |
| pcercuei | 0:03b5121a232e | 3445 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3446 | } |
| pcercuei | 0:03b5121a232e | 3447 | return(parent->last); |
| pcercuei | 0:03b5121a232e | 3448 | } |
| pcercuei | 0:03b5121a232e | 3449 | |
| pcercuei | 0:03b5121a232e | 3450 | #ifdef LIBXML_TREE_ENABLED |
| pcercuei | 0:03b5121a232e | 3451 | /* |
| pcercuei | 0:03b5121a232e | 3452 | * 5 interfaces from DOM ElementTraversal |
| pcercuei | 0:03b5121a232e | 3453 | */ |
| pcercuei | 0:03b5121a232e | 3454 | |
| pcercuei | 0:03b5121a232e | 3455 | /** |
| pcercuei | 0:03b5121a232e | 3456 | * xmlChildElementCount: |
| pcercuei | 0:03b5121a232e | 3457 | * @parent: the parent node |
| pcercuei | 0:03b5121a232e | 3458 | * |
| pcercuei | 0:03b5121a232e | 3459 | * Finds the current number of child nodes of that element which are |
| pcercuei | 0:03b5121a232e | 3460 | * element nodes. |
| pcercuei | 0:03b5121a232e | 3461 | * Note the handling of entities references is different than in |
| pcercuei | 0:03b5121a232e | 3462 | * the W3C DOM element traversal spec since we don't have back reference |
| pcercuei | 0:03b5121a232e | 3463 | * from entities content to entities references. |
| pcercuei | 0:03b5121a232e | 3464 | * |
| pcercuei | 0:03b5121a232e | 3465 | * Returns the count of element child or 0 if not available |
| pcercuei | 0:03b5121a232e | 3466 | */ |
| pcercuei | 0:03b5121a232e | 3467 | unsigned long |
| pcercuei | 0:03b5121a232e | 3468 | xmlChildElementCount(xmlNodePtr parent) { |
| pcercuei | 0:03b5121a232e | 3469 | unsigned long ret = 0; |
| pcercuei | 0:03b5121a232e | 3470 | xmlNodePtr cur = NULL; |
| pcercuei | 0:03b5121a232e | 3471 | |
| pcercuei | 0:03b5121a232e | 3472 | if (parent == NULL) |
| pcercuei | 0:03b5121a232e | 3473 | return(0); |
| pcercuei | 0:03b5121a232e | 3474 | switch (parent->type) { |
| pcercuei | 0:03b5121a232e | 3475 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 3476 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 3477 | case XML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 3478 | case XML_DOCUMENT_FRAG_NODE: |
| pcercuei | 0:03b5121a232e | 3479 | case XML_HTML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 3480 | cur = parent->children; |
| pcercuei | 0:03b5121a232e | 3481 | break; |
| pcercuei | 0:03b5121a232e | 3482 | default: |
| pcercuei | 0:03b5121a232e | 3483 | return(0); |
| pcercuei | 0:03b5121a232e | 3484 | } |
| pcercuei | 0:03b5121a232e | 3485 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 3486 | if (cur->type == XML_ELEMENT_NODE) |
| pcercuei | 0:03b5121a232e | 3487 | ret++; |
| pcercuei | 0:03b5121a232e | 3488 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 3489 | } |
| pcercuei | 0:03b5121a232e | 3490 | return(ret); |
| pcercuei | 0:03b5121a232e | 3491 | } |
| pcercuei | 0:03b5121a232e | 3492 | |
| pcercuei | 0:03b5121a232e | 3493 | /** |
| pcercuei | 0:03b5121a232e | 3494 | * xmlFirstElementChild: |
| pcercuei | 0:03b5121a232e | 3495 | * @parent: the parent node |
| pcercuei | 0:03b5121a232e | 3496 | * |
| pcercuei | 0:03b5121a232e | 3497 | * Finds the first child node of that element which is a Element node |
| pcercuei | 0:03b5121a232e | 3498 | * Note the handling of entities references is different than in |
| pcercuei | 0:03b5121a232e | 3499 | * the W3C DOM element traversal spec since we don't have back reference |
| pcercuei | 0:03b5121a232e | 3500 | * from entities content to entities references. |
| pcercuei | 0:03b5121a232e | 3501 | * |
| pcercuei | 0:03b5121a232e | 3502 | * Returns the first element child or NULL if not available |
| pcercuei | 0:03b5121a232e | 3503 | */ |
| pcercuei | 0:03b5121a232e | 3504 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 3505 | xmlFirstElementChild(xmlNodePtr parent) { |
| pcercuei | 0:03b5121a232e | 3506 | xmlNodePtr cur = NULL; |
| pcercuei | 0:03b5121a232e | 3507 | |
| pcercuei | 0:03b5121a232e | 3508 | if (parent == NULL) |
| pcercuei | 0:03b5121a232e | 3509 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3510 | switch (parent->type) { |
| pcercuei | 0:03b5121a232e | 3511 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 3512 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 3513 | case XML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 3514 | case XML_DOCUMENT_FRAG_NODE: |
| pcercuei | 0:03b5121a232e | 3515 | case XML_HTML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 3516 | cur = parent->children; |
| pcercuei | 0:03b5121a232e | 3517 | break; |
| pcercuei | 0:03b5121a232e | 3518 | default: |
| pcercuei | 0:03b5121a232e | 3519 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3520 | } |
| pcercuei | 0:03b5121a232e | 3521 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 3522 | if (cur->type == XML_ELEMENT_NODE) |
| pcercuei | 0:03b5121a232e | 3523 | return(cur); |
| pcercuei | 0:03b5121a232e | 3524 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 3525 | } |
| pcercuei | 0:03b5121a232e | 3526 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3527 | } |
| pcercuei | 0:03b5121a232e | 3528 | |
| pcercuei | 0:03b5121a232e | 3529 | /** |
| pcercuei | 0:03b5121a232e | 3530 | * xmlLastElementChild: |
| pcercuei | 0:03b5121a232e | 3531 | * @parent: the parent node |
| pcercuei | 0:03b5121a232e | 3532 | * |
| pcercuei | 0:03b5121a232e | 3533 | * Finds the last child node of that element which is a Element node |
| pcercuei | 0:03b5121a232e | 3534 | * Note the handling of entities references is different than in |
| pcercuei | 0:03b5121a232e | 3535 | * the W3C DOM element traversal spec since we don't have back reference |
| pcercuei | 0:03b5121a232e | 3536 | * from entities content to entities references. |
| pcercuei | 0:03b5121a232e | 3537 | * |
| pcercuei | 0:03b5121a232e | 3538 | * Returns the last element child or NULL if not available |
| pcercuei | 0:03b5121a232e | 3539 | */ |
| pcercuei | 0:03b5121a232e | 3540 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 3541 | xmlLastElementChild(xmlNodePtr parent) { |
| pcercuei | 0:03b5121a232e | 3542 | xmlNodePtr cur = NULL; |
| pcercuei | 0:03b5121a232e | 3543 | |
| pcercuei | 0:03b5121a232e | 3544 | if (parent == NULL) |
| pcercuei | 0:03b5121a232e | 3545 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3546 | switch (parent->type) { |
| pcercuei | 0:03b5121a232e | 3547 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 3548 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 3549 | case XML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 3550 | case XML_DOCUMENT_FRAG_NODE: |
| pcercuei | 0:03b5121a232e | 3551 | case XML_HTML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 3552 | cur = parent->last; |
| pcercuei | 0:03b5121a232e | 3553 | break; |
| pcercuei | 0:03b5121a232e | 3554 | default: |
| pcercuei | 0:03b5121a232e | 3555 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3556 | } |
| pcercuei | 0:03b5121a232e | 3557 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 3558 | if (cur->type == XML_ELEMENT_NODE) |
| pcercuei | 0:03b5121a232e | 3559 | return(cur); |
| pcercuei | 0:03b5121a232e | 3560 | cur = cur->prev; |
| pcercuei | 0:03b5121a232e | 3561 | } |
| pcercuei | 0:03b5121a232e | 3562 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3563 | } |
| pcercuei | 0:03b5121a232e | 3564 | |
| pcercuei | 0:03b5121a232e | 3565 | /** |
| pcercuei | 0:03b5121a232e | 3566 | * xmlPreviousElementSibling: |
| pcercuei | 0:03b5121a232e | 3567 | * @node: the current node |
| pcercuei | 0:03b5121a232e | 3568 | * |
| pcercuei | 0:03b5121a232e | 3569 | * Finds the first closest previous sibling of the node which is an |
| pcercuei | 0:03b5121a232e | 3570 | * element node. |
| pcercuei | 0:03b5121a232e | 3571 | * Note the handling of entities references is different than in |
| pcercuei | 0:03b5121a232e | 3572 | * the W3C DOM element traversal spec since we don't have back reference |
| pcercuei | 0:03b5121a232e | 3573 | * from entities content to entities references. |
| pcercuei | 0:03b5121a232e | 3574 | * |
| pcercuei | 0:03b5121a232e | 3575 | * Returns the previous element sibling or NULL if not available |
| pcercuei | 0:03b5121a232e | 3576 | */ |
| pcercuei | 0:03b5121a232e | 3577 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 3578 | xmlPreviousElementSibling(xmlNodePtr node) { |
| pcercuei | 0:03b5121a232e | 3579 | if (node == NULL) |
| pcercuei | 0:03b5121a232e | 3580 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3581 | switch (node->type) { |
| pcercuei | 0:03b5121a232e | 3582 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 3583 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 3584 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 3585 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 3586 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 3587 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 3588 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 3589 | case XML_XINCLUDE_START: |
| pcercuei | 0:03b5121a232e | 3590 | case XML_XINCLUDE_END: |
| pcercuei | 0:03b5121a232e | 3591 | node = node->prev; |
| pcercuei | 0:03b5121a232e | 3592 | break; |
| pcercuei | 0:03b5121a232e | 3593 | default: |
| pcercuei | 0:03b5121a232e | 3594 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3595 | } |
| pcercuei | 0:03b5121a232e | 3596 | while (node != NULL) { |
| pcercuei | 0:03b5121a232e | 3597 | if (node->type == XML_ELEMENT_NODE) |
| pcercuei | 0:03b5121a232e | 3598 | return(node); |
| pcercuei | 0:03b5121a232e | 3599 | node = node->prev; |
| pcercuei | 0:03b5121a232e | 3600 | } |
| pcercuei | 0:03b5121a232e | 3601 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3602 | } |
| pcercuei | 0:03b5121a232e | 3603 | |
| pcercuei | 0:03b5121a232e | 3604 | /** |
| pcercuei | 0:03b5121a232e | 3605 | * xmlNextElementSibling: |
| pcercuei | 0:03b5121a232e | 3606 | * @node: the current node |
| pcercuei | 0:03b5121a232e | 3607 | * |
| pcercuei | 0:03b5121a232e | 3608 | * Finds the first closest next sibling of the node which is an |
| pcercuei | 0:03b5121a232e | 3609 | * element node. |
| pcercuei | 0:03b5121a232e | 3610 | * Note the handling of entities references is different than in |
| pcercuei | 0:03b5121a232e | 3611 | * the W3C DOM element traversal spec since we don't have back reference |
| pcercuei | 0:03b5121a232e | 3612 | * from entities content to entities references. |
| pcercuei | 0:03b5121a232e | 3613 | * |
| pcercuei | 0:03b5121a232e | 3614 | * Returns the next element sibling or NULL if not available |
| pcercuei | 0:03b5121a232e | 3615 | */ |
| pcercuei | 0:03b5121a232e | 3616 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 3617 | xmlNextElementSibling(xmlNodePtr node) { |
| pcercuei | 0:03b5121a232e | 3618 | if (node == NULL) |
| pcercuei | 0:03b5121a232e | 3619 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3620 | switch (node->type) { |
| pcercuei | 0:03b5121a232e | 3621 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 3622 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 3623 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 3624 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 3625 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 3626 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 3627 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 3628 | case XML_DTD_NODE: |
| pcercuei | 0:03b5121a232e | 3629 | case XML_XINCLUDE_START: |
| pcercuei | 0:03b5121a232e | 3630 | case XML_XINCLUDE_END: |
| pcercuei | 0:03b5121a232e | 3631 | node = node->next; |
| pcercuei | 0:03b5121a232e | 3632 | break; |
| pcercuei | 0:03b5121a232e | 3633 | default: |
| pcercuei | 0:03b5121a232e | 3634 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3635 | } |
| pcercuei | 0:03b5121a232e | 3636 | while (node != NULL) { |
| pcercuei | 0:03b5121a232e | 3637 | if (node->type == XML_ELEMENT_NODE) |
| pcercuei | 0:03b5121a232e | 3638 | return(node); |
| pcercuei | 0:03b5121a232e | 3639 | node = node->next; |
| pcercuei | 0:03b5121a232e | 3640 | } |
| pcercuei | 0:03b5121a232e | 3641 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3642 | } |
| pcercuei | 0:03b5121a232e | 3643 | |
| pcercuei | 0:03b5121a232e | 3644 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 3645 | |
| pcercuei | 0:03b5121a232e | 3646 | /** |
| pcercuei | 0:03b5121a232e | 3647 | * xmlFreeNodeList: |
| pcercuei | 0:03b5121a232e | 3648 | * @cur: the first node in the list |
| pcercuei | 0:03b5121a232e | 3649 | * |
| pcercuei | 0:03b5121a232e | 3650 | * Free a node and all its siblings, this is a recursive behaviour, all |
| pcercuei | 0:03b5121a232e | 3651 | * the children are freed too. |
| pcercuei | 0:03b5121a232e | 3652 | */ |
| pcercuei | 0:03b5121a232e | 3653 | void |
| pcercuei | 0:03b5121a232e | 3654 | xmlFreeNodeList(xmlNodePtr cur) { |
| pcercuei | 0:03b5121a232e | 3655 | xmlNodePtr next; |
| pcercuei | 0:03b5121a232e | 3656 | xmlDictPtr dict = NULL; |
| pcercuei | 0:03b5121a232e | 3657 | |
| pcercuei | 0:03b5121a232e | 3658 | if (cur == NULL) return; |
| pcercuei | 0:03b5121a232e | 3659 | if (cur->type == XML_NAMESPACE_DECL) { |
| pcercuei | 0:03b5121a232e | 3660 | xmlFreeNsList((xmlNsPtr) cur); |
| pcercuei | 0:03b5121a232e | 3661 | return; |
| pcercuei | 0:03b5121a232e | 3662 | } |
| pcercuei | 0:03b5121a232e | 3663 | if ((cur->type == XML_DOCUMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 3664 | #ifdef LIBXML_DOCB_ENABLED |
| pcercuei | 0:03b5121a232e | 3665 | (cur->type == XML_DOCB_DOCUMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 3666 | #endif |
| pcercuei | 0:03b5121a232e | 3667 | (cur->type == XML_HTML_DOCUMENT_NODE)) { |
| pcercuei | 0:03b5121a232e | 3668 | xmlFreeDoc((xmlDocPtr) cur); |
| pcercuei | 0:03b5121a232e | 3669 | return; |
| pcercuei | 0:03b5121a232e | 3670 | } |
| pcercuei | 0:03b5121a232e | 3671 | if (cur->doc != NULL) dict = cur->doc->dict; |
| pcercuei | 0:03b5121a232e | 3672 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 3673 | next = cur->next; |
| pcercuei | 0:03b5121a232e | 3674 | if (cur->type != XML_DTD_NODE) { |
| pcercuei | 0:03b5121a232e | 3675 | |
| pcercuei | 0:03b5121a232e | 3676 | if ((__xmlRegisterCallbacks) && (xmlDeregisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 3677 | xmlDeregisterNodeDefaultValue(cur); |
| pcercuei | 0:03b5121a232e | 3678 | |
| pcercuei | 0:03b5121a232e | 3679 | if ((cur->children != NULL) && |
| pcercuei | 0:03b5121a232e | 3680 | (cur->type != XML_ENTITY_REF_NODE)) |
| pcercuei | 0:03b5121a232e | 3681 | xmlFreeNodeList(cur->children); |
| pcercuei | 0:03b5121a232e | 3682 | if (((cur->type == XML_ELEMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 3683 | (cur->type == XML_XINCLUDE_START) || |
| pcercuei | 0:03b5121a232e | 3684 | (cur->type == XML_XINCLUDE_END)) && |
| pcercuei | 0:03b5121a232e | 3685 | (cur->properties != NULL)) |
| pcercuei | 0:03b5121a232e | 3686 | xmlFreePropList(cur->properties); |
| pcercuei | 0:03b5121a232e | 3687 | if ((cur->type != XML_ELEMENT_NODE) && |
| pcercuei | 0:03b5121a232e | 3688 | (cur->type != XML_XINCLUDE_START) && |
| pcercuei | 0:03b5121a232e | 3689 | (cur->type != XML_XINCLUDE_END) && |
| pcercuei | 0:03b5121a232e | 3690 | (cur->type != XML_ENTITY_REF_NODE) && |
| pcercuei | 0:03b5121a232e | 3691 | (cur->content != (xmlChar *) &(cur->properties))) { |
| pcercuei | 0:03b5121a232e | 3692 | DICT_FREE(cur->content) |
| pcercuei | 0:03b5121a232e | 3693 | } |
| pcercuei | 0:03b5121a232e | 3694 | if (((cur->type == XML_ELEMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 3695 | (cur->type == XML_XINCLUDE_START) || |
| pcercuei | 0:03b5121a232e | 3696 | (cur->type == XML_XINCLUDE_END)) && |
| pcercuei | 0:03b5121a232e | 3697 | (cur->nsDef != NULL)) |
| pcercuei | 0:03b5121a232e | 3698 | xmlFreeNsList(cur->nsDef); |
| pcercuei | 0:03b5121a232e | 3699 | |
| pcercuei | 0:03b5121a232e | 3700 | /* |
| pcercuei | 0:03b5121a232e | 3701 | * When a node is a text node or a comment, it uses a global static |
| pcercuei | 0:03b5121a232e | 3702 | * variable for the name of the node. |
| pcercuei | 0:03b5121a232e | 3703 | * Otherwise the node name might come from the document's |
| pcercuei | 0:03b5121a232e | 3704 | * dictionnary |
| pcercuei | 0:03b5121a232e | 3705 | */ |
| pcercuei | 0:03b5121a232e | 3706 | if ((cur->name != NULL) && |
| pcercuei | 0:03b5121a232e | 3707 | (cur->type != XML_TEXT_NODE) && |
| pcercuei | 0:03b5121a232e | 3708 | (cur->type != XML_COMMENT_NODE)) |
| pcercuei | 0:03b5121a232e | 3709 | DICT_FREE(cur->name) |
| pcercuei | 0:03b5121a232e | 3710 | xmlFree(cur); |
| pcercuei | 0:03b5121a232e | 3711 | } |
| pcercuei | 0:03b5121a232e | 3712 | cur = next; |
| pcercuei | 0:03b5121a232e | 3713 | } |
| pcercuei | 0:03b5121a232e | 3714 | } |
| pcercuei | 0:03b5121a232e | 3715 | |
| pcercuei | 0:03b5121a232e | 3716 | /** |
| pcercuei | 0:03b5121a232e | 3717 | * xmlFreeNode: |
| pcercuei | 0:03b5121a232e | 3718 | * @cur: the node |
| pcercuei | 0:03b5121a232e | 3719 | * |
| pcercuei | 0:03b5121a232e | 3720 | * Free a node, this is a recursive behaviour, all the children are freed too. |
| pcercuei | 0:03b5121a232e | 3721 | * This doesn't unlink the child from the list, use xmlUnlinkNode() first. |
| pcercuei | 0:03b5121a232e | 3722 | */ |
| pcercuei | 0:03b5121a232e | 3723 | void |
| pcercuei | 0:03b5121a232e | 3724 | xmlFreeNode(xmlNodePtr cur) { |
| pcercuei | 0:03b5121a232e | 3725 | xmlDictPtr dict = NULL; |
| pcercuei | 0:03b5121a232e | 3726 | |
| pcercuei | 0:03b5121a232e | 3727 | if (cur == NULL) return; |
| pcercuei | 0:03b5121a232e | 3728 | |
| pcercuei | 0:03b5121a232e | 3729 | /* use xmlFreeDtd for DTD nodes */ |
| pcercuei | 0:03b5121a232e | 3730 | if (cur->type == XML_DTD_NODE) { |
| pcercuei | 0:03b5121a232e | 3731 | xmlFreeDtd((xmlDtdPtr) cur); |
| pcercuei | 0:03b5121a232e | 3732 | return; |
| pcercuei | 0:03b5121a232e | 3733 | } |
| pcercuei | 0:03b5121a232e | 3734 | if (cur->type == XML_NAMESPACE_DECL) { |
| pcercuei | 0:03b5121a232e | 3735 | xmlFreeNs((xmlNsPtr) cur); |
| pcercuei | 0:03b5121a232e | 3736 | return; |
| pcercuei | 0:03b5121a232e | 3737 | } |
| pcercuei | 0:03b5121a232e | 3738 | if (cur->type == XML_ATTRIBUTE_NODE) { |
| pcercuei | 0:03b5121a232e | 3739 | xmlFreeProp((xmlAttrPtr) cur); |
| pcercuei | 0:03b5121a232e | 3740 | return; |
| pcercuei | 0:03b5121a232e | 3741 | } |
| pcercuei | 0:03b5121a232e | 3742 | |
| pcercuei | 0:03b5121a232e | 3743 | if ((__xmlRegisterCallbacks) && (xmlDeregisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 3744 | xmlDeregisterNodeDefaultValue(cur); |
| pcercuei | 0:03b5121a232e | 3745 | |
| pcercuei | 0:03b5121a232e | 3746 | if (cur->doc != NULL) dict = cur->doc->dict; |
| pcercuei | 0:03b5121a232e | 3747 | |
| pcercuei | 0:03b5121a232e | 3748 | if (cur->type == XML_ENTITY_DECL) { |
| pcercuei | 0:03b5121a232e | 3749 | xmlEntityPtr ent = (xmlEntityPtr) cur; |
| pcercuei | 0:03b5121a232e | 3750 | DICT_FREE(ent->SystemID); |
| pcercuei | 0:03b5121a232e | 3751 | DICT_FREE(ent->ExternalID); |
| pcercuei | 0:03b5121a232e | 3752 | } |
| pcercuei | 0:03b5121a232e | 3753 | if ((cur->children != NULL) && |
| pcercuei | 0:03b5121a232e | 3754 | (cur->type != XML_ENTITY_REF_NODE)) |
| pcercuei | 0:03b5121a232e | 3755 | xmlFreeNodeList(cur->children); |
| pcercuei | 0:03b5121a232e | 3756 | if (((cur->type == XML_ELEMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 3757 | (cur->type == XML_XINCLUDE_START) || |
| pcercuei | 0:03b5121a232e | 3758 | (cur->type == XML_XINCLUDE_END)) && |
| pcercuei | 0:03b5121a232e | 3759 | (cur->properties != NULL)) |
| pcercuei | 0:03b5121a232e | 3760 | xmlFreePropList(cur->properties); |
| pcercuei | 0:03b5121a232e | 3761 | if ((cur->type != XML_ELEMENT_NODE) && |
| pcercuei | 0:03b5121a232e | 3762 | (cur->content != NULL) && |
| pcercuei | 0:03b5121a232e | 3763 | (cur->type != XML_ENTITY_REF_NODE) && |
| pcercuei | 0:03b5121a232e | 3764 | (cur->type != XML_XINCLUDE_END) && |
| pcercuei | 0:03b5121a232e | 3765 | (cur->type != XML_XINCLUDE_START) && |
| pcercuei | 0:03b5121a232e | 3766 | (cur->content != (xmlChar *) &(cur->properties))) { |
| pcercuei | 0:03b5121a232e | 3767 | DICT_FREE(cur->content) |
| pcercuei | 0:03b5121a232e | 3768 | } |
| pcercuei | 0:03b5121a232e | 3769 | |
| pcercuei | 0:03b5121a232e | 3770 | /* |
| pcercuei | 0:03b5121a232e | 3771 | * When a node is a text node or a comment, it uses a global static |
| pcercuei | 0:03b5121a232e | 3772 | * variable for the name of the node. |
| pcercuei | 0:03b5121a232e | 3773 | * Otherwise the node name might come from the document's dictionnary |
| pcercuei | 0:03b5121a232e | 3774 | */ |
| pcercuei | 0:03b5121a232e | 3775 | if ((cur->name != NULL) && |
| pcercuei | 0:03b5121a232e | 3776 | (cur->type != XML_TEXT_NODE) && |
| pcercuei | 0:03b5121a232e | 3777 | (cur->type != XML_COMMENT_NODE)) |
| pcercuei | 0:03b5121a232e | 3778 | DICT_FREE(cur->name) |
| pcercuei | 0:03b5121a232e | 3779 | |
| pcercuei | 0:03b5121a232e | 3780 | if (((cur->type == XML_ELEMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 3781 | (cur->type == XML_XINCLUDE_START) || |
| pcercuei | 0:03b5121a232e | 3782 | (cur->type == XML_XINCLUDE_END)) && |
| pcercuei | 0:03b5121a232e | 3783 | (cur->nsDef != NULL)) |
| pcercuei | 0:03b5121a232e | 3784 | xmlFreeNsList(cur->nsDef); |
| pcercuei | 0:03b5121a232e | 3785 | xmlFree(cur); |
| pcercuei | 0:03b5121a232e | 3786 | } |
| pcercuei | 0:03b5121a232e | 3787 | |
| pcercuei | 0:03b5121a232e | 3788 | /** |
| pcercuei | 0:03b5121a232e | 3789 | * xmlUnlinkNode: |
| pcercuei | 0:03b5121a232e | 3790 | * @cur: the node |
| pcercuei | 0:03b5121a232e | 3791 | * |
| pcercuei | 0:03b5121a232e | 3792 | * Unlink a node from it's current context, the node is not freed |
| pcercuei | 0:03b5121a232e | 3793 | * If one need to free the node, use xmlFreeNode() routine after the |
| pcercuei | 0:03b5121a232e | 3794 | * unlink to discard it. |
| pcercuei | 0:03b5121a232e | 3795 | * Note that namespace nodes can't be unlinked as they do not have |
| pcercuei | 0:03b5121a232e | 3796 | * pointer to their parent. |
| pcercuei | 0:03b5121a232e | 3797 | */ |
| pcercuei | 0:03b5121a232e | 3798 | void |
| pcercuei | 0:03b5121a232e | 3799 | xmlUnlinkNode(xmlNodePtr cur) { |
| pcercuei | 0:03b5121a232e | 3800 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 3801 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3802 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3803 | "xmlUnlinkNode : node == NULL\n"); |
| pcercuei | 0:03b5121a232e | 3804 | #endif |
| pcercuei | 0:03b5121a232e | 3805 | return; |
| pcercuei | 0:03b5121a232e | 3806 | } |
| pcercuei | 0:03b5121a232e | 3807 | if (cur->type == XML_NAMESPACE_DECL) |
| pcercuei | 0:03b5121a232e | 3808 | return; |
| pcercuei | 0:03b5121a232e | 3809 | if (cur->type == XML_DTD_NODE) { |
| pcercuei | 0:03b5121a232e | 3810 | xmlDocPtr doc; |
| pcercuei | 0:03b5121a232e | 3811 | doc = cur->doc; |
| pcercuei | 0:03b5121a232e | 3812 | if (doc != NULL) { |
| pcercuei | 0:03b5121a232e | 3813 | if (doc->intSubset == (xmlDtdPtr) cur) |
| pcercuei | 0:03b5121a232e | 3814 | doc->intSubset = NULL; |
| pcercuei | 0:03b5121a232e | 3815 | if (doc->extSubset == (xmlDtdPtr) cur) |
| pcercuei | 0:03b5121a232e | 3816 | doc->extSubset = NULL; |
| pcercuei | 0:03b5121a232e | 3817 | } |
| pcercuei | 0:03b5121a232e | 3818 | } |
| pcercuei | 0:03b5121a232e | 3819 | if (cur->type == XML_ENTITY_DECL) { |
| pcercuei | 0:03b5121a232e | 3820 | xmlDocPtr doc; |
| pcercuei | 0:03b5121a232e | 3821 | doc = cur->doc; |
| pcercuei | 0:03b5121a232e | 3822 | if (doc != NULL) { |
| pcercuei | 0:03b5121a232e | 3823 | if (doc->intSubset != NULL) { |
| pcercuei | 0:03b5121a232e | 3824 | if (xmlHashLookup(doc->intSubset->entities, cur->name) == cur) |
| pcercuei | 0:03b5121a232e | 3825 | xmlHashRemoveEntry(doc->intSubset->entities, cur->name, |
| pcercuei | 0:03b5121a232e | 3826 | NULL); |
| pcercuei | 0:03b5121a232e | 3827 | if (xmlHashLookup(doc->intSubset->pentities, cur->name) == cur) |
| pcercuei | 0:03b5121a232e | 3828 | xmlHashRemoveEntry(doc->intSubset->pentities, cur->name, |
| pcercuei | 0:03b5121a232e | 3829 | NULL); |
| pcercuei | 0:03b5121a232e | 3830 | } |
| pcercuei | 0:03b5121a232e | 3831 | if (doc->extSubset != NULL) { |
| pcercuei | 0:03b5121a232e | 3832 | if (xmlHashLookup(doc->extSubset->entities, cur->name) == cur) |
| pcercuei | 0:03b5121a232e | 3833 | xmlHashRemoveEntry(doc->extSubset->entities, cur->name, |
| pcercuei | 0:03b5121a232e | 3834 | NULL); |
| pcercuei | 0:03b5121a232e | 3835 | if (xmlHashLookup(doc->extSubset->pentities, cur->name) == cur) |
| pcercuei | 0:03b5121a232e | 3836 | xmlHashRemoveEntry(doc->extSubset->pentities, cur->name, |
| pcercuei | 0:03b5121a232e | 3837 | NULL); |
| pcercuei | 0:03b5121a232e | 3838 | } |
| pcercuei | 0:03b5121a232e | 3839 | } |
| pcercuei | 0:03b5121a232e | 3840 | } |
| pcercuei | 0:03b5121a232e | 3841 | if (cur->parent != NULL) { |
| pcercuei | 0:03b5121a232e | 3842 | xmlNodePtr parent; |
| pcercuei | 0:03b5121a232e | 3843 | parent = cur->parent; |
| pcercuei | 0:03b5121a232e | 3844 | if (cur->type == XML_ATTRIBUTE_NODE) { |
| pcercuei | 0:03b5121a232e | 3845 | if (parent->properties == (xmlAttrPtr) cur) |
| pcercuei | 0:03b5121a232e | 3846 | parent->properties = ((xmlAttrPtr) cur)->next; |
| pcercuei | 0:03b5121a232e | 3847 | } else { |
| pcercuei | 0:03b5121a232e | 3848 | if (parent->children == cur) |
| pcercuei | 0:03b5121a232e | 3849 | parent->children = cur->next; |
| pcercuei | 0:03b5121a232e | 3850 | if (parent->last == cur) |
| pcercuei | 0:03b5121a232e | 3851 | parent->last = cur->prev; |
| pcercuei | 0:03b5121a232e | 3852 | } |
| pcercuei | 0:03b5121a232e | 3853 | cur->parent = NULL; |
| pcercuei | 0:03b5121a232e | 3854 | } |
| pcercuei | 0:03b5121a232e | 3855 | if (cur->next != NULL) |
| pcercuei | 0:03b5121a232e | 3856 | cur->next->prev = cur->prev; |
| pcercuei | 0:03b5121a232e | 3857 | if (cur->prev != NULL) |
| pcercuei | 0:03b5121a232e | 3858 | cur->prev->next = cur->next; |
| pcercuei | 0:03b5121a232e | 3859 | cur->next = cur->prev = NULL; |
| pcercuei | 0:03b5121a232e | 3860 | } |
| pcercuei | 0:03b5121a232e | 3861 | |
| pcercuei | 0:03b5121a232e | 3862 | #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_WRITER_ENABLED) |
| pcercuei | 0:03b5121a232e | 3863 | /** |
| pcercuei | 0:03b5121a232e | 3864 | * xmlReplaceNode: |
| pcercuei | 0:03b5121a232e | 3865 | * @old: the old node |
| pcercuei | 0:03b5121a232e | 3866 | * @cur: the node |
| pcercuei | 0:03b5121a232e | 3867 | * |
| pcercuei | 0:03b5121a232e | 3868 | * Unlink the old node from its current context, prune the new one |
| pcercuei | 0:03b5121a232e | 3869 | * at the same place. If @cur was already inserted in a document it is |
| pcercuei | 0:03b5121a232e | 3870 | * first unlinked from its existing context. |
| pcercuei | 0:03b5121a232e | 3871 | * |
| pcercuei | 0:03b5121a232e | 3872 | * Returns the @old node |
| pcercuei | 0:03b5121a232e | 3873 | */ |
| pcercuei | 0:03b5121a232e | 3874 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 3875 | xmlReplaceNode(xmlNodePtr old, xmlNodePtr cur) { |
| pcercuei | 0:03b5121a232e | 3876 | if (old == cur) return(NULL); |
| pcercuei | 0:03b5121a232e | 3877 | if ((old == NULL) || (old->type == XML_NAMESPACE_DECL) || |
| pcercuei | 0:03b5121a232e | 3878 | (old->parent == NULL)) { |
| pcercuei | 0:03b5121a232e | 3879 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3880 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3881 | "xmlReplaceNode : old == NULL or without parent\n"); |
| pcercuei | 0:03b5121a232e | 3882 | #endif |
| pcercuei | 0:03b5121a232e | 3883 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3884 | } |
| pcercuei | 0:03b5121a232e | 3885 | if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { |
| pcercuei | 0:03b5121a232e | 3886 | xmlUnlinkNode(old); |
| pcercuei | 0:03b5121a232e | 3887 | return(old); |
| pcercuei | 0:03b5121a232e | 3888 | } |
| pcercuei | 0:03b5121a232e | 3889 | if (cur == old) { |
| pcercuei | 0:03b5121a232e | 3890 | return(old); |
| pcercuei | 0:03b5121a232e | 3891 | } |
| pcercuei | 0:03b5121a232e | 3892 | if ((old->type==XML_ATTRIBUTE_NODE) && (cur->type!=XML_ATTRIBUTE_NODE)) { |
| pcercuei | 0:03b5121a232e | 3893 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3894 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3895 | "xmlReplaceNode : Trying to replace attribute node with other node type\n"); |
| pcercuei | 0:03b5121a232e | 3896 | #endif |
| pcercuei | 0:03b5121a232e | 3897 | return(old); |
| pcercuei | 0:03b5121a232e | 3898 | } |
| pcercuei | 0:03b5121a232e | 3899 | if ((cur->type==XML_ATTRIBUTE_NODE) && (old->type!=XML_ATTRIBUTE_NODE)) { |
| pcercuei | 0:03b5121a232e | 3900 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3901 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3902 | "xmlReplaceNode : Trying to replace a non-attribute node with attribute node\n"); |
| pcercuei | 0:03b5121a232e | 3903 | #endif |
| pcercuei | 0:03b5121a232e | 3904 | return(old); |
| pcercuei | 0:03b5121a232e | 3905 | } |
| pcercuei | 0:03b5121a232e | 3906 | xmlUnlinkNode(cur); |
| pcercuei | 0:03b5121a232e | 3907 | xmlSetTreeDoc(cur, old->doc); |
| pcercuei | 0:03b5121a232e | 3908 | cur->parent = old->parent; |
| pcercuei | 0:03b5121a232e | 3909 | cur->next = old->next; |
| pcercuei | 0:03b5121a232e | 3910 | if (cur->next != NULL) |
| pcercuei | 0:03b5121a232e | 3911 | cur->next->prev = cur; |
| pcercuei | 0:03b5121a232e | 3912 | cur->prev = old->prev; |
| pcercuei | 0:03b5121a232e | 3913 | if (cur->prev != NULL) |
| pcercuei | 0:03b5121a232e | 3914 | cur->prev->next = cur; |
| pcercuei | 0:03b5121a232e | 3915 | if (cur->parent != NULL) { |
| pcercuei | 0:03b5121a232e | 3916 | if (cur->type == XML_ATTRIBUTE_NODE) { |
| pcercuei | 0:03b5121a232e | 3917 | if (cur->parent->properties == (xmlAttrPtr)old) |
| pcercuei | 0:03b5121a232e | 3918 | cur->parent->properties = ((xmlAttrPtr) cur); |
| pcercuei | 0:03b5121a232e | 3919 | } else { |
| pcercuei | 0:03b5121a232e | 3920 | if (cur->parent->children == old) |
| pcercuei | 0:03b5121a232e | 3921 | cur->parent->children = cur; |
| pcercuei | 0:03b5121a232e | 3922 | if (cur->parent->last == old) |
| pcercuei | 0:03b5121a232e | 3923 | cur->parent->last = cur; |
| pcercuei | 0:03b5121a232e | 3924 | } |
| pcercuei | 0:03b5121a232e | 3925 | } |
| pcercuei | 0:03b5121a232e | 3926 | old->next = old->prev = NULL; |
| pcercuei | 0:03b5121a232e | 3927 | old->parent = NULL; |
| pcercuei | 0:03b5121a232e | 3928 | return(old); |
| pcercuei | 0:03b5121a232e | 3929 | } |
| pcercuei | 0:03b5121a232e | 3930 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 3931 | |
| pcercuei | 0:03b5121a232e | 3932 | /************************************************************************ |
| pcercuei | 0:03b5121a232e | 3933 | * * |
| pcercuei | 0:03b5121a232e | 3934 | * Copy operations * |
| pcercuei | 0:03b5121a232e | 3935 | * * |
| pcercuei | 0:03b5121a232e | 3936 | ************************************************************************/ |
| pcercuei | 0:03b5121a232e | 3937 | |
| pcercuei | 0:03b5121a232e | 3938 | /** |
| pcercuei | 0:03b5121a232e | 3939 | * xmlCopyNamespace: |
| pcercuei | 0:03b5121a232e | 3940 | * @cur: the namespace |
| pcercuei | 0:03b5121a232e | 3941 | * |
| pcercuei | 0:03b5121a232e | 3942 | * Do a copy of the namespace. |
| pcercuei | 0:03b5121a232e | 3943 | * |
| pcercuei | 0:03b5121a232e | 3944 | * Returns: a new #xmlNsPtr, or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 3945 | */ |
| pcercuei | 0:03b5121a232e | 3946 | xmlNsPtr |
| pcercuei | 0:03b5121a232e | 3947 | xmlCopyNamespace(xmlNsPtr cur) { |
| pcercuei | 0:03b5121a232e | 3948 | xmlNsPtr ret; |
| pcercuei | 0:03b5121a232e | 3949 | |
| pcercuei | 0:03b5121a232e | 3950 | if (cur == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 3951 | switch (cur->type) { |
| pcercuei | 0:03b5121a232e | 3952 | case XML_LOCAL_NAMESPACE: |
| pcercuei | 0:03b5121a232e | 3953 | ret = xmlNewNs(NULL, cur->href, cur->prefix); |
| pcercuei | 0:03b5121a232e | 3954 | break; |
| pcercuei | 0:03b5121a232e | 3955 | default: |
| pcercuei | 0:03b5121a232e | 3956 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 3957 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 3958 | "xmlCopyNamespace: invalid type %d\n", cur->type); |
| pcercuei | 0:03b5121a232e | 3959 | #endif |
| pcercuei | 0:03b5121a232e | 3960 | return(NULL); |
| pcercuei | 0:03b5121a232e | 3961 | } |
| pcercuei | 0:03b5121a232e | 3962 | return(ret); |
| pcercuei | 0:03b5121a232e | 3963 | } |
| pcercuei | 0:03b5121a232e | 3964 | |
| pcercuei | 0:03b5121a232e | 3965 | /** |
| pcercuei | 0:03b5121a232e | 3966 | * xmlCopyNamespaceList: |
| pcercuei | 0:03b5121a232e | 3967 | * @cur: the first namespace |
| pcercuei | 0:03b5121a232e | 3968 | * |
| pcercuei | 0:03b5121a232e | 3969 | * Do a copy of an namespace list. |
| pcercuei | 0:03b5121a232e | 3970 | * |
| pcercuei | 0:03b5121a232e | 3971 | * Returns: a new #xmlNsPtr, or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 3972 | */ |
| pcercuei | 0:03b5121a232e | 3973 | xmlNsPtr |
| pcercuei | 0:03b5121a232e | 3974 | xmlCopyNamespaceList(xmlNsPtr cur) { |
| pcercuei | 0:03b5121a232e | 3975 | xmlNsPtr ret = NULL; |
| pcercuei | 0:03b5121a232e | 3976 | xmlNsPtr p = NULL,q; |
| pcercuei | 0:03b5121a232e | 3977 | |
| pcercuei | 0:03b5121a232e | 3978 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 3979 | q = xmlCopyNamespace(cur); |
| pcercuei | 0:03b5121a232e | 3980 | if (p == NULL) { |
| pcercuei | 0:03b5121a232e | 3981 | ret = p = q; |
| pcercuei | 0:03b5121a232e | 3982 | } else { |
| pcercuei | 0:03b5121a232e | 3983 | p->next = q; |
| pcercuei | 0:03b5121a232e | 3984 | p = q; |
| pcercuei | 0:03b5121a232e | 3985 | } |
| pcercuei | 0:03b5121a232e | 3986 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 3987 | } |
| pcercuei | 0:03b5121a232e | 3988 | return(ret); |
| pcercuei | 0:03b5121a232e | 3989 | } |
| pcercuei | 0:03b5121a232e | 3990 | |
| pcercuei | 0:03b5121a232e | 3991 | static xmlNodePtr |
| pcercuei | 0:03b5121a232e | 3992 | xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent); |
| pcercuei | 0:03b5121a232e | 3993 | |
| pcercuei | 0:03b5121a232e | 3994 | static xmlAttrPtr |
| pcercuei | 0:03b5121a232e | 3995 | xmlCopyPropInternal(xmlDocPtr doc, xmlNodePtr target, xmlAttrPtr cur) { |
| pcercuei | 0:03b5121a232e | 3996 | xmlAttrPtr ret; |
| pcercuei | 0:03b5121a232e | 3997 | |
| pcercuei | 0:03b5121a232e | 3998 | if (cur == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 3999 | if ((target != NULL) && (target->type != XML_ELEMENT_NODE)) |
| pcercuei | 0:03b5121a232e | 4000 | return(NULL); |
| pcercuei | 0:03b5121a232e | 4001 | if (target != NULL) |
| pcercuei | 0:03b5121a232e | 4002 | ret = xmlNewDocProp(target->doc, cur->name, NULL); |
| pcercuei | 0:03b5121a232e | 4003 | else if (doc != NULL) |
| pcercuei | 0:03b5121a232e | 4004 | ret = xmlNewDocProp(doc, cur->name, NULL); |
| pcercuei | 0:03b5121a232e | 4005 | else if (cur->parent != NULL) |
| pcercuei | 0:03b5121a232e | 4006 | ret = xmlNewDocProp(cur->parent->doc, cur->name, NULL); |
| pcercuei | 0:03b5121a232e | 4007 | else if (cur->children != NULL) |
| pcercuei | 0:03b5121a232e | 4008 | ret = xmlNewDocProp(cur->children->doc, cur->name, NULL); |
| pcercuei | 0:03b5121a232e | 4009 | else |
| pcercuei | 0:03b5121a232e | 4010 | ret = xmlNewDocProp(NULL, cur->name, NULL); |
| pcercuei | 0:03b5121a232e | 4011 | if (ret == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 4012 | ret->parent = target; |
| pcercuei | 0:03b5121a232e | 4013 | |
| pcercuei | 0:03b5121a232e | 4014 | if ((cur->ns != NULL) && (target != NULL)) { |
| pcercuei | 0:03b5121a232e | 4015 | xmlNsPtr ns; |
| pcercuei | 0:03b5121a232e | 4016 | |
| pcercuei | 0:03b5121a232e | 4017 | ns = xmlSearchNs(target->doc, target, cur->ns->prefix); |
| pcercuei | 0:03b5121a232e | 4018 | if (ns == NULL) { |
| pcercuei | 0:03b5121a232e | 4019 | /* |
| pcercuei | 0:03b5121a232e | 4020 | * Humm, we are copying an element whose namespace is defined |
| pcercuei | 0:03b5121a232e | 4021 | * out of the new tree scope. Search it in the original tree |
| pcercuei | 0:03b5121a232e | 4022 | * and add it at the top of the new tree |
| pcercuei | 0:03b5121a232e | 4023 | */ |
| pcercuei | 0:03b5121a232e | 4024 | ns = xmlSearchNs(cur->doc, cur->parent, cur->ns->prefix); |
| pcercuei | 0:03b5121a232e | 4025 | if (ns != NULL) { |
| pcercuei | 0:03b5121a232e | 4026 | xmlNodePtr root = target; |
| pcercuei | 0:03b5121a232e | 4027 | xmlNodePtr pred = NULL; |
| pcercuei | 0:03b5121a232e | 4028 | |
| pcercuei | 0:03b5121a232e | 4029 | while (root->parent != NULL) { |
| pcercuei | 0:03b5121a232e | 4030 | pred = root; |
| pcercuei | 0:03b5121a232e | 4031 | root = root->parent; |
| pcercuei | 0:03b5121a232e | 4032 | } |
| pcercuei | 0:03b5121a232e | 4033 | if (root == (xmlNodePtr) target->doc) { |
| pcercuei | 0:03b5121a232e | 4034 | /* correct possibly cycling above the document elt */ |
| pcercuei | 0:03b5121a232e | 4035 | root = pred; |
| pcercuei | 0:03b5121a232e | 4036 | } |
| pcercuei | 0:03b5121a232e | 4037 | ret->ns = xmlNewNs(root, ns->href, ns->prefix); |
| pcercuei | 0:03b5121a232e | 4038 | } |
| pcercuei | 0:03b5121a232e | 4039 | } else { |
| pcercuei | 0:03b5121a232e | 4040 | /* |
| pcercuei | 0:03b5121a232e | 4041 | * we have to find something appropriate here since |
| pcercuei | 0:03b5121a232e | 4042 | * we cant be sure, that the namespce we found is identified |
| pcercuei | 0:03b5121a232e | 4043 | * by the prefix |
| pcercuei | 0:03b5121a232e | 4044 | */ |
| pcercuei | 0:03b5121a232e | 4045 | if (xmlStrEqual(ns->href, cur->ns->href)) { |
| pcercuei | 0:03b5121a232e | 4046 | /* this is the nice case */ |
| pcercuei | 0:03b5121a232e | 4047 | ret->ns = ns; |
| pcercuei | 0:03b5121a232e | 4048 | } else { |
| pcercuei | 0:03b5121a232e | 4049 | /* |
| pcercuei | 0:03b5121a232e | 4050 | * we are in trouble: we need a new reconcilied namespace. |
| pcercuei | 0:03b5121a232e | 4051 | * This is expensive |
| pcercuei | 0:03b5121a232e | 4052 | */ |
| pcercuei | 0:03b5121a232e | 4053 | ret->ns = xmlNewReconciliedNs(target->doc, target, cur->ns); |
| pcercuei | 0:03b5121a232e | 4054 | } |
| pcercuei | 0:03b5121a232e | 4055 | } |
| pcercuei | 0:03b5121a232e | 4056 | |
| pcercuei | 0:03b5121a232e | 4057 | } else |
| pcercuei | 0:03b5121a232e | 4058 | ret->ns = NULL; |
| pcercuei | 0:03b5121a232e | 4059 | |
| pcercuei | 0:03b5121a232e | 4060 | if (cur->children != NULL) { |
| pcercuei | 0:03b5121a232e | 4061 | xmlNodePtr tmp; |
| pcercuei | 0:03b5121a232e | 4062 | |
| pcercuei | 0:03b5121a232e | 4063 | ret->children = xmlStaticCopyNodeList(cur->children, ret->doc, (xmlNodePtr) ret); |
| pcercuei | 0:03b5121a232e | 4064 | ret->last = NULL; |
| pcercuei | 0:03b5121a232e | 4065 | tmp = ret->children; |
| pcercuei | 0:03b5121a232e | 4066 | while (tmp != NULL) { |
| pcercuei | 0:03b5121a232e | 4067 | /* tmp->parent = (xmlNodePtr)ret; */ |
| pcercuei | 0:03b5121a232e | 4068 | if (tmp->next == NULL) |
| pcercuei | 0:03b5121a232e | 4069 | ret->last = tmp; |
| pcercuei | 0:03b5121a232e | 4070 | tmp = tmp->next; |
| pcercuei | 0:03b5121a232e | 4071 | } |
| pcercuei | 0:03b5121a232e | 4072 | } |
| pcercuei | 0:03b5121a232e | 4073 | /* |
| pcercuei | 0:03b5121a232e | 4074 | * Try to handle IDs |
| pcercuei | 0:03b5121a232e | 4075 | */ |
| pcercuei | 0:03b5121a232e | 4076 | if ((target!= NULL) && (cur!= NULL) && |
| pcercuei | 0:03b5121a232e | 4077 | (target->doc != NULL) && (cur->doc != NULL) && |
| pcercuei | 0:03b5121a232e | 4078 | (cur->doc->ids != NULL) && (cur->parent != NULL)) { |
| pcercuei | 0:03b5121a232e | 4079 | if (xmlIsID(cur->doc, cur->parent, cur)) { |
| pcercuei | 0:03b5121a232e | 4080 | xmlChar *id; |
| pcercuei | 0:03b5121a232e | 4081 | |
| pcercuei | 0:03b5121a232e | 4082 | id = xmlNodeListGetString(cur->doc, cur->children, 1); |
| pcercuei | 0:03b5121a232e | 4083 | if (id != NULL) { |
| pcercuei | 0:03b5121a232e | 4084 | xmlAddID(NULL, target->doc, id, ret); |
| pcercuei | 0:03b5121a232e | 4085 | xmlFree(id); |
| pcercuei | 0:03b5121a232e | 4086 | } |
| pcercuei | 0:03b5121a232e | 4087 | } |
| pcercuei | 0:03b5121a232e | 4088 | } |
| pcercuei | 0:03b5121a232e | 4089 | return(ret); |
| pcercuei | 0:03b5121a232e | 4090 | } |
| pcercuei | 0:03b5121a232e | 4091 | |
| pcercuei | 0:03b5121a232e | 4092 | /** |
| pcercuei | 0:03b5121a232e | 4093 | * xmlCopyProp: |
| pcercuei | 0:03b5121a232e | 4094 | * @target: the element where the attribute will be grafted |
| pcercuei | 0:03b5121a232e | 4095 | * @cur: the attribute |
| pcercuei | 0:03b5121a232e | 4096 | * |
| pcercuei | 0:03b5121a232e | 4097 | * Do a copy of the attribute. |
| pcercuei | 0:03b5121a232e | 4098 | * |
| pcercuei | 0:03b5121a232e | 4099 | * Returns: a new #xmlAttrPtr, or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 4100 | */ |
| pcercuei | 0:03b5121a232e | 4101 | xmlAttrPtr |
| pcercuei | 0:03b5121a232e | 4102 | xmlCopyProp(xmlNodePtr target, xmlAttrPtr cur) { |
| pcercuei | 0:03b5121a232e | 4103 | return xmlCopyPropInternal(NULL, target, cur); |
| pcercuei | 0:03b5121a232e | 4104 | } |
| pcercuei | 0:03b5121a232e | 4105 | |
| pcercuei | 0:03b5121a232e | 4106 | /** |
| pcercuei | 0:03b5121a232e | 4107 | * xmlCopyPropList: |
| pcercuei | 0:03b5121a232e | 4108 | * @target: the element where the attributes will be grafted |
| pcercuei | 0:03b5121a232e | 4109 | * @cur: the first attribute |
| pcercuei | 0:03b5121a232e | 4110 | * |
| pcercuei | 0:03b5121a232e | 4111 | * Do a copy of an attribute list. |
| pcercuei | 0:03b5121a232e | 4112 | * |
| pcercuei | 0:03b5121a232e | 4113 | * Returns: a new #xmlAttrPtr, or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 4114 | */ |
| pcercuei | 0:03b5121a232e | 4115 | xmlAttrPtr |
| pcercuei | 0:03b5121a232e | 4116 | xmlCopyPropList(xmlNodePtr target, xmlAttrPtr cur) { |
| pcercuei | 0:03b5121a232e | 4117 | xmlAttrPtr ret = NULL; |
| pcercuei | 0:03b5121a232e | 4118 | xmlAttrPtr p = NULL,q; |
| pcercuei | 0:03b5121a232e | 4119 | |
| pcercuei | 0:03b5121a232e | 4120 | if ((target != NULL) && (target->type != XML_ELEMENT_NODE)) |
| pcercuei | 0:03b5121a232e | 4121 | return(NULL); |
| pcercuei | 0:03b5121a232e | 4122 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 4123 | q = xmlCopyProp(target, cur); |
| pcercuei | 0:03b5121a232e | 4124 | if (q == NULL) |
| pcercuei | 0:03b5121a232e | 4125 | return(NULL); |
| pcercuei | 0:03b5121a232e | 4126 | if (p == NULL) { |
| pcercuei | 0:03b5121a232e | 4127 | ret = p = q; |
| pcercuei | 0:03b5121a232e | 4128 | } else { |
| pcercuei | 0:03b5121a232e | 4129 | p->next = q; |
| pcercuei | 0:03b5121a232e | 4130 | q->prev = p; |
| pcercuei | 0:03b5121a232e | 4131 | p = q; |
| pcercuei | 0:03b5121a232e | 4132 | } |
| pcercuei | 0:03b5121a232e | 4133 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 4134 | } |
| pcercuei | 0:03b5121a232e | 4135 | return(ret); |
| pcercuei | 0:03b5121a232e | 4136 | } |
| pcercuei | 0:03b5121a232e | 4137 | |
| pcercuei | 0:03b5121a232e | 4138 | /* |
| pcercuei | 0:03b5121a232e | 4139 | * NOTE about the CopyNode operations ! |
| pcercuei | 0:03b5121a232e | 4140 | * |
| pcercuei | 0:03b5121a232e | 4141 | * They are split into external and internal parts for one |
| pcercuei | 0:03b5121a232e | 4142 | * tricky reason: namespaces. Doing a direct copy of a node |
| pcercuei | 0:03b5121a232e | 4143 | * say RPM:Copyright without changing the namespace pointer to |
| pcercuei | 0:03b5121a232e | 4144 | * something else can produce stale links. One way to do it is |
| pcercuei | 0:03b5121a232e | 4145 | * to keep a reference counter but this doesn't work as soon |
| pcercuei | 0:03b5121a232e | 4146 | * as one move the element or the subtree out of the scope of |
| pcercuei | 0:03b5121a232e | 4147 | * the existing namespace. The actual solution seems to add |
| pcercuei | 0:03b5121a232e | 4148 | * a copy of the namespace at the top of the copied tree if |
| pcercuei | 0:03b5121a232e | 4149 | * not available in the subtree. |
| pcercuei | 0:03b5121a232e | 4150 | * Hence two functions, the public front-end call the inner ones |
| pcercuei | 0:03b5121a232e | 4151 | * The argument "recursive" normally indicates a recursive copy |
| pcercuei | 0:03b5121a232e | 4152 | * of the node with values 0 (no) and 1 (yes). For XInclude, |
| pcercuei | 0:03b5121a232e | 4153 | * however, we allow a value of 2 to indicate copy properties and |
| pcercuei | 0:03b5121a232e | 4154 | * namespace info, but don't recurse on children. |
| pcercuei | 0:03b5121a232e | 4155 | */ |
| pcercuei | 0:03b5121a232e | 4156 | |
| pcercuei | 0:03b5121a232e | 4157 | static xmlNodePtr |
| pcercuei | 0:03b5121a232e | 4158 | xmlStaticCopyNode(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, |
| pcercuei | 0:03b5121a232e | 4159 | int extended) { |
| pcercuei | 0:03b5121a232e | 4160 | xmlNodePtr ret; |
| pcercuei | 0:03b5121a232e | 4161 | |
| pcercuei | 0:03b5121a232e | 4162 | if (node == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 4163 | switch (node->type) { |
| pcercuei | 0:03b5121a232e | 4164 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 4165 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 4166 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 4167 | case XML_DOCUMENT_FRAG_NODE: |
| pcercuei | 0:03b5121a232e | 4168 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 4169 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 4170 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 4171 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 4172 | case XML_XINCLUDE_START: |
| pcercuei | 0:03b5121a232e | 4173 | case XML_XINCLUDE_END: |
| pcercuei | 0:03b5121a232e | 4174 | break; |
| pcercuei | 0:03b5121a232e | 4175 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 4176 | return((xmlNodePtr) xmlCopyPropInternal(doc, parent, (xmlAttrPtr) node)); |
| pcercuei | 0:03b5121a232e | 4177 | case XML_NAMESPACE_DECL: |
| pcercuei | 0:03b5121a232e | 4178 | return((xmlNodePtr) xmlCopyNamespaceList((xmlNsPtr) node)); |
| pcercuei | 0:03b5121a232e | 4179 | |
| pcercuei | 0:03b5121a232e | 4180 | case XML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 4181 | case XML_HTML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 4182 | #ifdef LIBXML_DOCB_ENABLED |
| pcercuei | 0:03b5121a232e | 4183 | case XML_DOCB_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 4184 | #endif |
| pcercuei | 0:03b5121a232e | 4185 | #ifdef LIBXML_TREE_ENABLED |
| pcercuei | 0:03b5121a232e | 4186 | return((xmlNodePtr) xmlCopyDoc((xmlDocPtr) node, extended)); |
| pcercuei | 0:03b5121a232e | 4187 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 4188 | case XML_DOCUMENT_TYPE_NODE: |
| pcercuei | 0:03b5121a232e | 4189 | case XML_NOTATION_NODE: |
| pcercuei | 0:03b5121a232e | 4190 | case XML_DTD_NODE: |
| pcercuei | 0:03b5121a232e | 4191 | case XML_ELEMENT_DECL: |
| pcercuei | 0:03b5121a232e | 4192 | case XML_ATTRIBUTE_DECL: |
| pcercuei | 0:03b5121a232e | 4193 | case XML_ENTITY_DECL: |
| pcercuei | 0:03b5121a232e | 4194 | return(NULL); |
| pcercuei | 0:03b5121a232e | 4195 | } |
| pcercuei | 0:03b5121a232e | 4196 | |
| pcercuei | 0:03b5121a232e | 4197 | /* |
| pcercuei | 0:03b5121a232e | 4198 | * Allocate a new node and fill the fields. |
| pcercuei | 0:03b5121a232e | 4199 | */ |
| pcercuei | 0:03b5121a232e | 4200 | ret = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 4201 | if (ret == NULL) { |
| pcercuei | 0:03b5121a232e | 4202 | xmlTreeErrMemory("copying node"); |
| pcercuei | 0:03b5121a232e | 4203 | return(NULL); |
| pcercuei | 0:03b5121a232e | 4204 | } |
| pcercuei | 0:03b5121a232e | 4205 | memset(ret, 0, sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 4206 | ret->type = node->type; |
| pcercuei | 0:03b5121a232e | 4207 | |
| pcercuei | 0:03b5121a232e | 4208 | ret->doc = doc; |
| pcercuei | 0:03b5121a232e | 4209 | ret->parent = parent; |
| pcercuei | 0:03b5121a232e | 4210 | if (node->name == xmlStringText) |
| pcercuei | 0:03b5121a232e | 4211 | ret->name = xmlStringText; |
| pcercuei | 0:03b5121a232e | 4212 | else if (node->name == xmlStringTextNoenc) |
| pcercuei | 0:03b5121a232e | 4213 | ret->name = xmlStringTextNoenc; |
| pcercuei | 0:03b5121a232e | 4214 | else if (node->name == xmlStringComment) |
| pcercuei | 0:03b5121a232e | 4215 | ret->name = xmlStringComment; |
| pcercuei | 0:03b5121a232e | 4216 | else if (node->name != NULL) { |
| pcercuei | 0:03b5121a232e | 4217 | if ((doc != NULL) && (doc->dict != NULL)) |
| pcercuei | 0:03b5121a232e | 4218 | ret->name = xmlDictLookup(doc->dict, node->name, -1); |
| pcercuei | 0:03b5121a232e | 4219 | else |
| pcercuei | 0:03b5121a232e | 4220 | ret->name = xmlStrdup(node->name); |
| pcercuei | 0:03b5121a232e | 4221 | } |
| pcercuei | 0:03b5121a232e | 4222 | if ((node->type != XML_ELEMENT_NODE) && |
| pcercuei | 0:03b5121a232e | 4223 | (node->content != NULL) && |
| pcercuei | 0:03b5121a232e | 4224 | (node->type != XML_ENTITY_REF_NODE) && |
| pcercuei | 0:03b5121a232e | 4225 | (node->type != XML_XINCLUDE_END) && |
| pcercuei | 0:03b5121a232e | 4226 | (node->type != XML_XINCLUDE_START)) { |
| pcercuei | 0:03b5121a232e | 4227 | ret->content = xmlStrdup(node->content); |
| pcercuei | 0:03b5121a232e | 4228 | }else{ |
| pcercuei | 0:03b5121a232e | 4229 | if (node->type == XML_ELEMENT_NODE) |
| pcercuei | 0:03b5121a232e | 4230 | ret->line = node->line; |
| pcercuei | 0:03b5121a232e | 4231 | } |
| pcercuei | 0:03b5121a232e | 4232 | if (parent != NULL) { |
| pcercuei | 0:03b5121a232e | 4233 | xmlNodePtr tmp; |
| pcercuei | 0:03b5121a232e | 4234 | |
| pcercuei | 0:03b5121a232e | 4235 | /* |
| pcercuei | 0:03b5121a232e | 4236 | * this is a tricky part for the node register thing: |
| pcercuei | 0:03b5121a232e | 4237 | * in case ret does get coalesced in xmlAddChild |
| pcercuei | 0:03b5121a232e | 4238 | * the deregister-node callback is called; so we register ret now already |
| pcercuei | 0:03b5121a232e | 4239 | */ |
| pcercuei | 0:03b5121a232e | 4240 | if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
| pcercuei | 0:03b5121a232e | 4241 | xmlRegisterNodeDefaultValue((xmlNodePtr)ret); |
| pcercuei | 0:03b5121a232e | 4242 | |
| pcercuei | 0:03b5121a232e | 4243 | tmp = xmlAddChild(parent, ret); |
| pcercuei | 0:03b5121a232e | 4244 | /* node could have coalesced */ |
| pcercuei | 0:03b5121a232e | 4245 | if (tmp != ret) |
| pcercuei | 0:03b5121a232e | 4246 | return(tmp); |
| pcercuei | 0:03b5121a232e | 4247 | } |
| pcercuei | 0:03b5121a232e | 4248 | |
| pcercuei | 0:03b5121a232e | 4249 | if (!extended) |
| pcercuei | 0:03b5121a232e | 4250 | goto out; |
| pcercuei | 0:03b5121a232e | 4251 | if (((node->type == XML_ELEMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 4252 | (node->type == XML_XINCLUDE_START)) && (node->nsDef != NULL)) |
| pcercuei | 0:03b5121a232e | 4253 | ret->nsDef = xmlCopyNamespaceList(node->nsDef); |
| pcercuei | 0:03b5121a232e | 4254 | |
| pcercuei | 0:03b5121a232e | 4255 | if (node->ns != NULL) { |
| pcercuei | 0:03b5121a232e | 4256 | xmlNsPtr ns; |
| pcercuei | 0:03b5121a232e | 4257 | |
| pcercuei | 0:03b5121a232e | 4258 | ns = xmlSearchNs(doc, ret, node->ns->prefix); |
| pcercuei | 0:03b5121a232e | 4259 | if (ns == NULL) { |
| pcercuei | 0:03b5121a232e | 4260 | /* |
| pcercuei | 0:03b5121a232e | 4261 | * Humm, we are copying an element whose namespace is defined |
| pcercuei | 0:03b5121a232e | 4262 | * out of the new tree scope. Search it in the original tree |
| pcercuei | 0:03b5121a232e | 4263 | * and add it at the top of the new tree |
| pcercuei | 0:03b5121a232e | 4264 | */ |
| pcercuei | 0:03b5121a232e | 4265 | ns = xmlSearchNs(node->doc, node, node->ns->prefix); |
| pcercuei | 0:03b5121a232e | 4266 | if (ns != NULL) { |
| pcercuei | 0:03b5121a232e | 4267 | xmlNodePtr root = ret; |
| pcercuei | 0:03b5121a232e | 4268 | |
| pcercuei | 0:03b5121a232e | 4269 | while (root->parent != NULL) root = root->parent; |
| pcercuei | 0:03b5121a232e | 4270 | ret->ns = xmlNewNs(root, ns->href, ns->prefix); |
| pcercuei | 0:03b5121a232e | 4271 | } else { |
| pcercuei | 0:03b5121a232e | 4272 | ret->ns = xmlNewReconciliedNs(doc, ret, node->ns); |
| pcercuei | 0:03b5121a232e | 4273 | } |
| pcercuei | 0:03b5121a232e | 4274 | } else { |
| pcercuei | 0:03b5121a232e | 4275 | /* |
| pcercuei | 0:03b5121a232e | 4276 | * reference the existing namespace definition in our own tree. |
| pcercuei | 0:03b5121a232e | 4277 | */ |
| pcercuei | 0:03b5121a232e | 4278 | ret->ns = ns; |
| pcercuei | 0:03b5121a232e | 4279 | } |
| pcercuei | 0:03b5121a232e | 4280 | } |
| pcercuei | 0:03b5121a232e | 4281 | if (((node->type == XML_ELEMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 4282 | (node->type == XML_XINCLUDE_START)) && (node->properties != NULL)) |
| pcercuei | 0:03b5121a232e | 4283 | ret->properties = xmlCopyPropList(ret, node->properties); |
| pcercuei | 0:03b5121a232e | 4284 | if (node->type == XML_ENTITY_REF_NODE) { |
| pcercuei | 0:03b5121a232e | 4285 | if ((doc == NULL) || (node->doc != doc)) { |
| pcercuei | 0:03b5121a232e | 4286 | /* |
| pcercuei | 0:03b5121a232e | 4287 | * The copied node will go into a separate document, so |
| pcercuei | 0:03b5121a232e | 4288 | * to avoid dangling references to the ENTITY_DECL node |
| pcercuei | 0:03b5121a232e | 4289 | * we cannot keep the reference. Try to find it in the |
| pcercuei | 0:03b5121a232e | 4290 | * target document. |
| pcercuei | 0:03b5121a232e | 4291 | */ |
| pcercuei | 0:03b5121a232e | 4292 | ret->children = (xmlNodePtr) xmlGetDocEntity(doc, ret->name); |
| pcercuei | 0:03b5121a232e | 4293 | } else { |
| pcercuei | 0:03b5121a232e | 4294 | ret->children = node->children; |
| pcercuei | 0:03b5121a232e | 4295 | } |
| pcercuei | 0:03b5121a232e | 4296 | ret->last = ret->children; |
| pcercuei | 0:03b5121a232e | 4297 | } else if ((node->children != NULL) && (extended != 2)) { |
| pcercuei | 0:03b5121a232e | 4298 | ret->children = xmlStaticCopyNodeList(node->children, doc, ret); |
| pcercuei | 0:03b5121a232e | 4299 | UPDATE_LAST_CHILD_AND_PARENT(ret) |
| pcercuei | 0:03b5121a232e | 4300 | } |
| pcercuei | 0:03b5121a232e | 4301 | |
| pcercuei | 0:03b5121a232e | 4302 | out: |
| pcercuei | 0:03b5121a232e | 4303 | /* if parent != NULL we already registered the node above */ |
| pcercuei | 0:03b5121a232e | 4304 | if ((parent == NULL) && |
| pcercuei | 0:03b5121a232e | 4305 | ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue))) |
| pcercuei | 0:03b5121a232e | 4306 | xmlRegisterNodeDefaultValue((xmlNodePtr)ret); |
| pcercuei | 0:03b5121a232e | 4307 | return(ret); |
| pcercuei | 0:03b5121a232e | 4308 | } |
| pcercuei | 0:03b5121a232e | 4309 | |
| pcercuei | 0:03b5121a232e | 4310 | static xmlNodePtr |
| pcercuei | 0:03b5121a232e | 4311 | xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent) { |
| pcercuei | 0:03b5121a232e | 4312 | xmlNodePtr ret = NULL; |
| pcercuei | 0:03b5121a232e | 4313 | xmlNodePtr p = NULL,q; |
| pcercuei | 0:03b5121a232e | 4314 | |
| pcercuei | 0:03b5121a232e | 4315 | while (node != NULL) { |
| pcercuei | 0:03b5121a232e | 4316 | #ifdef LIBXML_TREE_ENABLED |
| pcercuei | 0:03b5121a232e | 4317 | if (node->type == XML_DTD_NODE ) { |
| pcercuei | 0:03b5121a232e | 4318 | if (doc == NULL) { |
| pcercuei | 0:03b5121a232e | 4319 | node = node->next; |
| pcercuei | 0:03b5121a232e | 4320 | continue; |
| pcercuei | 0:03b5121a232e | 4321 | } |
| pcercuei | 0:03b5121a232e | 4322 | if (doc->intSubset == NULL) { |
| pcercuei | 0:03b5121a232e | 4323 | q = (xmlNodePtr) xmlCopyDtd( (xmlDtdPtr) node ); |
| pcercuei | 0:03b5121a232e | 4324 | if (q == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 4325 | q->doc = doc; |
| pcercuei | 0:03b5121a232e | 4326 | q->parent = parent; |
| pcercuei | 0:03b5121a232e | 4327 | doc->intSubset = (xmlDtdPtr) q; |
| pcercuei | 0:03b5121a232e | 4328 | xmlAddChild(parent, q); |
| pcercuei | 0:03b5121a232e | 4329 | } else { |
| pcercuei | 0:03b5121a232e | 4330 | q = (xmlNodePtr) doc->intSubset; |
| pcercuei | 0:03b5121a232e | 4331 | xmlAddChild(parent, q); |
| pcercuei | 0:03b5121a232e | 4332 | } |
| pcercuei | 0:03b5121a232e | 4333 | } else |
| pcercuei | 0:03b5121a232e | 4334 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 4335 | q = xmlStaticCopyNode(node, doc, parent, 1); |
| pcercuei | 0:03b5121a232e | 4336 | if (q == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 4337 | if (ret == NULL) { |
| pcercuei | 0:03b5121a232e | 4338 | q->prev = NULL; |
| pcercuei | 0:03b5121a232e | 4339 | ret = p = q; |
| pcercuei | 0:03b5121a232e | 4340 | } else if (p != q) { |
| pcercuei | 0:03b5121a232e | 4341 | /* the test is required if xmlStaticCopyNode coalesced 2 text nodes */ |
| pcercuei | 0:03b5121a232e | 4342 | p->next = q; |
| pcercuei | 0:03b5121a232e | 4343 | q->prev = p; |
| pcercuei | 0:03b5121a232e | 4344 | p = q; |
| pcercuei | 0:03b5121a232e | 4345 | } |
| pcercuei | 0:03b5121a232e | 4346 | node = node->next; |
| pcercuei | 0:03b5121a232e | 4347 | } |
| pcercuei | 0:03b5121a232e | 4348 | return(ret); |
| pcercuei | 0:03b5121a232e | 4349 | } |
| pcercuei | 0:03b5121a232e | 4350 | |
| pcercuei | 0:03b5121a232e | 4351 | /** |
| pcercuei | 0:03b5121a232e | 4352 | * xmlCopyNode: |
| pcercuei | 0:03b5121a232e | 4353 | * @node: the node |
| pcercuei | 0:03b5121a232e | 4354 | * @extended: if 1 do a recursive copy (properties, namespaces and children |
| pcercuei | 0:03b5121a232e | 4355 | * when applicable) |
| pcercuei | 0:03b5121a232e | 4356 | * if 2 copy properties and namespaces (when applicable) |
| pcercuei | 0:03b5121a232e | 4357 | * |
| pcercuei | 0:03b5121a232e | 4358 | * Do a copy of the node. |
| pcercuei | 0:03b5121a232e | 4359 | * |
| pcercuei | 0:03b5121a232e | 4360 | * Returns: a new #xmlNodePtr, or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 4361 | */ |
| pcercuei | 0:03b5121a232e | 4362 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 4363 | xmlCopyNode(xmlNodePtr node, int extended) { |
| pcercuei | 0:03b5121a232e | 4364 | xmlNodePtr ret; |
| pcercuei | 0:03b5121a232e | 4365 | |
| pcercuei | 0:03b5121a232e | 4366 | ret = xmlStaticCopyNode(node, NULL, NULL, extended); |
| pcercuei | 0:03b5121a232e | 4367 | return(ret); |
| pcercuei | 0:03b5121a232e | 4368 | } |
| pcercuei | 0:03b5121a232e | 4369 | |
| pcercuei | 0:03b5121a232e | 4370 | /** |
| pcercuei | 0:03b5121a232e | 4371 | * xmlDocCopyNode: |
| pcercuei | 0:03b5121a232e | 4372 | * @node: the node |
| pcercuei | 0:03b5121a232e | 4373 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 4374 | * @extended: if 1 do a recursive copy (properties, namespaces and children |
| pcercuei | 0:03b5121a232e | 4375 | * when applicable) |
| pcercuei | 0:03b5121a232e | 4376 | * if 2 copy properties and namespaces (when applicable) |
| pcercuei | 0:03b5121a232e | 4377 | * |
| pcercuei | 0:03b5121a232e | 4378 | * Do a copy of the node to a given document. |
| pcercuei | 0:03b5121a232e | 4379 | * |
| pcercuei | 0:03b5121a232e | 4380 | * Returns: a new #xmlNodePtr, or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 4381 | */ |
| pcercuei | 0:03b5121a232e | 4382 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 4383 | xmlDocCopyNode(xmlNodePtr node, xmlDocPtr doc, int extended) { |
| pcercuei | 0:03b5121a232e | 4384 | xmlNodePtr ret; |
| pcercuei | 0:03b5121a232e | 4385 | |
| pcercuei | 0:03b5121a232e | 4386 | ret = xmlStaticCopyNode(node, doc, NULL, extended); |
| pcercuei | 0:03b5121a232e | 4387 | return(ret); |
| pcercuei | 0:03b5121a232e | 4388 | } |
| pcercuei | 0:03b5121a232e | 4389 | |
| pcercuei | 0:03b5121a232e | 4390 | /** |
| pcercuei | 0:03b5121a232e | 4391 | * xmlDocCopyNodeList: |
| pcercuei | 0:03b5121a232e | 4392 | * @doc: the target document |
| pcercuei | 0:03b5121a232e | 4393 | * @node: the first node in the list. |
| pcercuei | 0:03b5121a232e | 4394 | * |
| pcercuei | 0:03b5121a232e | 4395 | * Do a recursive copy of the node list. |
| pcercuei | 0:03b5121a232e | 4396 | * |
| pcercuei | 0:03b5121a232e | 4397 | * Returns: a new #xmlNodePtr, or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 4398 | */ |
| pcercuei | 0:03b5121a232e | 4399 | xmlNodePtr xmlDocCopyNodeList(xmlDocPtr doc, xmlNodePtr node) { |
| pcercuei | 0:03b5121a232e | 4400 | xmlNodePtr ret = xmlStaticCopyNodeList(node, doc, NULL); |
| pcercuei | 0:03b5121a232e | 4401 | return(ret); |
| pcercuei | 0:03b5121a232e | 4402 | } |
| pcercuei | 0:03b5121a232e | 4403 | |
| pcercuei | 0:03b5121a232e | 4404 | /** |
| pcercuei | 0:03b5121a232e | 4405 | * xmlCopyNodeList: |
| pcercuei | 0:03b5121a232e | 4406 | * @node: the first node in the list. |
| pcercuei | 0:03b5121a232e | 4407 | * |
| pcercuei | 0:03b5121a232e | 4408 | * Do a recursive copy of the node list. |
| pcercuei | 0:03b5121a232e | 4409 | * Use xmlDocCopyNodeList() if possible to ensure string interning. |
| pcercuei | 0:03b5121a232e | 4410 | * |
| pcercuei | 0:03b5121a232e | 4411 | * Returns: a new #xmlNodePtr, or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 4412 | */ |
| pcercuei | 0:03b5121a232e | 4413 | xmlNodePtr xmlCopyNodeList(xmlNodePtr node) { |
| pcercuei | 0:03b5121a232e | 4414 | xmlNodePtr ret = xmlStaticCopyNodeList(node, NULL, NULL); |
| pcercuei | 0:03b5121a232e | 4415 | return(ret); |
| pcercuei | 0:03b5121a232e | 4416 | } |
| pcercuei | 0:03b5121a232e | 4417 | |
| pcercuei | 0:03b5121a232e | 4418 | #if defined(LIBXML_TREE_ENABLED) |
| pcercuei | 0:03b5121a232e | 4419 | /** |
| pcercuei | 0:03b5121a232e | 4420 | * xmlCopyDtd: |
| pcercuei | 0:03b5121a232e | 4421 | * @dtd: the dtd |
| pcercuei | 0:03b5121a232e | 4422 | * |
| pcercuei | 0:03b5121a232e | 4423 | * Do a copy of the dtd. |
| pcercuei | 0:03b5121a232e | 4424 | * |
| pcercuei | 0:03b5121a232e | 4425 | * Returns: a new #xmlDtdPtr, or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 4426 | */ |
| pcercuei | 0:03b5121a232e | 4427 | xmlDtdPtr |
| pcercuei | 0:03b5121a232e | 4428 | xmlCopyDtd(xmlDtdPtr dtd) { |
| pcercuei | 0:03b5121a232e | 4429 | xmlDtdPtr ret; |
| pcercuei | 0:03b5121a232e | 4430 | xmlNodePtr cur, p = NULL, q; |
| pcercuei | 0:03b5121a232e | 4431 | |
| pcercuei | 0:03b5121a232e | 4432 | if (dtd == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 4433 | ret = xmlNewDtd(NULL, dtd->name, dtd->ExternalID, dtd->SystemID); |
| pcercuei | 0:03b5121a232e | 4434 | if (ret == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 4435 | if (dtd->entities != NULL) |
| pcercuei | 0:03b5121a232e | 4436 | ret->entities = (void *) xmlCopyEntitiesTable( |
| pcercuei | 0:03b5121a232e | 4437 | (xmlEntitiesTablePtr) dtd->entities); |
| pcercuei | 0:03b5121a232e | 4438 | if (dtd->notations != NULL) |
| pcercuei | 0:03b5121a232e | 4439 | ret->notations = (void *) xmlCopyNotationTable( |
| pcercuei | 0:03b5121a232e | 4440 | (xmlNotationTablePtr) dtd->notations); |
| pcercuei | 0:03b5121a232e | 4441 | if (dtd->elements != NULL) |
| pcercuei | 0:03b5121a232e | 4442 | ret->elements = (void *) xmlCopyElementTable( |
| pcercuei | 0:03b5121a232e | 4443 | (xmlElementTablePtr) dtd->elements); |
| pcercuei | 0:03b5121a232e | 4444 | if (dtd->attributes != NULL) |
| pcercuei | 0:03b5121a232e | 4445 | ret->attributes = (void *) xmlCopyAttributeTable( |
| pcercuei | 0:03b5121a232e | 4446 | (xmlAttributeTablePtr) dtd->attributes); |
| pcercuei | 0:03b5121a232e | 4447 | if (dtd->pentities != NULL) |
| pcercuei | 0:03b5121a232e | 4448 | ret->pentities = (void *) xmlCopyEntitiesTable( |
| pcercuei | 0:03b5121a232e | 4449 | (xmlEntitiesTablePtr) dtd->pentities); |
| pcercuei | 0:03b5121a232e | 4450 | |
| pcercuei | 0:03b5121a232e | 4451 | cur = dtd->children; |
| pcercuei | 0:03b5121a232e | 4452 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 4453 | q = NULL; |
| pcercuei | 0:03b5121a232e | 4454 | |
| pcercuei | 0:03b5121a232e | 4455 | if (cur->type == XML_ENTITY_DECL) { |
| pcercuei | 0:03b5121a232e | 4456 | xmlEntityPtr tmp = (xmlEntityPtr) cur; |
| pcercuei | 0:03b5121a232e | 4457 | switch (tmp->etype) { |
| pcercuei | 0:03b5121a232e | 4458 | case XML_INTERNAL_GENERAL_ENTITY: |
| pcercuei | 0:03b5121a232e | 4459 | case XML_EXTERNAL_GENERAL_PARSED_ENTITY: |
| pcercuei | 0:03b5121a232e | 4460 | case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: |
| pcercuei | 0:03b5121a232e | 4461 | q = (xmlNodePtr) xmlGetEntityFromDtd(ret, tmp->name); |
| pcercuei | 0:03b5121a232e | 4462 | break; |
| pcercuei | 0:03b5121a232e | 4463 | case XML_INTERNAL_PARAMETER_ENTITY: |
| pcercuei | 0:03b5121a232e | 4464 | case XML_EXTERNAL_PARAMETER_ENTITY: |
| pcercuei | 0:03b5121a232e | 4465 | q = (xmlNodePtr) |
| pcercuei | 0:03b5121a232e | 4466 | xmlGetParameterEntityFromDtd(ret, tmp->name); |
| pcercuei | 0:03b5121a232e | 4467 | break; |
| pcercuei | 0:03b5121a232e | 4468 | case XML_INTERNAL_PREDEFINED_ENTITY: |
| pcercuei | 0:03b5121a232e | 4469 | break; |
| pcercuei | 0:03b5121a232e | 4470 | } |
| pcercuei | 0:03b5121a232e | 4471 | } else if (cur->type == XML_ELEMENT_DECL) { |
| pcercuei | 0:03b5121a232e | 4472 | xmlElementPtr tmp = (xmlElementPtr) cur; |
| pcercuei | 0:03b5121a232e | 4473 | q = (xmlNodePtr) |
| pcercuei | 0:03b5121a232e | 4474 | xmlGetDtdQElementDesc(ret, tmp->name, tmp->prefix); |
| pcercuei | 0:03b5121a232e | 4475 | } else if (cur->type == XML_ATTRIBUTE_DECL) { |
| pcercuei | 0:03b5121a232e | 4476 | xmlAttributePtr tmp = (xmlAttributePtr) cur; |
| pcercuei | 0:03b5121a232e | 4477 | q = (xmlNodePtr) |
| pcercuei | 0:03b5121a232e | 4478 | xmlGetDtdQAttrDesc(ret, tmp->elem, tmp->name, tmp->prefix); |
| pcercuei | 0:03b5121a232e | 4479 | } else if (cur->type == XML_COMMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 4480 | q = xmlCopyNode(cur, 0); |
| pcercuei | 0:03b5121a232e | 4481 | } |
| pcercuei | 0:03b5121a232e | 4482 | |
| pcercuei | 0:03b5121a232e | 4483 | if (q == NULL) { |
| pcercuei | 0:03b5121a232e | 4484 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 4485 | continue; |
| pcercuei | 0:03b5121a232e | 4486 | } |
| pcercuei | 0:03b5121a232e | 4487 | |
| pcercuei | 0:03b5121a232e | 4488 | if (p == NULL) |
| pcercuei | 0:03b5121a232e | 4489 | ret->children = q; |
| pcercuei | 0:03b5121a232e | 4490 | else |
| pcercuei | 0:03b5121a232e | 4491 | p->next = q; |
| pcercuei | 0:03b5121a232e | 4492 | |
| pcercuei | 0:03b5121a232e | 4493 | q->prev = p; |
| pcercuei | 0:03b5121a232e | 4494 | q->parent = (xmlNodePtr) ret; |
| pcercuei | 0:03b5121a232e | 4495 | q->next = NULL; |
| pcercuei | 0:03b5121a232e | 4496 | ret->last = q; |
| pcercuei | 0:03b5121a232e | 4497 | p = q; |
| pcercuei | 0:03b5121a232e | 4498 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 4499 | } |
| pcercuei | 0:03b5121a232e | 4500 | |
| pcercuei | 0:03b5121a232e | 4501 | return(ret); |
| pcercuei | 0:03b5121a232e | 4502 | } |
| pcercuei | 0:03b5121a232e | 4503 | #endif |
| pcercuei | 0:03b5121a232e | 4504 | |
| pcercuei | 0:03b5121a232e | 4505 | #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) |
| pcercuei | 0:03b5121a232e | 4506 | /** |
| pcercuei | 0:03b5121a232e | 4507 | * xmlCopyDoc: |
| pcercuei | 0:03b5121a232e | 4508 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 4509 | * @recursive: if not zero do a recursive copy. |
| pcercuei | 0:03b5121a232e | 4510 | * |
| pcercuei | 0:03b5121a232e | 4511 | * Do a copy of the document info. If recursive, the content tree will |
| pcercuei | 0:03b5121a232e | 4512 | * be copied too as well as DTD, namespaces and entities. |
| pcercuei | 0:03b5121a232e | 4513 | * |
| pcercuei | 0:03b5121a232e | 4514 | * Returns: a new #xmlDocPtr, or NULL in case of error. |
| pcercuei | 0:03b5121a232e | 4515 | */ |
| pcercuei | 0:03b5121a232e | 4516 | xmlDocPtr |
| pcercuei | 0:03b5121a232e | 4517 | xmlCopyDoc(xmlDocPtr doc, int recursive) { |
| pcercuei | 0:03b5121a232e | 4518 | xmlDocPtr ret; |
| pcercuei | 0:03b5121a232e | 4519 | |
| pcercuei | 0:03b5121a232e | 4520 | if (doc == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 4521 | ret = xmlNewDoc(doc->version); |
| pcercuei | 0:03b5121a232e | 4522 | if (ret == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 4523 | if (doc->name != NULL) |
| pcercuei | 0:03b5121a232e | 4524 | ret->name = xmlMemStrdup(doc->name); |
| pcercuei | 0:03b5121a232e | 4525 | if (doc->encoding != NULL) |
| pcercuei | 0:03b5121a232e | 4526 | ret->encoding = xmlStrdup(doc->encoding); |
| pcercuei | 0:03b5121a232e | 4527 | if (doc->URL != NULL) |
| pcercuei | 0:03b5121a232e | 4528 | ret->URL = xmlStrdup(doc->URL); |
| pcercuei | 0:03b5121a232e | 4529 | ret->charset = doc->charset; |
| pcercuei | 0:03b5121a232e | 4530 | ret->compression = doc->compression; |
| pcercuei | 0:03b5121a232e | 4531 | ret->standalone = doc->standalone; |
| pcercuei | 0:03b5121a232e | 4532 | if (!recursive) return(ret); |
| pcercuei | 0:03b5121a232e | 4533 | |
| pcercuei | 0:03b5121a232e | 4534 | ret->last = NULL; |
| pcercuei | 0:03b5121a232e | 4535 | ret->children = NULL; |
| pcercuei | 0:03b5121a232e | 4536 | #ifdef LIBXML_TREE_ENABLED |
| pcercuei | 0:03b5121a232e | 4537 | if (doc->intSubset != NULL) { |
| pcercuei | 0:03b5121a232e | 4538 | ret->intSubset = xmlCopyDtd(doc->intSubset); |
| pcercuei | 0:03b5121a232e | 4539 | if (ret->intSubset == NULL) { |
| pcercuei | 0:03b5121a232e | 4540 | xmlFreeDoc(ret); |
| pcercuei | 0:03b5121a232e | 4541 | return(NULL); |
| pcercuei | 0:03b5121a232e | 4542 | } |
| pcercuei | 0:03b5121a232e | 4543 | xmlSetTreeDoc((xmlNodePtr)ret->intSubset, ret); |
| pcercuei | 0:03b5121a232e | 4544 | ret->intSubset->parent = ret; |
| pcercuei | 0:03b5121a232e | 4545 | } |
| pcercuei | 0:03b5121a232e | 4546 | #endif |
| pcercuei | 0:03b5121a232e | 4547 | if (doc->oldNs != NULL) |
| pcercuei | 0:03b5121a232e | 4548 | ret->oldNs = xmlCopyNamespaceList(doc->oldNs); |
| pcercuei | 0:03b5121a232e | 4549 | if (doc->children != NULL) { |
| pcercuei | 0:03b5121a232e | 4550 | xmlNodePtr tmp; |
| pcercuei | 0:03b5121a232e | 4551 | |
| pcercuei | 0:03b5121a232e | 4552 | ret->children = xmlStaticCopyNodeList(doc->children, ret, |
| pcercuei | 0:03b5121a232e | 4553 | (xmlNodePtr)ret); |
| pcercuei | 0:03b5121a232e | 4554 | ret->last = NULL; |
| pcercuei | 0:03b5121a232e | 4555 | tmp = ret->children; |
| pcercuei | 0:03b5121a232e | 4556 | while (tmp != NULL) { |
| pcercuei | 0:03b5121a232e | 4557 | if (tmp->next == NULL) |
| pcercuei | 0:03b5121a232e | 4558 | ret->last = tmp; |
| pcercuei | 0:03b5121a232e | 4559 | tmp = tmp->next; |
| pcercuei | 0:03b5121a232e | 4560 | } |
| pcercuei | 0:03b5121a232e | 4561 | } |
| pcercuei | 0:03b5121a232e | 4562 | return(ret); |
| pcercuei | 0:03b5121a232e | 4563 | } |
| pcercuei | 0:03b5121a232e | 4564 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 4565 | |
| pcercuei | 0:03b5121a232e | 4566 | /************************************************************************ |
| pcercuei | 0:03b5121a232e | 4567 | * * |
| pcercuei | 0:03b5121a232e | 4568 | * Content access functions * |
| pcercuei | 0:03b5121a232e | 4569 | * * |
| pcercuei | 0:03b5121a232e | 4570 | ************************************************************************/ |
| pcercuei | 0:03b5121a232e | 4571 | |
| pcercuei | 0:03b5121a232e | 4572 | /** |
| pcercuei | 0:03b5121a232e | 4573 | * xmlGetLineNoInternal: |
| pcercuei | 0:03b5121a232e | 4574 | * @node: valid node |
| pcercuei | 0:03b5121a232e | 4575 | * @depth: used to limit any risk of recursion |
| pcercuei | 0:03b5121a232e | 4576 | * |
| pcercuei | 0:03b5121a232e | 4577 | * Get line number of @node. |
| pcercuei | 0:03b5121a232e | 4578 | * Try to override the limitation of lines being store in 16 bits ints |
| pcercuei | 0:03b5121a232e | 4579 | * |
| pcercuei | 0:03b5121a232e | 4580 | * Returns the line number if successful, -1 otherwise |
| pcercuei | 0:03b5121a232e | 4581 | */ |
| pcercuei | 0:03b5121a232e | 4582 | static long |
| pcercuei | 0:03b5121a232e | 4583 | xmlGetLineNoInternal(const xmlNode *node, int depth) |
| pcercuei | 0:03b5121a232e | 4584 | { |
| pcercuei | 0:03b5121a232e | 4585 | long result = -1; |
| pcercuei | 0:03b5121a232e | 4586 | |
| pcercuei | 0:03b5121a232e | 4587 | if (depth >= 5) |
| pcercuei | 0:03b5121a232e | 4588 | return(-1); |
| pcercuei | 0:03b5121a232e | 4589 | |
| pcercuei | 0:03b5121a232e | 4590 | if (!node) |
| pcercuei | 0:03b5121a232e | 4591 | return result; |
| pcercuei | 0:03b5121a232e | 4592 | if ((node->type == XML_ELEMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 4593 | (node->type == XML_TEXT_NODE) || |
| pcercuei | 0:03b5121a232e | 4594 | (node->type == XML_COMMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 4595 | (node->type == XML_PI_NODE)) { |
| pcercuei | 0:03b5121a232e | 4596 | if (node->line == 65535) { |
| pcercuei | 0:03b5121a232e | 4597 | if ((node->type == XML_TEXT_NODE) && (node->psvi != NULL)) |
| pcercuei | 0:03b5121a232e | 4598 | result = (long) node->psvi; |
| pcercuei | 0:03b5121a232e | 4599 | else if ((node->type == XML_ELEMENT_NODE) && |
| pcercuei | 0:03b5121a232e | 4600 | (node->children != NULL)) |
| pcercuei | 0:03b5121a232e | 4601 | result = xmlGetLineNoInternal(node->children, depth + 1); |
| pcercuei | 0:03b5121a232e | 4602 | else if (node->next != NULL) |
| pcercuei | 0:03b5121a232e | 4603 | result = xmlGetLineNoInternal(node->next, depth + 1); |
| pcercuei | 0:03b5121a232e | 4604 | else if (node->prev != NULL) |
| pcercuei | 0:03b5121a232e | 4605 | result = xmlGetLineNoInternal(node->prev, depth + 1); |
| pcercuei | 0:03b5121a232e | 4606 | } |
| pcercuei | 0:03b5121a232e | 4607 | if ((result == -1) || (result == 65535)) |
| pcercuei | 0:03b5121a232e | 4608 | result = (long) node->line; |
| pcercuei | 0:03b5121a232e | 4609 | } else if ((node->prev != NULL) && |
| pcercuei | 0:03b5121a232e | 4610 | ((node->prev->type == XML_ELEMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 4611 | (node->prev->type == XML_TEXT_NODE) || |
| pcercuei | 0:03b5121a232e | 4612 | (node->prev->type == XML_COMMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 4613 | (node->prev->type == XML_PI_NODE))) |
| pcercuei | 0:03b5121a232e | 4614 | result = xmlGetLineNoInternal(node->prev, depth + 1); |
| pcercuei | 0:03b5121a232e | 4615 | else if ((node->parent != NULL) && |
| pcercuei | 0:03b5121a232e | 4616 | (node->parent->type == XML_ELEMENT_NODE)) |
| pcercuei | 0:03b5121a232e | 4617 | result = xmlGetLineNoInternal(node->parent, depth + 1); |
| pcercuei | 0:03b5121a232e | 4618 | |
| pcercuei | 0:03b5121a232e | 4619 | return result; |
| pcercuei | 0:03b5121a232e | 4620 | } |
| pcercuei | 0:03b5121a232e | 4621 | |
| pcercuei | 0:03b5121a232e | 4622 | /** |
| pcercuei | 0:03b5121a232e | 4623 | * xmlGetLineNo: |
| pcercuei | 0:03b5121a232e | 4624 | * @node: valid node |
| pcercuei | 0:03b5121a232e | 4625 | * |
| pcercuei | 0:03b5121a232e | 4626 | * Get line number of @node. |
| pcercuei | 0:03b5121a232e | 4627 | * Try to override the limitation of lines being store in 16 bits ints |
| pcercuei | 0:03b5121a232e | 4628 | * if XML_PARSE_BIG_LINES parser option was used |
| pcercuei | 0:03b5121a232e | 4629 | * |
| pcercuei | 0:03b5121a232e | 4630 | * Returns the line number if successful, -1 otherwise |
| pcercuei | 0:03b5121a232e | 4631 | */ |
| pcercuei | 0:03b5121a232e | 4632 | long |
| pcercuei | 0:03b5121a232e | 4633 | xmlGetLineNo(const xmlNode *node) |
| pcercuei | 0:03b5121a232e | 4634 | { |
| pcercuei | 0:03b5121a232e | 4635 | return(xmlGetLineNoInternal(node, 0)); |
| pcercuei | 0:03b5121a232e | 4636 | } |
| pcercuei | 0:03b5121a232e | 4637 | |
| pcercuei | 0:03b5121a232e | 4638 | #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_DEBUG_ENABLED) |
| pcercuei | 0:03b5121a232e | 4639 | /** |
| pcercuei | 0:03b5121a232e | 4640 | * xmlGetNodePath: |
| pcercuei | 0:03b5121a232e | 4641 | * @node: a node |
| pcercuei | 0:03b5121a232e | 4642 | * |
| pcercuei | 0:03b5121a232e | 4643 | * Build a structure based Path for the given node |
| pcercuei | 0:03b5121a232e | 4644 | * |
| pcercuei | 0:03b5121a232e | 4645 | * Returns the new path or NULL in case of error. The caller must free |
| pcercuei | 0:03b5121a232e | 4646 | * the returned string |
| pcercuei | 0:03b5121a232e | 4647 | */ |
| pcercuei | 0:03b5121a232e | 4648 | xmlChar * |
| pcercuei | 0:03b5121a232e | 4649 | xmlGetNodePath(const xmlNode *node) |
| pcercuei | 0:03b5121a232e | 4650 | { |
| pcercuei | 0:03b5121a232e | 4651 | const xmlNode *cur, *tmp, *next; |
| pcercuei | 0:03b5121a232e | 4652 | xmlChar *buffer = NULL, *temp; |
| pcercuei | 0:03b5121a232e | 4653 | size_t buf_len; |
| pcercuei | 0:03b5121a232e | 4654 | xmlChar *buf; |
| pcercuei | 0:03b5121a232e | 4655 | const char *sep; |
| pcercuei | 0:03b5121a232e | 4656 | const char *name; |
| pcercuei | 0:03b5121a232e | 4657 | char nametemp[100]; |
| pcercuei | 0:03b5121a232e | 4658 | int occur = 0, generic; |
| pcercuei | 0:03b5121a232e | 4659 | |
| pcercuei | 0:03b5121a232e | 4660 | if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) |
| pcercuei | 0:03b5121a232e | 4661 | return (NULL); |
| pcercuei | 0:03b5121a232e | 4662 | |
| pcercuei | 0:03b5121a232e | 4663 | buf_len = 500; |
| pcercuei | 0:03b5121a232e | 4664 | buffer = (xmlChar *) xmlMallocAtomic(buf_len * sizeof(xmlChar)); |
| pcercuei | 0:03b5121a232e | 4665 | if (buffer == NULL) { |
| pcercuei | 0:03b5121a232e | 4666 | xmlTreeErrMemory("getting node path"); |
| pcercuei | 0:03b5121a232e | 4667 | return (NULL); |
| pcercuei | 0:03b5121a232e | 4668 | } |
| pcercuei | 0:03b5121a232e | 4669 | buf = (xmlChar *) xmlMallocAtomic(buf_len * sizeof(xmlChar)); |
| pcercuei | 0:03b5121a232e | 4670 | if (buf == NULL) { |
| pcercuei | 0:03b5121a232e | 4671 | xmlTreeErrMemory("getting node path"); |
| pcercuei | 0:03b5121a232e | 4672 | xmlFree(buffer); |
| pcercuei | 0:03b5121a232e | 4673 | return (NULL); |
| pcercuei | 0:03b5121a232e | 4674 | } |
| pcercuei | 0:03b5121a232e | 4675 | |
| pcercuei | 0:03b5121a232e | 4676 | buffer[0] = 0; |
| pcercuei | 0:03b5121a232e | 4677 | cur = node; |
| pcercuei | 0:03b5121a232e | 4678 | do { |
| pcercuei | 0:03b5121a232e | 4679 | name = ""; |
| pcercuei | 0:03b5121a232e | 4680 | sep = "?"; |
| pcercuei | 0:03b5121a232e | 4681 | occur = 0; |
| pcercuei | 0:03b5121a232e | 4682 | if ((cur->type == XML_DOCUMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 4683 | (cur->type == XML_HTML_DOCUMENT_NODE)) { |
| pcercuei | 0:03b5121a232e | 4684 | if (buffer[0] == '/') |
| pcercuei | 0:03b5121a232e | 4685 | break; |
| pcercuei | 0:03b5121a232e | 4686 | sep = "/"; |
| pcercuei | 0:03b5121a232e | 4687 | next = NULL; |
| pcercuei | 0:03b5121a232e | 4688 | } else if (cur->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 4689 | generic = 0; |
| pcercuei | 0:03b5121a232e | 4690 | sep = "/"; |
| pcercuei | 0:03b5121a232e | 4691 | name = (const char *) cur->name; |
| pcercuei | 0:03b5121a232e | 4692 | if (cur->ns) { |
| pcercuei | 0:03b5121a232e | 4693 | if (cur->ns->prefix != NULL) { |
| pcercuei | 0:03b5121a232e | 4694 | snprintf(nametemp, sizeof(nametemp) - 1, "%s:%s", |
| pcercuei | 0:03b5121a232e | 4695 | (char *)cur->ns->prefix, (char *)cur->name); |
| pcercuei | 0:03b5121a232e | 4696 | nametemp[sizeof(nametemp) - 1] = 0; |
| pcercuei | 0:03b5121a232e | 4697 | name = nametemp; |
| pcercuei | 0:03b5121a232e | 4698 | } else { |
| pcercuei | 0:03b5121a232e | 4699 | /* |
| pcercuei | 0:03b5121a232e | 4700 | * We cannot express named elements in the default |
| pcercuei | 0:03b5121a232e | 4701 | * namespace, so use "*". |
| pcercuei | 0:03b5121a232e | 4702 | */ |
| pcercuei | 0:03b5121a232e | 4703 | generic = 1; |
| pcercuei | 0:03b5121a232e | 4704 | name = "*"; |
| pcercuei | 0:03b5121a232e | 4705 | } |
| pcercuei | 0:03b5121a232e | 4706 | } |
| pcercuei | 0:03b5121a232e | 4707 | next = cur->parent; |
| pcercuei | 0:03b5121a232e | 4708 | |
| pcercuei | 0:03b5121a232e | 4709 | /* |
| pcercuei | 0:03b5121a232e | 4710 | * Thumbler index computation |
| pcercuei | 0:03b5121a232e | 4711 | * TODO: the ocurence test seems bogus for namespaced names |
| pcercuei | 0:03b5121a232e | 4712 | */ |
| pcercuei | 0:03b5121a232e | 4713 | tmp = cur->prev; |
| pcercuei | 0:03b5121a232e | 4714 | while (tmp != NULL) { |
| pcercuei | 0:03b5121a232e | 4715 | if ((tmp->type == XML_ELEMENT_NODE) && |
| pcercuei | 0:03b5121a232e | 4716 | (generic || |
| pcercuei | 0:03b5121a232e | 4717 | (xmlStrEqual(cur->name, tmp->name) && |
| pcercuei | 0:03b5121a232e | 4718 | ((tmp->ns == cur->ns) || |
| pcercuei | 0:03b5121a232e | 4719 | ((tmp->ns != NULL) && (cur->ns != NULL) && |
| pcercuei | 0:03b5121a232e | 4720 | (xmlStrEqual(cur->ns->prefix, tmp->ns->prefix))))))) |
| pcercuei | 0:03b5121a232e | 4721 | occur++; |
| pcercuei | 0:03b5121a232e | 4722 | tmp = tmp->prev; |
| pcercuei | 0:03b5121a232e | 4723 | } |
| pcercuei | 0:03b5121a232e | 4724 | if (occur == 0) { |
| pcercuei | 0:03b5121a232e | 4725 | tmp = cur->next; |
| pcercuei | 0:03b5121a232e | 4726 | while (tmp != NULL && occur == 0) { |
| pcercuei | 0:03b5121a232e | 4727 | if ((tmp->type == XML_ELEMENT_NODE) && |
| pcercuei | 0:03b5121a232e | 4728 | (generic || |
| pcercuei | 0:03b5121a232e | 4729 | (xmlStrEqual(cur->name, tmp->name) && |
| pcercuei | 0:03b5121a232e | 4730 | ((tmp->ns == cur->ns) || |
| pcercuei | 0:03b5121a232e | 4731 | ((tmp->ns != NULL) && (cur->ns != NULL) && |
| pcercuei | 0:03b5121a232e | 4732 | (xmlStrEqual(cur->ns->prefix, tmp->ns->prefix))))))) |
| pcercuei | 0:03b5121a232e | 4733 | occur++; |
| pcercuei | 0:03b5121a232e | 4734 | tmp = tmp->next; |
| pcercuei | 0:03b5121a232e | 4735 | } |
| pcercuei | 0:03b5121a232e | 4736 | if (occur != 0) |
| pcercuei | 0:03b5121a232e | 4737 | occur = 1; |
| pcercuei | 0:03b5121a232e | 4738 | } else |
| pcercuei | 0:03b5121a232e | 4739 | occur++; |
| pcercuei | 0:03b5121a232e | 4740 | } else if (cur->type == XML_COMMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 4741 | sep = "/"; |
| pcercuei | 0:03b5121a232e | 4742 | name = "comment()"; |
| pcercuei | 0:03b5121a232e | 4743 | next = cur->parent; |
| pcercuei | 0:03b5121a232e | 4744 | |
| pcercuei | 0:03b5121a232e | 4745 | /* |
| pcercuei | 0:03b5121a232e | 4746 | * Thumbler index computation |
| pcercuei | 0:03b5121a232e | 4747 | */ |
| pcercuei | 0:03b5121a232e | 4748 | tmp = cur->prev; |
| pcercuei | 0:03b5121a232e | 4749 | while (tmp != NULL) { |
| pcercuei | 0:03b5121a232e | 4750 | if (tmp->type == XML_COMMENT_NODE) |
| pcercuei | 0:03b5121a232e | 4751 | occur++; |
| pcercuei | 0:03b5121a232e | 4752 | tmp = tmp->prev; |
| pcercuei | 0:03b5121a232e | 4753 | } |
| pcercuei | 0:03b5121a232e | 4754 | if (occur == 0) { |
| pcercuei | 0:03b5121a232e | 4755 | tmp = cur->next; |
| pcercuei | 0:03b5121a232e | 4756 | while (tmp != NULL && occur == 0) { |
| pcercuei | 0:03b5121a232e | 4757 | if (tmp->type == XML_COMMENT_NODE) |
| pcercuei | 0:03b5121a232e | 4758 | occur++; |
| pcercuei | 0:03b5121a232e | 4759 | tmp = tmp->next; |
| pcercuei | 0:03b5121a232e | 4760 | } |
| pcercuei | 0:03b5121a232e | 4761 | if (occur != 0) |
| pcercuei | 0:03b5121a232e | 4762 | occur = 1; |
| pcercuei | 0:03b5121a232e | 4763 | } else |
| pcercuei | 0:03b5121a232e | 4764 | occur++; |
| pcercuei | 0:03b5121a232e | 4765 | } else if ((cur->type == XML_TEXT_NODE) || |
| pcercuei | 0:03b5121a232e | 4766 | (cur->type == XML_CDATA_SECTION_NODE)) { |
| pcercuei | 0:03b5121a232e | 4767 | sep = "/"; |
| pcercuei | 0:03b5121a232e | 4768 | name = "text()"; |
| pcercuei | 0:03b5121a232e | 4769 | next = cur->parent; |
| pcercuei | 0:03b5121a232e | 4770 | |
| pcercuei | 0:03b5121a232e | 4771 | /* |
| pcercuei | 0:03b5121a232e | 4772 | * Thumbler index computation |
| pcercuei | 0:03b5121a232e | 4773 | */ |
| pcercuei | 0:03b5121a232e | 4774 | tmp = cur->prev; |
| pcercuei | 0:03b5121a232e | 4775 | while (tmp != NULL) { |
| pcercuei | 0:03b5121a232e | 4776 | if ((tmp->type == XML_TEXT_NODE) || |
| pcercuei | 0:03b5121a232e | 4777 | (tmp->type == XML_CDATA_SECTION_NODE)) |
| pcercuei | 0:03b5121a232e | 4778 | occur++; |
| pcercuei | 0:03b5121a232e | 4779 | tmp = tmp->prev; |
| pcercuei | 0:03b5121a232e | 4780 | } |
| pcercuei | 0:03b5121a232e | 4781 | /* |
| pcercuei | 0:03b5121a232e | 4782 | * Evaluate if this is the only text- or CDATA-section-node; |
| pcercuei | 0:03b5121a232e | 4783 | * if yes, then we'll get "text()", otherwise "text()[1]". |
| pcercuei | 0:03b5121a232e | 4784 | */ |
| pcercuei | 0:03b5121a232e | 4785 | if (occur == 0) { |
| pcercuei | 0:03b5121a232e | 4786 | tmp = cur->next; |
| pcercuei | 0:03b5121a232e | 4787 | while (tmp != NULL) { |
| pcercuei | 0:03b5121a232e | 4788 | if ((tmp->type == XML_TEXT_NODE) || |
| pcercuei | 0:03b5121a232e | 4789 | (tmp->type == XML_CDATA_SECTION_NODE)) |
| pcercuei | 0:03b5121a232e | 4790 | { |
| pcercuei | 0:03b5121a232e | 4791 | occur = 1; |
| pcercuei | 0:03b5121a232e | 4792 | break; |
| pcercuei | 0:03b5121a232e | 4793 | } |
| pcercuei | 0:03b5121a232e | 4794 | tmp = tmp->next; |
| pcercuei | 0:03b5121a232e | 4795 | } |
| pcercuei | 0:03b5121a232e | 4796 | } else |
| pcercuei | 0:03b5121a232e | 4797 | occur++; |
| pcercuei | 0:03b5121a232e | 4798 | } else if (cur->type == XML_PI_NODE) { |
| pcercuei | 0:03b5121a232e | 4799 | sep = "/"; |
| pcercuei | 0:03b5121a232e | 4800 | snprintf(nametemp, sizeof(nametemp) - 1, |
| pcercuei | 0:03b5121a232e | 4801 | "processing-instruction('%s')", (char *)cur->name); |
| pcercuei | 0:03b5121a232e | 4802 | nametemp[sizeof(nametemp) - 1] = 0; |
| pcercuei | 0:03b5121a232e | 4803 | name = nametemp; |
| pcercuei | 0:03b5121a232e | 4804 | |
| pcercuei | 0:03b5121a232e | 4805 | next = cur->parent; |
| pcercuei | 0:03b5121a232e | 4806 | |
| pcercuei | 0:03b5121a232e | 4807 | /* |
| pcercuei | 0:03b5121a232e | 4808 | * Thumbler index computation |
| pcercuei | 0:03b5121a232e | 4809 | */ |
| pcercuei | 0:03b5121a232e | 4810 | tmp = cur->prev; |
| pcercuei | 0:03b5121a232e | 4811 | while (tmp != NULL) { |
| pcercuei | 0:03b5121a232e | 4812 | if ((tmp->type == XML_PI_NODE) && |
| pcercuei | 0:03b5121a232e | 4813 | (xmlStrEqual(cur->name, tmp->name))) |
| pcercuei | 0:03b5121a232e | 4814 | occur++; |
| pcercuei | 0:03b5121a232e | 4815 | tmp = tmp->prev; |
| pcercuei | 0:03b5121a232e | 4816 | } |
| pcercuei | 0:03b5121a232e | 4817 | if (occur == 0) { |
| pcercuei | 0:03b5121a232e | 4818 | tmp = cur->next; |
| pcercuei | 0:03b5121a232e | 4819 | while (tmp != NULL && occur == 0) { |
| pcercuei | 0:03b5121a232e | 4820 | if ((tmp->type == XML_PI_NODE) && |
| pcercuei | 0:03b5121a232e | 4821 | (xmlStrEqual(cur->name, tmp->name))) |
| pcercuei | 0:03b5121a232e | 4822 | occur++; |
| pcercuei | 0:03b5121a232e | 4823 | tmp = tmp->next; |
| pcercuei | 0:03b5121a232e | 4824 | } |
| pcercuei | 0:03b5121a232e | 4825 | if (occur != 0) |
| pcercuei | 0:03b5121a232e | 4826 | occur = 1; |
| pcercuei | 0:03b5121a232e | 4827 | } else |
| pcercuei | 0:03b5121a232e | 4828 | occur++; |
| pcercuei | 0:03b5121a232e | 4829 | |
| pcercuei | 0:03b5121a232e | 4830 | } else if (cur->type == XML_ATTRIBUTE_NODE) { |
| pcercuei | 0:03b5121a232e | 4831 | sep = "/@"; |
| pcercuei | 0:03b5121a232e | 4832 | name = (const char *) (((xmlAttrPtr) cur)->name); |
| pcercuei | 0:03b5121a232e | 4833 | if (cur->ns) { |
| pcercuei | 0:03b5121a232e | 4834 | if (cur->ns->prefix != NULL) |
| pcercuei | 0:03b5121a232e | 4835 | snprintf(nametemp, sizeof(nametemp) - 1, "%s:%s", |
| pcercuei | 0:03b5121a232e | 4836 | (char *)cur->ns->prefix, (char *)cur->name); |
| pcercuei | 0:03b5121a232e | 4837 | else |
| pcercuei | 0:03b5121a232e | 4838 | snprintf(nametemp, sizeof(nametemp) - 1, "%s", |
| pcercuei | 0:03b5121a232e | 4839 | (char *)cur->name); |
| pcercuei | 0:03b5121a232e | 4840 | nametemp[sizeof(nametemp) - 1] = 0; |
| pcercuei | 0:03b5121a232e | 4841 | name = nametemp; |
| pcercuei | 0:03b5121a232e | 4842 | } |
| pcercuei | 0:03b5121a232e | 4843 | next = ((xmlAttrPtr) cur)->parent; |
| pcercuei | 0:03b5121a232e | 4844 | } else { |
| pcercuei | 0:03b5121a232e | 4845 | next = cur->parent; |
| pcercuei | 0:03b5121a232e | 4846 | } |
| pcercuei | 0:03b5121a232e | 4847 | |
| pcercuei | 0:03b5121a232e | 4848 | /* |
| pcercuei | 0:03b5121a232e | 4849 | * Make sure there is enough room |
| pcercuei | 0:03b5121a232e | 4850 | */ |
| pcercuei | 0:03b5121a232e | 4851 | if (xmlStrlen(buffer) + sizeof(nametemp) + 20 > buf_len) { |
| pcercuei | 0:03b5121a232e | 4852 | buf_len = |
| pcercuei | 0:03b5121a232e | 4853 | 2 * buf_len + xmlStrlen(buffer) + sizeof(nametemp) + 20; |
| pcercuei | 0:03b5121a232e | 4854 | temp = (xmlChar *) xmlRealloc(buffer, buf_len); |
| pcercuei | 0:03b5121a232e | 4855 | if (temp == NULL) { |
| pcercuei | 0:03b5121a232e | 4856 | xmlTreeErrMemory("getting node path"); |
| pcercuei | 0:03b5121a232e | 4857 | xmlFree(buf); |
| pcercuei | 0:03b5121a232e | 4858 | xmlFree(buffer); |
| pcercuei | 0:03b5121a232e | 4859 | return (NULL); |
| pcercuei | 0:03b5121a232e | 4860 | } |
| pcercuei | 0:03b5121a232e | 4861 | buffer = temp; |
| pcercuei | 0:03b5121a232e | 4862 | temp = (xmlChar *) xmlRealloc(buf, buf_len); |
| pcercuei | 0:03b5121a232e | 4863 | if (temp == NULL) { |
| pcercuei | 0:03b5121a232e | 4864 | xmlTreeErrMemory("getting node path"); |
| pcercuei | 0:03b5121a232e | 4865 | xmlFree(buf); |
| pcercuei | 0:03b5121a232e | 4866 | xmlFree(buffer); |
| pcercuei | 0:03b5121a232e | 4867 | return (NULL); |
| pcercuei | 0:03b5121a232e | 4868 | } |
| pcercuei | 0:03b5121a232e | 4869 | buf = temp; |
| pcercuei | 0:03b5121a232e | 4870 | } |
| pcercuei | 0:03b5121a232e | 4871 | if (occur == 0) |
| pcercuei | 0:03b5121a232e | 4872 | snprintf((char *) buf, buf_len, "%s%s%s", |
| pcercuei | 0:03b5121a232e | 4873 | sep, name, (char *) buffer); |
| pcercuei | 0:03b5121a232e | 4874 | else |
| pcercuei | 0:03b5121a232e | 4875 | snprintf((char *) buf, buf_len, "%s%s[%d]%s", |
| pcercuei | 0:03b5121a232e | 4876 | sep, name, occur, (char *) buffer); |
| pcercuei | 0:03b5121a232e | 4877 | snprintf((char *) buffer, buf_len, "%s", (char *)buf); |
| pcercuei | 0:03b5121a232e | 4878 | cur = next; |
| pcercuei | 0:03b5121a232e | 4879 | } while (cur != NULL); |
| pcercuei | 0:03b5121a232e | 4880 | xmlFree(buf); |
| pcercuei | 0:03b5121a232e | 4881 | return (buffer); |
| pcercuei | 0:03b5121a232e | 4882 | } |
| pcercuei | 0:03b5121a232e | 4883 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 4884 | |
| pcercuei | 0:03b5121a232e | 4885 | /** |
| pcercuei | 0:03b5121a232e | 4886 | * xmlDocGetRootElement: |
| pcercuei | 0:03b5121a232e | 4887 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 4888 | * |
| pcercuei | 0:03b5121a232e | 4889 | * Get the root element of the document (doc->children is a list |
| pcercuei | 0:03b5121a232e | 4890 | * containing possibly comments, PIs, etc ...). |
| pcercuei | 0:03b5121a232e | 4891 | * |
| pcercuei | 0:03b5121a232e | 4892 | * Returns the #xmlNodePtr for the root or NULL |
| pcercuei | 0:03b5121a232e | 4893 | */ |
| pcercuei | 0:03b5121a232e | 4894 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 4895 | xmlDocGetRootElement(const xmlDoc *doc) { |
| pcercuei | 0:03b5121a232e | 4896 | xmlNodePtr ret; |
| pcercuei | 0:03b5121a232e | 4897 | |
| pcercuei | 0:03b5121a232e | 4898 | if (doc == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 4899 | ret = doc->children; |
| pcercuei | 0:03b5121a232e | 4900 | while (ret != NULL) { |
| pcercuei | 0:03b5121a232e | 4901 | if (ret->type == XML_ELEMENT_NODE) |
| pcercuei | 0:03b5121a232e | 4902 | return(ret); |
| pcercuei | 0:03b5121a232e | 4903 | ret = ret->next; |
| pcercuei | 0:03b5121a232e | 4904 | } |
| pcercuei | 0:03b5121a232e | 4905 | return(ret); |
| pcercuei | 0:03b5121a232e | 4906 | } |
| pcercuei | 0:03b5121a232e | 4907 | |
| pcercuei | 0:03b5121a232e | 4908 | #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_WRITER_ENABLED) |
| pcercuei | 0:03b5121a232e | 4909 | /** |
| pcercuei | 0:03b5121a232e | 4910 | * xmlDocSetRootElement: |
| pcercuei | 0:03b5121a232e | 4911 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 4912 | * @root: the new document root element, if root is NULL no action is taken, |
| pcercuei | 0:03b5121a232e | 4913 | * to remove a node from a document use xmlUnlinkNode(root) instead. |
| pcercuei | 0:03b5121a232e | 4914 | * |
| pcercuei | 0:03b5121a232e | 4915 | * Set the root element of the document (doc->children is a list |
| pcercuei | 0:03b5121a232e | 4916 | * containing possibly comments, PIs, etc ...). |
| pcercuei | 0:03b5121a232e | 4917 | * |
| pcercuei | 0:03b5121a232e | 4918 | * Returns the old root element if any was found, NULL if root was NULL |
| pcercuei | 0:03b5121a232e | 4919 | */ |
| pcercuei | 0:03b5121a232e | 4920 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 4921 | xmlDocSetRootElement(xmlDocPtr doc, xmlNodePtr root) { |
| pcercuei | 0:03b5121a232e | 4922 | xmlNodePtr old = NULL; |
| pcercuei | 0:03b5121a232e | 4923 | |
| pcercuei | 0:03b5121a232e | 4924 | if (doc == NULL) return(NULL); |
| pcercuei | 0:03b5121a232e | 4925 | if ((root == NULL) || (root->type == XML_NAMESPACE_DECL)) |
| pcercuei | 0:03b5121a232e | 4926 | return(NULL); |
| pcercuei | 0:03b5121a232e | 4927 | xmlUnlinkNode(root); |
| pcercuei | 0:03b5121a232e | 4928 | xmlSetTreeDoc(root, doc); |
| pcercuei | 0:03b5121a232e | 4929 | root->parent = (xmlNodePtr) doc; |
| pcercuei | 0:03b5121a232e | 4930 | old = doc->children; |
| pcercuei | 0:03b5121a232e | 4931 | while (old != NULL) { |
| pcercuei | 0:03b5121a232e | 4932 | if (old->type == XML_ELEMENT_NODE) |
| pcercuei | 0:03b5121a232e | 4933 | break; |
| pcercuei | 0:03b5121a232e | 4934 | old = old->next; |
| pcercuei | 0:03b5121a232e | 4935 | } |
| pcercuei | 0:03b5121a232e | 4936 | if (old == NULL) { |
| pcercuei | 0:03b5121a232e | 4937 | if (doc->children == NULL) { |
| pcercuei | 0:03b5121a232e | 4938 | doc->children = root; |
| pcercuei | 0:03b5121a232e | 4939 | doc->last = root; |
| pcercuei | 0:03b5121a232e | 4940 | } else { |
| pcercuei | 0:03b5121a232e | 4941 | xmlAddSibling(doc->children, root); |
| pcercuei | 0:03b5121a232e | 4942 | } |
| pcercuei | 0:03b5121a232e | 4943 | } else { |
| pcercuei | 0:03b5121a232e | 4944 | xmlReplaceNode(old, root); |
| pcercuei | 0:03b5121a232e | 4945 | } |
| pcercuei | 0:03b5121a232e | 4946 | return(old); |
| pcercuei | 0:03b5121a232e | 4947 | } |
| pcercuei | 0:03b5121a232e | 4948 | #endif |
| pcercuei | 0:03b5121a232e | 4949 | |
| pcercuei | 0:03b5121a232e | 4950 | #if defined(LIBXML_TREE_ENABLED) |
| pcercuei | 0:03b5121a232e | 4951 | /** |
| pcercuei | 0:03b5121a232e | 4952 | * xmlNodeSetLang: |
| pcercuei | 0:03b5121a232e | 4953 | * @cur: the node being changed |
| pcercuei | 0:03b5121a232e | 4954 | * @lang: the language description |
| pcercuei | 0:03b5121a232e | 4955 | * |
| pcercuei | 0:03b5121a232e | 4956 | * Set the language of a node, i.e. the values of the xml:lang |
| pcercuei | 0:03b5121a232e | 4957 | * attribute. |
| pcercuei | 0:03b5121a232e | 4958 | */ |
| pcercuei | 0:03b5121a232e | 4959 | void |
| pcercuei | 0:03b5121a232e | 4960 | xmlNodeSetLang(xmlNodePtr cur, const xmlChar *lang) { |
| pcercuei | 0:03b5121a232e | 4961 | xmlNsPtr ns; |
| pcercuei | 0:03b5121a232e | 4962 | |
| pcercuei | 0:03b5121a232e | 4963 | if (cur == NULL) return; |
| pcercuei | 0:03b5121a232e | 4964 | switch(cur->type) { |
| pcercuei | 0:03b5121a232e | 4965 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 4966 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 4967 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 4968 | case XML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 4969 | case XML_DOCUMENT_TYPE_NODE: |
| pcercuei | 0:03b5121a232e | 4970 | case XML_DOCUMENT_FRAG_NODE: |
| pcercuei | 0:03b5121a232e | 4971 | case XML_NOTATION_NODE: |
| pcercuei | 0:03b5121a232e | 4972 | case XML_HTML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 4973 | case XML_DTD_NODE: |
| pcercuei | 0:03b5121a232e | 4974 | case XML_ELEMENT_DECL: |
| pcercuei | 0:03b5121a232e | 4975 | case XML_ATTRIBUTE_DECL: |
| pcercuei | 0:03b5121a232e | 4976 | case XML_ENTITY_DECL: |
| pcercuei | 0:03b5121a232e | 4977 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 4978 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 4979 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 4980 | case XML_NAMESPACE_DECL: |
| pcercuei | 0:03b5121a232e | 4981 | #ifdef LIBXML_DOCB_ENABLED |
| pcercuei | 0:03b5121a232e | 4982 | case XML_DOCB_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 4983 | #endif |
| pcercuei | 0:03b5121a232e | 4984 | case XML_XINCLUDE_START: |
| pcercuei | 0:03b5121a232e | 4985 | case XML_XINCLUDE_END: |
| pcercuei | 0:03b5121a232e | 4986 | return; |
| pcercuei | 0:03b5121a232e | 4987 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 4988 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 4989 | break; |
| pcercuei | 0:03b5121a232e | 4990 | } |
| pcercuei | 0:03b5121a232e | 4991 | ns = xmlSearchNsByHref(cur->doc, cur, XML_XML_NAMESPACE); |
| pcercuei | 0:03b5121a232e | 4992 | if (ns == NULL) |
| pcercuei | 0:03b5121a232e | 4993 | return; |
| pcercuei | 0:03b5121a232e | 4994 | xmlSetNsProp(cur, ns, BAD_CAST "lang", lang); |
| pcercuei | 0:03b5121a232e | 4995 | } |
| pcercuei | 0:03b5121a232e | 4996 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 4997 | |
| pcercuei | 0:03b5121a232e | 4998 | /** |
| pcercuei | 0:03b5121a232e | 4999 | * xmlNodeGetLang: |
| pcercuei | 0:03b5121a232e | 5000 | * @cur: the node being checked |
| pcercuei | 0:03b5121a232e | 5001 | * |
| pcercuei | 0:03b5121a232e | 5002 | * Searches the language of a node, i.e. the values of the xml:lang |
| pcercuei | 0:03b5121a232e | 5003 | * attribute or the one carried by the nearest ancestor. |
| pcercuei | 0:03b5121a232e | 5004 | * |
| pcercuei | 0:03b5121a232e | 5005 | * Returns a pointer to the lang value, or NULL if not found |
| pcercuei | 0:03b5121a232e | 5006 | * It's up to the caller to free the memory with xmlFree(). |
| pcercuei | 0:03b5121a232e | 5007 | */ |
| pcercuei | 0:03b5121a232e | 5008 | xmlChar * |
| pcercuei | 0:03b5121a232e | 5009 | xmlNodeGetLang(const xmlNode *cur) { |
| pcercuei | 0:03b5121a232e | 5010 | xmlChar *lang; |
| pcercuei | 0:03b5121a232e | 5011 | |
| pcercuei | 0:03b5121a232e | 5012 | if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) |
| pcercuei | 0:03b5121a232e | 5013 | return(NULL); |
| pcercuei | 0:03b5121a232e | 5014 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 5015 | lang = xmlGetNsProp(cur, BAD_CAST "lang", XML_XML_NAMESPACE); |
| pcercuei | 0:03b5121a232e | 5016 | if (lang != NULL) |
| pcercuei | 0:03b5121a232e | 5017 | return(lang); |
| pcercuei | 0:03b5121a232e | 5018 | cur = cur->parent; |
| pcercuei | 0:03b5121a232e | 5019 | } |
| pcercuei | 0:03b5121a232e | 5020 | return(NULL); |
| pcercuei | 0:03b5121a232e | 5021 | } |
| pcercuei | 0:03b5121a232e | 5022 | |
| pcercuei | 0:03b5121a232e | 5023 | |
| pcercuei | 0:03b5121a232e | 5024 | #ifdef LIBXML_TREE_ENABLED |
| pcercuei | 0:03b5121a232e | 5025 | /** |
| pcercuei | 0:03b5121a232e | 5026 | * xmlNodeSetSpacePreserve: |
| pcercuei | 0:03b5121a232e | 5027 | * @cur: the node being changed |
| pcercuei | 0:03b5121a232e | 5028 | * @val: the xml:space value ("0": default, 1: "preserve") |
| pcercuei | 0:03b5121a232e | 5029 | * |
| pcercuei | 0:03b5121a232e | 5030 | * Set (or reset) the space preserving behaviour of a node, i.e. the |
| pcercuei | 0:03b5121a232e | 5031 | * value of the xml:space attribute. |
| pcercuei | 0:03b5121a232e | 5032 | */ |
| pcercuei | 0:03b5121a232e | 5033 | void |
| pcercuei | 0:03b5121a232e | 5034 | xmlNodeSetSpacePreserve(xmlNodePtr cur, int val) { |
| pcercuei | 0:03b5121a232e | 5035 | xmlNsPtr ns; |
| pcercuei | 0:03b5121a232e | 5036 | |
| pcercuei | 0:03b5121a232e | 5037 | if (cur == NULL) return; |
| pcercuei | 0:03b5121a232e | 5038 | switch(cur->type) { |
| pcercuei | 0:03b5121a232e | 5039 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 5040 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 5041 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5042 | case XML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5043 | case XML_DOCUMENT_TYPE_NODE: |
| pcercuei | 0:03b5121a232e | 5044 | case XML_DOCUMENT_FRAG_NODE: |
| pcercuei | 0:03b5121a232e | 5045 | case XML_NOTATION_NODE: |
| pcercuei | 0:03b5121a232e | 5046 | case XML_HTML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5047 | case XML_DTD_NODE: |
| pcercuei | 0:03b5121a232e | 5048 | case XML_ELEMENT_DECL: |
| pcercuei | 0:03b5121a232e | 5049 | case XML_ATTRIBUTE_DECL: |
| pcercuei | 0:03b5121a232e | 5050 | case XML_ENTITY_DECL: |
| pcercuei | 0:03b5121a232e | 5051 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 5052 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 5053 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 5054 | case XML_NAMESPACE_DECL: |
| pcercuei | 0:03b5121a232e | 5055 | case XML_XINCLUDE_START: |
| pcercuei | 0:03b5121a232e | 5056 | case XML_XINCLUDE_END: |
| pcercuei | 0:03b5121a232e | 5057 | #ifdef LIBXML_DOCB_ENABLED |
| pcercuei | 0:03b5121a232e | 5058 | case XML_DOCB_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5059 | #endif |
| pcercuei | 0:03b5121a232e | 5060 | return; |
| pcercuei | 0:03b5121a232e | 5061 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5062 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 5063 | break; |
| pcercuei | 0:03b5121a232e | 5064 | } |
| pcercuei | 0:03b5121a232e | 5065 | ns = xmlSearchNsByHref(cur->doc, cur, XML_XML_NAMESPACE); |
| pcercuei | 0:03b5121a232e | 5066 | if (ns == NULL) |
| pcercuei | 0:03b5121a232e | 5067 | return; |
| pcercuei | 0:03b5121a232e | 5068 | switch (val) { |
| pcercuei | 0:03b5121a232e | 5069 | case 0: |
| pcercuei | 0:03b5121a232e | 5070 | xmlSetNsProp(cur, ns, BAD_CAST "space", BAD_CAST "default"); |
| pcercuei | 0:03b5121a232e | 5071 | break; |
| pcercuei | 0:03b5121a232e | 5072 | case 1: |
| pcercuei | 0:03b5121a232e | 5073 | xmlSetNsProp(cur, ns, BAD_CAST "space", BAD_CAST "preserve"); |
| pcercuei | 0:03b5121a232e | 5074 | break; |
| pcercuei | 0:03b5121a232e | 5075 | } |
| pcercuei | 0:03b5121a232e | 5076 | } |
| pcercuei | 0:03b5121a232e | 5077 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 5078 | |
| pcercuei | 0:03b5121a232e | 5079 | /** |
| pcercuei | 0:03b5121a232e | 5080 | * xmlNodeGetSpacePreserve: |
| pcercuei | 0:03b5121a232e | 5081 | * @cur: the node being checked |
| pcercuei | 0:03b5121a232e | 5082 | * |
| pcercuei | 0:03b5121a232e | 5083 | * Searches the space preserving behaviour of a node, i.e. the values |
| pcercuei | 0:03b5121a232e | 5084 | * of the xml:space attribute or the one carried by the nearest |
| pcercuei | 0:03b5121a232e | 5085 | * ancestor. |
| pcercuei | 0:03b5121a232e | 5086 | * |
| pcercuei | 0:03b5121a232e | 5087 | * Returns -1 if xml:space is not inherited, 0 if "default", 1 if "preserve" |
| pcercuei | 0:03b5121a232e | 5088 | */ |
| pcercuei | 0:03b5121a232e | 5089 | int |
| pcercuei | 0:03b5121a232e | 5090 | xmlNodeGetSpacePreserve(const xmlNode *cur) { |
| pcercuei | 0:03b5121a232e | 5091 | xmlChar *space; |
| pcercuei | 0:03b5121a232e | 5092 | |
| pcercuei | 0:03b5121a232e | 5093 | if ((cur == NULL) || (cur->type != XML_ELEMENT_NODE)) |
| pcercuei | 0:03b5121a232e | 5094 | return(-1); |
| pcercuei | 0:03b5121a232e | 5095 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 5096 | space = xmlGetNsProp(cur, BAD_CAST "space", XML_XML_NAMESPACE); |
| pcercuei | 0:03b5121a232e | 5097 | if (space != NULL) { |
| pcercuei | 0:03b5121a232e | 5098 | if (xmlStrEqual(space, BAD_CAST "preserve")) { |
| pcercuei | 0:03b5121a232e | 5099 | xmlFree(space); |
| pcercuei | 0:03b5121a232e | 5100 | return(1); |
| pcercuei | 0:03b5121a232e | 5101 | } |
| pcercuei | 0:03b5121a232e | 5102 | if (xmlStrEqual(space, BAD_CAST "default")) { |
| pcercuei | 0:03b5121a232e | 5103 | xmlFree(space); |
| pcercuei | 0:03b5121a232e | 5104 | return(0); |
| pcercuei | 0:03b5121a232e | 5105 | } |
| pcercuei | 0:03b5121a232e | 5106 | xmlFree(space); |
| pcercuei | 0:03b5121a232e | 5107 | } |
| pcercuei | 0:03b5121a232e | 5108 | cur = cur->parent; |
| pcercuei | 0:03b5121a232e | 5109 | } |
| pcercuei | 0:03b5121a232e | 5110 | return(-1); |
| pcercuei | 0:03b5121a232e | 5111 | } |
| pcercuei | 0:03b5121a232e | 5112 | |
| pcercuei | 0:03b5121a232e | 5113 | #ifdef LIBXML_TREE_ENABLED |
| pcercuei | 0:03b5121a232e | 5114 | /** |
| pcercuei | 0:03b5121a232e | 5115 | * xmlNodeSetName: |
| pcercuei | 0:03b5121a232e | 5116 | * @cur: the node being changed |
| pcercuei | 0:03b5121a232e | 5117 | * @name: the new tag name |
| pcercuei | 0:03b5121a232e | 5118 | * |
| pcercuei | 0:03b5121a232e | 5119 | * Set (or reset) the name of a node. |
| pcercuei | 0:03b5121a232e | 5120 | */ |
| pcercuei | 0:03b5121a232e | 5121 | void |
| pcercuei | 0:03b5121a232e | 5122 | xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) { |
| pcercuei | 0:03b5121a232e | 5123 | xmlDocPtr doc; |
| pcercuei | 0:03b5121a232e | 5124 | xmlDictPtr dict; |
| pcercuei | 0:03b5121a232e | 5125 | const xmlChar *freeme = NULL; |
| pcercuei | 0:03b5121a232e | 5126 | |
| pcercuei | 0:03b5121a232e | 5127 | if (cur == NULL) return; |
| pcercuei | 0:03b5121a232e | 5128 | if (name == NULL) return; |
| pcercuei | 0:03b5121a232e | 5129 | switch(cur->type) { |
| pcercuei | 0:03b5121a232e | 5130 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 5131 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 5132 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5133 | case XML_DOCUMENT_TYPE_NODE: |
| pcercuei | 0:03b5121a232e | 5134 | case XML_DOCUMENT_FRAG_NODE: |
| pcercuei | 0:03b5121a232e | 5135 | case XML_NOTATION_NODE: |
| pcercuei | 0:03b5121a232e | 5136 | case XML_HTML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5137 | case XML_NAMESPACE_DECL: |
| pcercuei | 0:03b5121a232e | 5138 | case XML_XINCLUDE_START: |
| pcercuei | 0:03b5121a232e | 5139 | case XML_XINCLUDE_END: |
| pcercuei | 0:03b5121a232e | 5140 | #ifdef LIBXML_DOCB_ENABLED |
| pcercuei | 0:03b5121a232e | 5141 | case XML_DOCB_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5142 | #endif |
| pcercuei | 0:03b5121a232e | 5143 | return; |
| pcercuei | 0:03b5121a232e | 5144 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5145 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 5146 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 5147 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 5148 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 5149 | case XML_DTD_NODE: |
| pcercuei | 0:03b5121a232e | 5150 | case XML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5151 | case XML_ELEMENT_DECL: |
| pcercuei | 0:03b5121a232e | 5152 | case XML_ATTRIBUTE_DECL: |
| pcercuei | 0:03b5121a232e | 5153 | case XML_ENTITY_DECL: |
| pcercuei | 0:03b5121a232e | 5154 | break; |
| pcercuei | 0:03b5121a232e | 5155 | } |
| pcercuei | 0:03b5121a232e | 5156 | doc = cur->doc; |
| pcercuei | 0:03b5121a232e | 5157 | if (doc != NULL) |
| pcercuei | 0:03b5121a232e | 5158 | dict = doc->dict; |
| pcercuei | 0:03b5121a232e | 5159 | else |
| pcercuei | 0:03b5121a232e | 5160 | dict = NULL; |
| pcercuei | 0:03b5121a232e | 5161 | if (dict != NULL) { |
| pcercuei | 0:03b5121a232e | 5162 | if ((cur->name != NULL) && (!xmlDictOwns(dict, cur->name))) |
| pcercuei | 0:03b5121a232e | 5163 | freeme = cur->name; |
| pcercuei | 0:03b5121a232e | 5164 | cur->name = xmlDictLookup(dict, name, -1); |
| pcercuei | 0:03b5121a232e | 5165 | } else { |
| pcercuei | 0:03b5121a232e | 5166 | if (cur->name != NULL) |
| pcercuei | 0:03b5121a232e | 5167 | freeme = cur->name; |
| pcercuei | 0:03b5121a232e | 5168 | cur->name = xmlStrdup(name); |
| pcercuei | 0:03b5121a232e | 5169 | } |
| pcercuei | 0:03b5121a232e | 5170 | |
| pcercuei | 0:03b5121a232e | 5171 | if (freeme) |
| pcercuei | 0:03b5121a232e | 5172 | xmlFree((xmlChar *) freeme); |
| pcercuei | 0:03b5121a232e | 5173 | } |
| pcercuei | 0:03b5121a232e | 5174 | #endif |
| pcercuei | 0:03b5121a232e | 5175 | |
| pcercuei | 0:03b5121a232e | 5176 | #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED) |
| pcercuei | 0:03b5121a232e | 5177 | /** |
| pcercuei | 0:03b5121a232e | 5178 | * xmlNodeSetBase: |
| pcercuei | 0:03b5121a232e | 5179 | * @cur: the node being changed |
| pcercuei | 0:03b5121a232e | 5180 | * @uri: the new base URI |
| pcercuei | 0:03b5121a232e | 5181 | * |
| pcercuei | 0:03b5121a232e | 5182 | * Set (or reset) the base URI of a node, i.e. the value of the |
| pcercuei | 0:03b5121a232e | 5183 | * xml:base attribute. |
| pcercuei | 0:03b5121a232e | 5184 | */ |
| pcercuei | 0:03b5121a232e | 5185 | void |
| pcercuei | 0:03b5121a232e | 5186 | xmlNodeSetBase(xmlNodePtr cur, const xmlChar* uri) { |
| pcercuei | 0:03b5121a232e | 5187 | xmlNsPtr ns; |
| pcercuei | 0:03b5121a232e | 5188 | xmlChar* fixed; |
| pcercuei | 0:03b5121a232e | 5189 | |
| pcercuei | 0:03b5121a232e | 5190 | if (cur == NULL) return; |
| pcercuei | 0:03b5121a232e | 5191 | switch(cur->type) { |
| pcercuei | 0:03b5121a232e | 5192 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 5193 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 5194 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5195 | case XML_DOCUMENT_TYPE_NODE: |
| pcercuei | 0:03b5121a232e | 5196 | case XML_DOCUMENT_FRAG_NODE: |
| pcercuei | 0:03b5121a232e | 5197 | case XML_NOTATION_NODE: |
| pcercuei | 0:03b5121a232e | 5198 | case XML_DTD_NODE: |
| pcercuei | 0:03b5121a232e | 5199 | case XML_ELEMENT_DECL: |
| pcercuei | 0:03b5121a232e | 5200 | case XML_ATTRIBUTE_DECL: |
| pcercuei | 0:03b5121a232e | 5201 | case XML_ENTITY_DECL: |
| pcercuei | 0:03b5121a232e | 5202 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 5203 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 5204 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 5205 | case XML_NAMESPACE_DECL: |
| pcercuei | 0:03b5121a232e | 5206 | case XML_XINCLUDE_START: |
| pcercuei | 0:03b5121a232e | 5207 | case XML_XINCLUDE_END: |
| pcercuei | 0:03b5121a232e | 5208 | return; |
| pcercuei | 0:03b5121a232e | 5209 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5210 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 5211 | break; |
| pcercuei | 0:03b5121a232e | 5212 | case XML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5213 | #ifdef LIBXML_DOCB_ENABLED |
| pcercuei | 0:03b5121a232e | 5214 | case XML_DOCB_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5215 | #endif |
| pcercuei | 0:03b5121a232e | 5216 | case XML_HTML_DOCUMENT_NODE: { |
| pcercuei | 0:03b5121a232e | 5217 | xmlDocPtr doc = (xmlDocPtr) cur; |
| pcercuei | 0:03b5121a232e | 5218 | |
| pcercuei | 0:03b5121a232e | 5219 | if (doc->URL != NULL) |
| pcercuei | 0:03b5121a232e | 5220 | xmlFree((xmlChar *) doc->URL); |
| pcercuei | 0:03b5121a232e | 5221 | if (uri == NULL) |
| pcercuei | 0:03b5121a232e | 5222 | doc->URL = NULL; |
| pcercuei | 0:03b5121a232e | 5223 | else |
| pcercuei | 0:03b5121a232e | 5224 | doc->URL = xmlPathToURI(uri); |
| pcercuei | 0:03b5121a232e | 5225 | return; |
| pcercuei | 0:03b5121a232e | 5226 | } |
| pcercuei | 0:03b5121a232e | 5227 | } |
| pcercuei | 0:03b5121a232e | 5228 | |
| pcercuei | 0:03b5121a232e | 5229 | ns = xmlSearchNsByHref(cur->doc, cur, XML_XML_NAMESPACE); |
| pcercuei | 0:03b5121a232e | 5230 | if (ns == NULL) |
| pcercuei | 0:03b5121a232e | 5231 | return; |
| pcercuei | 0:03b5121a232e | 5232 | fixed = xmlPathToURI(uri); |
| pcercuei | 0:03b5121a232e | 5233 | if (fixed != NULL) { |
| pcercuei | 0:03b5121a232e | 5234 | xmlSetNsProp(cur, ns, BAD_CAST "base", fixed); |
| pcercuei | 0:03b5121a232e | 5235 | xmlFree(fixed); |
| pcercuei | 0:03b5121a232e | 5236 | } else { |
| pcercuei | 0:03b5121a232e | 5237 | xmlSetNsProp(cur, ns, BAD_CAST "base", uri); |
| pcercuei | 0:03b5121a232e | 5238 | } |
| pcercuei | 0:03b5121a232e | 5239 | } |
| pcercuei | 0:03b5121a232e | 5240 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 5241 | |
| pcercuei | 0:03b5121a232e | 5242 | /** |
| pcercuei | 0:03b5121a232e | 5243 | * xmlNodeGetBase: |
| pcercuei | 0:03b5121a232e | 5244 | * @doc: the document the node pertains to |
| pcercuei | 0:03b5121a232e | 5245 | * @cur: the node being checked |
| pcercuei | 0:03b5121a232e | 5246 | * |
| pcercuei | 0:03b5121a232e | 5247 | * Searches for the BASE URL. The code should work on both XML |
| pcercuei | 0:03b5121a232e | 5248 | * and HTML document even if base mechanisms are completely different. |
| pcercuei | 0:03b5121a232e | 5249 | * It returns the base as defined in RFC 2396 sections |
| pcercuei | 0:03b5121a232e | 5250 | * 5.1.1. Base URI within Document Content |
| pcercuei | 0:03b5121a232e | 5251 | * and |
| pcercuei | 0:03b5121a232e | 5252 | * 5.1.2. Base URI from the Encapsulating Entity |
| pcercuei | 0:03b5121a232e | 5253 | * However it does not return the document base (5.1.3), use |
| pcercuei | 0:03b5121a232e | 5254 | * doc->URL in this case |
| pcercuei | 0:03b5121a232e | 5255 | * |
| pcercuei | 0:03b5121a232e | 5256 | * Returns a pointer to the base URL, or NULL if not found |
| pcercuei | 0:03b5121a232e | 5257 | * It's up to the caller to free the memory with xmlFree(). |
| pcercuei | 0:03b5121a232e | 5258 | */ |
| pcercuei | 0:03b5121a232e | 5259 | xmlChar * |
| pcercuei | 0:03b5121a232e | 5260 | xmlNodeGetBase(const xmlDoc *doc, const xmlNode *cur) { |
| pcercuei | 0:03b5121a232e | 5261 | xmlChar *oldbase = NULL; |
| pcercuei | 0:03b5121a232e | 5262 | xmlChar *base, *newbase; |
| pcercuei | 0:03b5121a232e | 5263 | |
| pcercuei | 0:03b5121a232e | 5264 | if ((cur == NULL) && (doc == NULL)) |
| pcercuei | 0:03b5121a232e | 5265 | return(NULL); |
| pcercuei | 0:03b5121a232e | 5266 | if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) |
| pcercuei | 0:03b5121a232e | 5267 | return(NULL); |
| pcercuei | 0:03b5121a232e | 5268 | if (doc == NULL) doc = cur->doc; |
| pcercuei | 0:03b5121a232e | 5269 | if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) { |
| pcercuei | 0:03b5121a232e | 5270 | cur = doc->children; |
| pcercuei | 0:03b5121a232e | 5271 | while ((cur != NULL) && (cur->name != NULL)) { |
| pcercuei | 0:03b5121a232e | 5272 | if (cur->type != XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 5273 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 5274 | continue; |
| pcercuei | 0:03b5121a232e | 5275 | } |
| pcercuei | 0:03b5121a232e | 5276 | if (!xmlStrcasecmp(cur->name, BAD_CAST "html")) { |
| pcercuei | 0:03b5121a232e | 5277 | cur = cur->children; |
| pcercuei | 0:03b5121a232e | 5278 | continue; |
| pcercuei | 0:03b5121a232e | 5279 | } |
| pcercuei | 0:03b5121a232e | 5280 | if (!xmlStrcasecmp(cur->name, BAD_CAST "head")) { |
| pcercuei | 0:03b5121a232e | 5281 | cur = cur->children; |
| pcercuei | 0:03b5121a232e | 5282 | continue; |
| pcercuei | 0:03b5121a232e | 5283 | } |
| pcercuei | 0:03b5121a232e | 5284 | if (!xmlStrcasecmp(cur->name, BAD_CAST "base")) { |
| pcercuei | 0:03b5121a232e | 5285 | return(xmlGetProp(cur, BAD_CAST "href")); |
| pcercuei | 0:03b5121a232e | 5286 | } |
| pcercuei | 0:03b5121a232e | 5287 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 5288 | } |
| pcercuei | 0:03b5121a232e | 5289 | return(NULL); |
| pcercuei | 0:03b5121a232e | 5290 | } |
| pcercuei | 0:03b5121a232e | 5291 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 5292 | if (cur->type == XML_ENTITY_DECL) { |
| pcercuei | 0:03b5121a232e | 5293 | xmlEntityPtr ent = (xmlEntityPtr) cur; |
| pcercuei | 0:03b5121a232e | 5294 | return(xmlStrdup(ent->URI)); |
| pcercuei | 0:03b5121a232e | 5295 | } |
| pcercuei | 0:03b5121a232e | 5296 | if (cur->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 5297 | base = xmlGetNsProp(cur, BAD_CAST "base", XML_XML_NAMESPACE); |
| pcercuei | 0:03b5121a232e | 5298 | if (base != NULL) { |
| pcercuei | 0:03b5121a232e | 5299 | if (oldbase != NULL) { |
| pcercuei | 0:03b5121a232e | 5300 | newbase = xmlBuildURI(oldbase, base); |
| pcercuei | 0:03b5121a232e | 5301 | if (newbase != NULL) { |
| pcercuei | 0:03b5121a232e | 5302 | xmlFree(oldbase); |
| pcercuei | 0:03b5121a232e | 5303 | xmlFree(base); |
| pcercuei | 0:03b5121a232e | 5304 | oldbase = newbase; |
| pcercuei | 0:03b5121a232e | 5305 | } else { |
| pcercuei | 0:03b5121a232e | 5306 | xmlFree(oldbase); |
| pcercuei | 0:03b5121a232e | 5307 | xmlFree(base); |
| pcercuei | 0:03b5121a232e | 5308 | return(NULL); |
| pcercuei | 0:03b5121a232e | 5309 | } |
| pcercuei | 0:03b5121a232e | 5310 | } else { |
| pcercuei | 0:03b5121a232e | 5311 | oldbase = base; |
| pcercuei | 0:03b5121a232e | 5312 | } |
| pcercuei | 0:03b5121a232e | 5313 | if ((!xmlStrncmp(oldbase, BAD_CAST "http://", 7)) || |
| pcercuei | 0:03b5121a232e | 5314 | (!xmlStrncmp(oldbase, BAD_CAST "ftp://", 6)) || |
| pcercuei | 0:03b5121a232e | 5315 | (!xmlStrncmp(oldbase, BAD_CAST "urn:", 4))) |
| pcercuei | 0:03b5121a232e | 5316 | return(oldbase); |
| pcercuei | 0:03b5121a232e | 5317 | } |
| pcercuei | 0:03b5121a232e | 5318 | } |
| pcercuei | 0:03b5121a232e | 5319 | cur = cur->parent; |
| pcercuei | 0:03b5121a232e | 5320 | } |
| pcercuei | 0:03b5121a232e | 5321 | if ((doc != NULL) && (doc->URL != NULL)) { |
| pcercuei | 0:03b5121a232e | 5322 | if (oldbase == NULL) |
| pcercuei | 0:03b5121a232e | 5323 | return(xmlStrdup(doc->URL)); |
| pcercuei | 0:03b5121a232e | 5324 | newbase = xmlBuildURI(oldbase, doc->URL); |
| pcercuei | 0:03b5121a232e | 5325 | xmlFree(oldbase); |
| pcercuei | 0:03b5121a232e | 5326 | return(newbase); |
| pcercuei | 0:03b5121a232e | 5327 | } |
| pcercuei | 0:03b5121a232e | 5328 | return(oldbase); |
| pcercuei | 0:03b5121a232e | 5329 | } |
| pcercuei | 0:03b5121a232e | 5330 | |
| pcercuei | 0:03b5121a232e | 5331 | /** |
| pcercuei | 0:03b5121a232e | 5332 | * xmlNodeBufGetContent: |
| pcercuei | 0:03b5121a232e | 5333 | * @buffer: a buffer |
| pcercuei | 0:03b5121a232e | 5334 | * @cur: the node being read |
| pcercuei | 0:03b5121a232e | 5335 | * |
| pcercuei | 0:03b5121a232e | 5336 | * Read the value of a node @cur, this can be either the text carried |
| pcercuei | 0:03b5121a232e | 5337 | * directly by this node if it's a TEXT node or the aggregate string |
| pcercuei | 0:03b5121a232e | 5338 | * of the values carried by this node child's (TEXT and ENTITY_REF). |
| pcercuei | 0:03b5121a232e | 5339 | * Entity references are substituted. |
| pcercuei | 0:03b5121a232e | 5340 | * Fills up the buffer @buffer with this value |
| pcercuei | 0:03b5121a232e | 5341 | * |
| pcercuei | 0:03b5121a232e | 5342 | * Returns 0 in case of success and -1 in case of error. |
| pcercuei | 0:03b5121a232e | 5343 | */ |
| pcercuei | 0:03b5121a232e | 5344 | int |
| pcercuei | 0:03b5121a232e | 5345 | xmlNodeBufGetContent(xmlBufferPtr buffer, const xmlNode *cur) |
| pcercuei | 0:03b5121a232e | 5346 | { |
| pcercuei | 0:03b5121a232e | 5347 | xmlBufPtr buf; |
| pcercuei | 0:03b5121a232e | 5348 | int ret; |
| pcercuei | 0:03b5121a232e | 5349 | |
| pcercuei | 0:03b5121a232e | 5350 | if ((cur == NULL) || (buffer == NULL)) return(-1); |
| pcercuei | 0:03b5121a232e | 5351 | buf = xmlBufFromBuffer(buffer); |
| pcercuei | 0:03b5121a232e | 5352 | ret = xmlBufGetNodeContent(buf, cur); |
| pcercuei | 0:03b5121a232e | 5353 | buffer = xmlBufBackToBuffer(buf); |
| pcercuei | 0:03b5121a232e | 5354 | if ((ret < 0) || (buffer == NULL)) |
| pcercuei | 0:03b5121a232e | 5355 | return(-1); |
| pcercuei | 0:03b5121a232e | 5356 | return(0); |
| pcercuei | 0:03b5121a232e | 5357 | } |
| pcercuei | 0:03b5121a232e | 5358 | |
| pcercuei | 0:03b5121a232e | 5359 | /** |
| pcercuei | 0:03b5121a232e | 5360 | * xmlBufGetNodeContent: |
| pcercuei | 0:03b5121a232e | 5361 | * @buf: a buffer xmlBufPtr |
| pcercuei | 0:03b5121a232e | 5362 | * @cur: the node being read |
| pcercuei | 0:03b5121a232e | 5363 | * |
| pcercuei | 0:03b5121a232e | 5364 | * Read the value of a node @cur, this can be either the text carried |
| pcercuei | 0:03b5121a232e | 5365 | * directly by this node if it's a TEXT node or the aggregate string |
| pcercuei | 0:03b5121a232e | 5366 | * of the values carried by this node child's (TEXT and ENTITY_REF). |
| pcercuei | 0:03b5121a232e | 5367 | * Entity references are substituted. |
| pcercuei | 0:03b5121a232e | 5368 | * Fills up the buffer @buf with this value |
| pcercuei | 0:03b5121a232e | 5369 | * |
| pcercuei | 0:03b5121a232e | 5370 | * Returns 0 in case of success and -1 in case of error. |
| pcercuei | 0:03b5121a232e | 5371 | */ |
| pcercuei | 0:03b5121a232e | 5372 | int |
| pcercuei | 0:03b5121a232e | 5373 | xmlBufGetNodeContent(xmlBufPtr buf, const xmlNode *cur) |
| pcercuei | 0:03b5121a232e | 5374 | { |
| pcercuei | 0:03b5121a232e | 5375 | if ((cur == NULL) || (buf == NULL)) return(-1); |
| pcercuei | 0:03b5121a232e | 5376 | switch (cur->type) { |
| pcercuei | 0:03b5121a232e | 5377 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 5378 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 5379 | xmlBufCat(buf, cur->content); |
| pcercuei | 0:03b5121a232e | 5380 | break; |
| pcercuei | 0:03b5121a232e | 5381 | case XML_DOCUMENT_FRAG_NODE: |
| pcercuei | 0:03b5121a232e | 5382 | case XML_ELEMENT_NODE:{ |
| pcercuei | 0:03b5121a232e | 5383 | const xmlNode *tmp = cur; |
| pcercuei | 0:03b5121a232e | 5384 | |
| pcercuei | 0:03b5121a232e | 5385 | while (tmp != NULL) { |
| pcercuei | 0:03b5121a232e | 5386 | switch (tmp->type) { |
| pcercuei | 0:03b5121a232e | 5387 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 5388 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 5389 | if (tmp->content != NULL) |
| pcercuei | 0:03b5121a232e | 5390 | xmlBufCat(buf, tmp->content); |
| pcercuei | 0:03b5121a232e | 5391 | break; |
| pcercuei | 0:03b5121a232e | 5392 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 5393 | xmlBufGetNodeContent(buf, tmp); |
| pcercuei | 0:03b5121a232e | 5394 | break; |
| pcercuei | 0:03b5121a232e | 5395 | default: |
| pcercuei | 0:03b5121a232e | 5396 | break; |
| pcercuei | 0:03b5121a232e | 5397 | } |
| pcercuei | 0:03b5121a232e | 5398 | /* |
| pcercuei | 0:03b5121a232e | 5399 | * Skip to next node |
| pcercuei | 0:03b5121a232e | 5400 | */ |
| pcercuei | 0:03b5121a232e | 5401 | if (tmp->children != NULL) { |
| pcercuei | 0:03b5121a232e | 5402 | if (tmp->children->type != XML_ENTITY_DECL) { |
| pcercuei | 0:03b5121a232e | 5403 | tmp = tmp->children; |
| pcercuei | 0:03b5121a232e | 5404 | continue; |
| pcercuei | 0:03b5121a232e | 5405 | } |
| pcercuei | 0:03b5121a232e | 5406 | } |
| pcercuei | 0:03b5121a232e | 5407 | if (tmp == cur) |
| pcercuei | 0:03b5121a232e | 5408 | break; |
| pcercuei | 0:03b5121a232e | 5409 | |
| pcercuei | 0:03b5121a232e | 5410 | if (tmp->next != NULL) { |
| pcercuei | 0:03b5121a232e | 5411 | tmp = tmp->next; |
| pcercuei | 0:03b5121a232e | 5412 | continue; |
| pcercuei | 0:03b5121a232e | 5413 | } |
| pcercuei | 0:03b5121a232e | 5414 | |
| pcercuei | 0:03b5121a232e | 5415 | do { |
| pcercuei | 0:03b5121a232e | 5416 | tmp = tmp->parent; |
| pcercuei | 0:03b5121a232e | 5417 | if (tmp == NULL) |
| pcercuei | 0:03b5121a232e | 5418 | break; |
| pcercuei | 0:03b5121a232e | 5419 | if (tmp == cur) { |
| pcercuei | 0:03b5121a232e | 5420 | tmp = NULL; |
| pcercuei | 0:03b5121a232e | 5421 | break; |
| pcercuei | 0:03b5121a232e | 5422 | } |
| pcercuei | 0:03b5121a232e | 5423 | if (tmp->next != NULL) { |
| pcercuei | 0:03b5121a232e | 5424 | tmp = tmp->next; |
| pcercuei | 0:03b5121a232e | 5425 | break; |
| pcercuei | 0:03b5121a232e | 5426 | } |
| pcercuei | 0:03b5121a232e | 5427 | } while (tmp != NULL); |
| pcercuei | 0:03b5121a232e | 5428 | } |
| pcercuei | 0:03b5121a232e | 5429 | break; |
| pcercuei | 0:03b5121a232e | 5430 | } |
| pcercuei | 0:03b5121a232e | 5431 | case XML_ATTRIBUTE_NODE:{ |
| pcercuei | 0:03b5121a232e | 5432 | xmlAttrPtr attr = (xmlAttrPtr) cur; |
| pcercuei | 0:03b5121a232e | 5433 | xmlNodePtr tmp = attr->children; |
| pcercuei | 0:03b5121a232e | 5434 | |
| pcercuei | 0:03b5121a232e | 5435 | while (tmp != NULL) { |
| pcercuei | 0:03b5121a232e | 5436 | if (tmp->type == XML_TEXT_NODE) |
| pcercuei | 0:03b5121a232e | 5437 | xmlBufCat(buf, tmp->content); |
| pcercuei | 0:03b5121a232e | 5438 | else |
| pcercuei | 0:03b5121a232e | 5439 | xmlBufGetNodeContent(buf, tmp); |
| pcercuei | 0:03b5121a232e | 5440 | tmp = tmp->next; |
| pcercuei | 0:03b5121a232e | 5441 | } |
| pcercuei | 0:03b5121a232e | 5442 | break; |
| pcercuei | 0:03b5121a232e | 5443 | } |
| pcercuei | 0:03b5121a232e | 5444 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5445 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 5446 | xmlBufCat(buf, cur->content); |
| pcercuei | 0:03b5121a232e | 5447 | break; |
| pcercuei | 0:03b5121a232e | 5448 | case XML_ENTITY_REF_NODE:{ |
| pcercuei | 0:03b5121a232e | 5449 | xmlEntityPtr ent; |
| pcercuei | 0:03b5121a232e | 5450 | xmlNodePtr tmp; |
| pcercuei | 0:03b5121a232e | 5451 | |
| pcercuei | 0:03b5121a232e | 5452 | /* lookup entity declaration */ |
| pcercuei | 0:03b5121a232e | 5453 | ent = xmlGetDocEntity(cur->doc, cur->name); |
| pcercuei | 0:03b5121a232e | 5454 | if (ent == NULL) |
| pcercuei | 0:03b5121a232e | 5455 | return(-1); |
| pcercuei | 0:03b5121a232e | 5456 | |
| pcercuei | 0:03b5121a232e | 5457 | /* an entity content can be any "well balanced chunk", |
| pcercuei | 0:03b5121a232e | 5458 | * i.e. the result of the content [43] production: |
| pcercuei | 0:03b5121a232e | 5459 | * http://www.w3.org/TR/REC-xml#NT-content |
| pcercuei | 0:03b5121a232e | 5460 | * -> we iterate through child nodes and recursive call |
| pcercuei | 0:03b5121a232e | 5461 | * xmlNodeGetContent() which handles all possible node types */ |
| pcercuei | 0:03b5121a232e | 5462 | tmp = ent->children; |
| pcercuei | 0:03b5121a232e | 5463 | while (tmp) { |
| pcercuei | 0:03b5121a232e | 5464 | xmlBufGetNodeContent(buf, tmp); |
| pcercuei | 0:03b5121a232e | 5465 | tmp = tmp->next; |
| pcercuei | 0:03b5121a232e | 5466 | } |
| pcercuei | 0:03b5121a232e | 5467 | break; |
| pcercuei | 0:03b5121a232e | 5468 | } |
| pcercuei | 0:03b5121a232e | 5469 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 5470 | case XML_DOCUMENT_TYPE_NODE: |
| pcercuei | 0:03b5121a232e | 5471 | case XML_NOTATION_NODE: |
| pcercuei | 0:03b5121a232e | 5472 | case XML_DTD_NODE: |
| pcercuei | 0:03b5121a232e | 5473 | case XML_XINCLUDE_START: |
| pcercuei | 0:03b5121a232e | 5474 | case XML_XINCLUDE_END: |
| pcercuei | 0:03b5121a232e | 5475 | break; |
| pcercuei | 0:03b5121a232e | 5476 | case XML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5477 | #ifdef LIBXML_DOCB_ENABLED |
| pcercuei | 0:03b5121a232e | 5478 | case XML_DOCB_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5479 | #endif |
| pcercuei | 0:03b5121a232e | 5480 | case XML_HTML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5481 | cur = cur->children; |
| pcercuei | 0:03b5121a232e | 5482 | while (cur!= NULL) { |
| pcercuei | 0:03b5121a232e | 5483 | if ((cur->type == XML_ELEMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 5484 | (cur->type == XML_TEXT_NODE) || |
| pcercuei | 0:03b5121a232e | 5485 | (cur->type == XML_CDATA_SECTION_NODE)) { |
| pcercuei | 0:03b5121a232e | 5486 | xmlBufGetNodeContent(buf, cur); |
| pcercuei | 0:03b5121a232e | 5487 | } |
| pcercuei | 0:03b5121a232e | 5488 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 5489 | } |
| pcercuei | 0:03b5121a232e | 5490 | break; |
| pcercuei | 0:03b5121a232e | 5491 | case XML_NAMESPACE_DECL: |
| pcercuei | 0:03b5121a232e | 5492 | xmlBufCat(buf, ((xmlNsPtr) cur)->href); |
| pcercuei | 0:03b5121a232e | 5493 | break; |
| pcercuei | 0:03b5121a232e | 5494 | case XML_ELEMENT_DECL: |
| pcercuei | 0:03b5121a232e | 5495 | case XML_ATTRIBUTE_DECL: |
| pcercuei | 0:03b5121a232e | 5496 | case XML_ENTITY_DECL: |
| pcercuei | 0:03b5121a232e | 5497 | break; |
| pcercuei | 0:03b5121a232e | 5498 | } |
| pcercuei | 0:03b5121a232e | 5499 | return(0); |
| pcercuei | 0:03b5121a232e | 5500 | } |
| pcercuei | 0:03b5121a232e | 5501 | |
| pcercuei | 0:03b5121a232e | 5502 | /** |
| pcercuei | 0:03b5121a232e | 5503 | * xmlNodeGetContent: |
| pcercuei | 0:03b5121a232e | 5504 | * @cur: the node being read |
| pcercuei | 0:03b5121a232e | 5505 | * |
| pcercuei | 0:03b5121a232e | 5506 | * Read the value of a node, this can be either the text carried |
| pcercuei | 0:03b5121a232e | 5507 | * directly by this node if it's a TEXT node or the aggregate string |
| pcercuei | 0:03b5121a232e | 5508 | * of the values carried by this node child's (TEXT and ENTITY_REF). |
| pcercuei | 0:03b5121a232e | 5509 | * Entity references are substituted. |
| pcercuei | 0:03b5121a232e | 5510 | * Returns a new #xmlChar * or NULL if no content is available. |
| pcercuei | 0:03b5121a232e | 5511 | * It's up to the caller to free the memory with xmlFree(). |
| pcercuei | 0:03b5121a232e | 5512 | */ |
| pcercuei | 0:03b5121a232e | 5513 | xmlChar * |
| pcercuei | 0:03b5121a232e | 5514 | xmlNodeGetContent(const xmlNode *cur) |
| pcercuei | 0:03b5121a232e | 5515 | { |
| pcercuei | 0:03b5121a232e | 5516 | if (cur == NULL) |
| pcercuei | 0:03b5121a232e | 5517 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5518 | switch (cur->type) { |
| pcercuei | 0:03b5121a232e | 5519 | case XML_DOCUMENT_FRAG_NODE: |
| pcercuei | 0:03b5121a232e | 5520 | case XML_ELEMENT_NODE:{ |
| pcercuei | 0:03b5121a232e | 5521 | xmlBufPtr buf; |
| pcercuei | 0:03b5121a232e | 5522 | xmlChar *ret; |
| pcercuei | 0:03b5121a232e | 5523 | |
| pcercuei | 0:03b5121a232e | 5524 | buf = xmlBufCreateSize(64); |
| pcercuei | 0:03b5121a232e | 5525 | if (buf == NULL) |
| pcercuei | 0:03b5121a232e | 5526 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5527 | xmlBufGetNodeContent(buf, cur); |
| pcercuei | 0:03b5121a232e | 5528 | ret = xmlBufDetach(buf); |
| pcercuei | 0:03b5121a232e | 5529 | xmlBufFree(buf); |
| pcercuei | 0:03b5121a232e | 5530 | return (ret); |
| pcercuei | 0:03b5121a232e | 5531 | } |
| pcercuei | 0:03b5121a232e | 5532 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 5533 | return(xmlGetPropNodeValueInternal((xmlAttrPtr) cur)); |
| pcercuei | 0:03b5121a232e | 5534 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5535 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 5536 | if (cur->content != NULL) |
| pcercuei | 0:03b5121a232e | 5537 | return (xmlStrdup(cur->content)); |
| pcercuei | 0:03b5121a232e | 5538 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5539 | case XML_ENTITY_REF_NODE:{ |
| pcercuei | 0:03b5121a232e | 5540 | xmlEntityPtr ent; |
| pcercuei | 0:03b5121a232e | 5541 | xmlBufPtr buf; |
| pcercuei | 0:03b5121a232e | 5542 | xmlChar *ret; |
| pcercuei | 0:03b5121a232e | 5543 | |
| pcercuei | 0:03b5121a232e | 5544 | /* lookup entity declaration */ |
| pcercuei | 0:03b5121a232e | 5545 | ent = xmlGetDocEntity(cur->doc, cur->name); |
| pcercuei | 0:03b5121a232e | 5546 | if (ent == NULL) |
| pcercuei | 0:03b5121a232e | 5547 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5548 | |
| pcercuei | 0:03b5121a232e | 5549 | buf = xmlBufCreate(); |
| pcercuei | 0:03b5121a232e | 5550 | if (buf == NULL) |
| pcercuei | 0:03b5121a232e | 5551 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5552 | |
| pcercuei | 0:03b5121a232e | 5553 | xmlBufGetNodeContent(buf, cur); |
| pcercuei | 0:03b5121a232e | 5554 | |
| pcercuei | 0:03b5121a232e | 5555 | ret = xmlBufDetach(buf); |
| pcercuei | 0:03b5121a232e | 5556 | xmlBufFree(buf); |
| pcercuei | 0:03b5121a232e | 5557 | return (ret); |
| pcercuei | 0:03b5121a232e | 5558 | } |
| pcercuei | 0:03b5121a232e | 5559 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 5560 | case XML_DOCUMENT_TYPE_NODE: |
| pcercuei | 0:03b5121a232e | 5561 | case XML_NOTATION_NODE: |
| pcercuei | 0:03b5121a232e | 5562 | case XML_DTD_NODE: |
| pcercuei | 0:03b5121a232e | 5563 | case XML_XINCLUDE_START: |
| pcercuei | 0:03b5121a232e | 5564 | case XML_XINCLUDE_END: |
| pcercuei | 0:03b5121a232e | 5565 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5566 | case XML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5567 | #ifdef LIBXML_DOCB_ENABLED |
| pcercuei | 0:03b5121a232e | 5568 | case XML_DOCB_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5569 | #endif |
| pcercuei | 0:03b5121a232e | 5570 | case XML_HTML_DOCUMENT_NODE: { |
| pcercuei | 0:03b5121a232e | 5571 | xmlBufPtr buf; |
| pcercuei | 0:03b5121a232e | 5572 | xmlChar *ret; |
| pcercuei | 0:03b5121a232e | 5573 | |
| pcercuei | 0:03b5121a232e | 5574 | buf = xmlBufCreate(); |
| pcercuei | 0:03b5121a232e | 5575 | if (buf == NULL) |
| pcercuei | 0:03b5121a232e | 5576 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5577 | |
| pcercuei | 0:03b5121a232e | 5578 | xmlBufGetNodeContent(buf, (xmlNodePtr) cur); |
| pcercuei | 0:03b5121a232e | 5579 | |
| pcercuei | 0:03b5121a232e | 5580 | ret = xmlBufDetach(buf); |
| pcercuei | 0:03b5121a232e | 5581 | xmlBufFree(buf); |
| pcercuei | 0:03b5121a232e | 5582 | return (ret); |
| pcercuei | 0:03b5121a232e | 5583 | } |
| pcercuei | 0:03b5121a232e | 5584 | case XML_NAMESPACE_DECL: { |
| pcercuei | 0:03b5121a232e | 5585 | xmlChar *tmp; |
| pcercuei | 0:03b5121a232e | 5586 | |
| pcercuei | 0:03b5121a232e | 5587 | tmp = xmlStrdup(((xmlNsPtr) cur)->href); |
| pcercuei | 0:03b5121a232e | 5588 | return (tmp); |
| pcercuei | 0:03b5121a232e | 5589 | } |
| pcercuei | 0:03b5121a232e | 5590 | case XML_ELEMENT_DECL: |
| pcercuei | 0:03b5121a232e | 5591 | /* TODO !!! */ |
| pcercuei | 0:03b5121a232e | 5592 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5593 | case XML_ATTRIBUTE_DECL: |
| pcercuei | 0:03b5121a232e | 5594 | /* TODO !!! */ |
| pcercuei | 0:03b5121a232e | 5595 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5596 | case XML_ENTITY_DECL: |
| pcercuei | 0:03b5121a232e | 5597 | /* TODO !!! */ |
| pcercuei | 0:03b5121a232e | 5598 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5599 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 5600 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 5601 | if (cur->content != NULL) |
| pcercuei | 0:03b5121a232e | 5602 | return (xmlStrdup(cur->content)); |
| pcercuei | 0:03b5121a232e | 5603 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5604 | } |
| pcercuei | 0:03b5121a232e | 5605 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5606 | } |
| pcercuei | 0:03b5121a232e | 5607 | |
| pcercuei | 0:03b5121a232e | 5608 | /** |
| pcercuei | 0:03b5121a232e | 5609 | * xmlNodeSetContent: |
| pcercuei | 0:03b5121a232e | 5610 | * @cur: the node being modified |
| pcercuei | 0:03b5121a232e | 5611 | * @content: the new value of the content |
| pcercuei | 0:03b5121a232e | 5612 | * |
| pcercuei | 0:03b5121a232e | 5613 | * Replace the content of a node. |
| pcercuei | 0:03b5121a232e | 5614 | * NOTE: @content is supposed to be a piece of XML CDATA, so it allows entity |
| pcercuei | 0:03b5121a232e | 5615 | * references, but XML special chars need to be escaped first by using |
| pcercuei | 0:03b5121a232e | 5616 | * xmlEncodeEntitiesReentrant() resp. xmlEncodeSpecialChars(). |
| pcercuei | 0:03b5121a232e | 5617 | */ |
| pcercuei | 0:03b5121a232e | 5618 | void |
| pcercuei | 0:03b5121a232e | 5619 | xmlNodeSetContent(xmlNodePtr cur, const xmlChar *content) { |
| pcercuei | 0:03b5121a232e | 5620 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 5621 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 5622 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 5623 | "xmlNodeSetContent : node == NULL\n"); |
| pcercuei | 0:03b5121a232e | 5624 | #endif |
| pcercuei | 0:03b5121a232e | 5625 | return; |
| pcercuei | 0:03b5121a232e | 5626 | } |
| pcercuei | 0:03b5121a232e | 5627 | switch (cur->type) { |
| pcercuei | 0:03b5121a232e | 5628 | case XML_DOCUMENT_FRAG_NODE: |
| pcercuei | 0:03b5121a232e | 5629 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5630 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 5631 | if (cur->children != NULL) xmlFreeNodeList(cur->children); |
| pcercuei | 0:03b5121a232e | 5632 | cur->children = xmlStringGetNodeList(cur->doc, content); |
| pcercuei | 0:03b5121a232e | 5633 | UPDATE_LAST_CHILD_AND_PARENT(cur) |
| pcercuei | 0:03b5121a232e | 5634 | break; |
| pcercuei | 0:03b5121a232e | 5635 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 5636 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 5637 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 5638 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 5639 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 5640 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5641 | if ((cur->content != NULL) && |
| pcercuei | 0:03b5121a232e | 5642 | (cur->content != (xmlChar *) &(cur->properties))) { |
| pcercuei | 0:03b5121a232e | 5643 | if (!((cur->doc != NULL) && (cur->doc->dict != NULL) && |
| pcercuei | 0:03b5121a232e | 5644 | (xmlDictOwns(cur->doc->dict, cur->content)))) |
| pcercuei | 0:03b5121a232e | 5645 | xmlFree(cur->content); |
| pcercuei | 0:03b5121a232e | 5646 | } |
| pcercuei | 0:03b5121a232e | 5647 | if (cur->children != NULL) xmlFreeNodeList(cur->children); |
| pcercuei | 0:03b5121a232e | 5648 | cur->last = cur->children = NULL; |
| pcercuei | 0:03b5121a232e | 5649 | if (content != NULL) { |
| pcercuei | 0:03b5121a232e | 5650 | cur->content = xmlStrdup(content); |
| pcercuei | 0:03b5121a232e | 5651 | } else |
| pcercuei | 0:03b5121a232e | 5652 | cur->content = NULL; |
| pcercuei | 0:03b5121a232e | 5653 | cur->properties = NULL; |
| pcercuei | 0:03b5121a232e | 5654 | cur->nsDef = NULL; |
| pcercuei | 0:03b5121a232e | 5655 | break; |
| pcercuei | 0:03b5121a232e | 5656 | case XML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5657 | case XML_HTML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5658 | case XML_DOCUMENT_TYPE_NODE: |
| pcercuei | 0:03b5121a232e | 5659 | case XML_XINCLUDE_START: |
| pcercuei | 0:03b5121a232e | 5660 | case XML_XINCLUDE_END: |
| pcercuei | 0:03b5121a232e | 5661 | #ifdef LIBXML_DOCB_ENABLED |
| pcercuei | 0:03b5121a232e | 5662 | case XML_DOCB_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5663 | #endif |
| pcercuei | 0:03b5121a232e | 5664 | break; |
| pcercuei | 0:03b5121a232e | 5665 | case XML_NOTATION_NODE: |
| pcercuei | 0:03b5121a232e | 5666 | break; |
| pcercuei | 0:03b5121a232e | 5667 | case XML_DTD_NODE: |
| pcercuei | 0:03b5121a232e | 5668 | break; |
| pcercuei | 0:03b5121a232e | 5669 | case XML_NAMESPACE_DECL: |
| pcercuei | 0:03b5121a232e | 5670 | break; |
| pcercuei | 0:03b5121a232e | 5671 | case XML_ELEMENT_DECL: |
| pcercuei | 0:03b5121a232e | 5672 | /* TODO !!! */ |
| pcercuei | 0:03b5121a232e | 5673 | break; |
| pcercuei | 0:03b5121a232e | 5674 | case XML_ATTRIBUTE_DECL: |
| pcercuei | 0:03b5121a232e | 5675 | /* TODO !!! */ |
| pcercuei | 0:03b5121a232e | 5676 | break; |
| pcercuei | 0:03b5121a232e | 5677 | case XML_ENTITY_DECL: |
| pcercuei | 0:03b5121a232e | 5678 | /* TODO !!! */ |
| pcercuei | 0:03b5121a232e | 5679 | break; |
| pcercuei | 0:03b5121a232e | 5680 | } |
| pcercuei | 0:03b5121a232e | 5681 | } |
| pcercuei | 0:03b5121a232e | 5682 | |
| pcercuei | 0:03b5121a232e | 5683 | #ifdef LIBXML_TREE_ENABLED |
| pcercuei | 0:03b5121a232e | 5684 | /** |
| pcercuei | 0:03b5121a232e | 5685 | * xmlNodeSetContentLen: |
| pcercuei | 0:03b5121a232e | 5686 | * @cur: the node being modified |
| pcercuei | 0:03b5121a232e | 5687 | * @content: the new value of the content |
| pcercuei | 0:03b5121a232e | 5688 | * @len: the size of @content |
| pcercuei | 0:03b5121a232e | 5689 | * |
| pcercuei | 0:03b5121a232e | 5690 | * Replace the content of a node. |
| pcercuei | 0:03b5121a232e | 5691 | * NOTE: @content is supposed to be a piece of XML CDATA, so it allows entity |
| pcercuei | 0:03b5121a232e | 5692 | * references, but XML special chars need to be escaped first by using |
| pcercuei | 0:03b5121a232e | 5693 | * xmlEncodeEntitiesReentrant() resp. xmlEncodeSpecialChars(). |
| pcercuei | 0:03b5121a232e | 5694 | */ |
| pcercuei | 0:03b5121a232e | 5695 | void |
| pcercuei | 0:03b5121a232e | 5696 | xmlNodeSetContentLen(xmlNodePtr cur, const xmlChar *content, int len) { |
| pcercuei | 0:03b5121a232e | 5697 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 5698 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 5699 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 5700 | "xmlNodeSetContentLen : node == NULL\n"); |
| pcercuei | 0:03b5121a232e | 5701 | #endif |
| pcercuei | 0:03b5121a232e | 5702 | return; |
| pcercuei | 0:03b5121a232e | 5703 | } |
| pcercuei | 0:03b5121a232e | 5704 | switch (cur->type) { |
| pcercuei | 0:03b5121a232e | 5705 | case XML_DOCUMENT_FRAG_NODE: |
| pcercuei | 0:03b5121a232e | 5706 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5707 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 5708 | if (cur->children != NULL) xmlFreeNodeList(cur->children); |
| pcercuei | 0:03b5121a232e | 5709 | cur->children = xmlStringLenGetNodeList(cur->doc, content, len); |
| pcercuei | 0:03b5121a232e | 5710 | UPDATE_LAST_CHILD_AND_PARENT(cur) |
| pcercuei | 0:03b5121a232e | 5711 | break; |
| pcercuei | 0:03b5121a232e | 5712 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 5713 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 5714 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 5715 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 5716 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 5717 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5718 | case XML_NOTATION_NODE: |
| pcercuei | 0:03b5121a232e | 5719 | if ((cur->content != NULL) && |
| pcercuei | 0:03b5121a232e | 5720 | (cur->content != (xmlChar *) &(cur->properties))) { |
| pcercuei | 0:03b5121a232e | 5721 | if (!((cur->doc != NULL) && (cur->doc->dict != NULL) && |
| pcercuei | 0:03b5121a232e | 5722 | (xmlDictOwns(cur->doc->dict, cur->content)))) |
| pcercuei | 0:03b5121a232e | 5723 | xmlFree(cur->content); |
| pcercuei | 0:03b5121a232e | 5724 | } |
| pcercuei | 0:03b5121a232e | 5725 | if (cur->children != NULL) xmlFreeNodeList(cur->children); |
| pcercuei | 0:03b5121a232e | 5726 | cur->children = cur->last = NULL; |
| pcercuei | 0:03b5121a232e | 5727 | if (content != NULL) { |
| pcercuei | 0:03b5121a232e | 5728 | cur->content = xmlStrndup(content, len); |
| pcercuei | 0:03b5121a232e | 5729 | } else |
| pcercuei | 0:03b5121a232e | 5730 | cur->content = NULL; |
| pcercuei | 0:03b5121a232e | 5731 | cur->properties = NULL; |
| pcercuei | 0:03b5121a232e | 5732 | cur->nsDef = NULL; |
| pcercuei | 0:03b5121a232e | 5733 | break; |
| pcercuei | 0:03b5121a232e | 5734 | case XML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5735 | case XML_DTD_NODE: |
| pcercuei | 0:03b5121a232e | 5736 | case XML_HTML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5737 | case XML_DOCUMENT_TYPE_NODE: |
| pcercuei | 0:03b5121a232e | 5738 | case XML_NAMESPACE_DECL: |
| pcercuei | 0:03b5121a232e | 5739 | case XML_XINCLUDE_START: |
| pcercuei | 0:03b5121a232e | 5740 | case XML_XINCLUDE_END: |
| pcercuei | 0:03b5121a232e | 5741 | #ifdef LIBXML_DOCB_ENABLED |
| pcercuei | 0:03b5121a232e | 5742 | case XML_DOCB_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5743 | #endif |
| pcercuei | 0:03b5121a232e | 5744 | break; |
| pcercuei | 0:03b5121a232e | 5745 | case XML_ELEMENT_DECL: |
| pcercuei | 0:03b5121a232e | 5746 | /* TODO !!! */ |
| pcercuei | 0:03b5121a232e | 5747 | break; |
| pcercuei | 0:03b5121a232e | 5748 | case XML_ATTRIBUTE_DECL: |
| pcercuei | 0:03b5121a232e | 5749 | /* TODO !!! */ |
| pcercuei | 0:03b5121a232e | 5750 | break; |
| pcercuei | 0:03b5121a232e | 5751 | case XML_ENTITY_DECL: |
| pcercuei | 0:03b5121a232e | 5752 | /* TODO !!! */ |
| pcercuei | 0:03b5121a232e | 5753 | break; |
| pcercuei | 0:03b5121a232e | 5754 | } |
| pcercuei | 0:03b5121a232e | 5755 | } |
| pcercuei | 0:03b5121a232e | 5756 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 5757 | |
| pcercuei | 0:03b5121a232e | 5758 | /** |
| pcercuei | 0:03b5121a232e | 5759 | * xmlNodeAddContentLen: |
| pcercuei | 0:03b5121a232e | 5760 | * @cur: the node being modified |
| pcercuei | 0:03b5121a232e | 5761 | * @content: extra content |
| pcercuei | 0:03b5121a232e | 5762 | * @len: the size of @content |
| pcercuei | 0:03b5121a232e | 5763 | * |
| pcercuei | 0:03b5121a232e | 5764 | * Append the extra substring to the node content. |
| pcercuei | 0:03b5121a232e | 5765 | * NOTE: In contrast to xmlNodeSetContentLen(), @content is supposed to be |
| pcercuei | 0:03b5121a232e | 5766 | * raw text, so unescaped XML special chars are allowed, entity |
| pcercuei | 0:03b5121a232e | 5767 | * references are not supported. |
| pcercuei | 0:03b5121a232e | 5768 | */ |
| pcercuei | 0:03b5121a232e | 5769 | void |
| pcercuei | 0:03b5121a232e | 5770 | xmlNodeAddContentLen(xmlNodePtr cur, const xmlChar *content, int len) { |
| pcercuei | 0:03b5121a232e | 5771 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 5772 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 5773 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 5774 | "xmlNodeAddContentLen : node == NULL\n"); |
| pcercuei | 0:03b5121a232e | 5775 | #endif |
| pcercuei | 0:03b5121a232e | 5776 | return; |
| pcercuei | 0:03b5121a232e | 5777 | } |
| pcercuei | 0:03b5121a232e | 5778 | if (len <= 0) return; |
| pcercuei | 0:03b5121a232e | 5779 | switch (cur->type) { |
| pcercuei | 0:03b5121a232e | 5780 | case XML_DOCUMENT_FRAG_NODE: |
| pcercuei | 0:03b5121a232e | 5781 | case XML_ELEMENT_NODE: { |
| pcercuei | 0:03b5121a232e | 5782 | xmlNodePtr last, newNode, tmp; |
| pcercuei | 0:03b5121a232e | 5783 | |
| pcercuei | 0:03b5121a232e | 5784 | last = cur->last; |
| pcercuei | 0:03b5121a232e | 5785 | newNode = xmlNewTextLen(content, len); |
| pcercuei | 0:03b5121a232e | 5786 | if (newNode != NULL) { |
| pcercuei | 0:03b5121a232e | 5787 | tmp = xmlAddChild(cur, newNode); |
| pcercuei | 0:03b5121a232e | 5788 | if (tmp != newNode) |
| pcercuei | 0:03b5121a232e | 5789 | return; |
| pcercuei | 0:03b5121a232e | 5790 | if ((last != NULL) && (last->next == newNode)) { |
| pcercuei | 0:03b5121a232e | 5791 | xmlTextMerge(last, newNode); |
| pcercuei | 0:03b5121a232e | 5792 | } |
| pcercuei | 0:03b5121a232e | 5793 | } |
| pcercuei | 0:03b5121a232e | 5794 | break; |
| pcercuei | 0:03b5121a232e | 5795 | } |
| pcercuei | 0:03b5121a232e | 5796 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 5797 | break; |
| pcercuei | 0:03b5121a232e | 5798 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 5799 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 5800 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 5801 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 5802 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 5803 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5804 | case XML_NOTATION_NODE: |
| pcercuei | 0:03b5121a232e | 5805 | if (content != NULL) { |
| pcercuei | 0:03b5121a232e | 5806 | if ((cur->content == (xmlChar *) &(cur->properties)) || |
| pcercuei | 0:03b5121a232e | 5807 | ((cur->doc != NULL) && (cur->doc->dict != NULL) && |
| pcercuei | 0:03b5121a232e | 5808 | xmlDictOwns(cur->doc->dict, cur->content))) { |
| pcercuei | 0:03b5121a232e | 5809 | cur->content = xmlStrncatNew(cur->content, content, len); |
| pcercuei | 0:03b5121a232e | 5810 | cur->properties = NULL; |
| pcercuei | 0:03b5121a232e | 5811 | cur->nsDef = NULL; |
| pcercuei | 0:03b5121a232e | 5812 | break; |
| pcercuei | 0:03b5121a232e | 5813 | } |
| pcercuei | 0:03b5121a232e | 5814 | cur->content = xmlStrncat(cur->content, content, len); |
| pcercuei | 0:03b5121a232e | 5815 | } |
| pcercuei | 0:03b5121a232e | 5816 | case XML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5817 | case XML_DTD_NODE: |
| pcercuei | 0:03b5121a232e | 5818 | case XML_HTML_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5819 | case XML_DOCUMENT_TYPE_NODE: |
| pcercuei | 0:03b5121a232e | 5820 | case XML_NAMESPACE_DECL: |
| pcercuei | 0:03b5121a232e | 5821 | case XML_XINCLUDE_START: |
| pcercuei | 0:03b5121a232e | 5822 | case XML_XINCLUDE_END: |
| pcercuei | 0:03b5121a232e | 5823 | #ifdef LIBXML_DOCB_ENABLED |
| pcercuei | 0:03b5121a232e | 5824 | case XML_DOCB_DOCUMENT_NODE: |
| pcercuei | 0:03b5121a232e | 5825 | #endif |
| pcercuei | 0:03b5121a232e | 5826 | break; |
| pcercuei | 0:03b5121a232e | 5827 | case XML_ELEMENT_DECL: |
| pcercuei | 0:03b5121a232e | 5828 | case XML_ATTRIBUTE_DECL: |
| pcercuei | 0:03b5121a232e | 5829 | case XML_ENTITY_DECL: |
| pcercuei | 0:03b5121a232e | 5830 | break; |
| pcercuei | 0:03b5121a232e | 5831 | } |
| pcercuei | 0:03b5121a232e | 5832 | } |
| pcercuei | 0:03b5121a232e | 5833 | |
| pcercuei | 0:03b5121a232e | 5834 | /** |
| pcercuei | 0:03b5121a232e | 5835 | * xmlNodeAddContent: |
| pcercuei | 0:03b5121a232e | 5836 | * @cur: the node being modified |
| pcercuei | 0:03b5121a232e | 5837 | * @content: extra content |
| pcercuei | 0:03b5121a232e | 5838 | * |
| pcercuei | 0:03b5121a232e | 5839 | * Append the extra substring to the node content. |
| pcercuei | 0:03b5121a232e | 5840 | * NOTE: In contrast to xmlNodeSetContent(), @content is supposed to be |
| pcercuei | 0:03b5121a232e | 5841 | * raw text, so unescaped XML special chars are allowed, entity |
| pcercuei | 0:03b5121a232e | 5842 | * references are not supported. |
| pcercuei | 0:03b5121a232e | 5843 | */ |
| pcercuei | 0:03b5121a232e | 5844 | void |
| pcercuei | 0:03b5121a232e | 5845 | xmlNodeAddContent(xmlNodePtr cur, const xmlChar *content) { |
| pcercuei | 0:03b5121a232e | 5846 | int len; |
| pcercuei | 0:03b5121a232e | 5847 | |
| pcercuei | 0:03b5121a232e | 5848 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 5849 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 5850 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 5851 | "xmlNodeAddContent : node == NULL\n"); |
| pcercuei | 0:03b5121a232e | 5852 | #endif |
| pcercuei | 0:03b5121a232e | 5853 | return; |
| pcercuei | 0:03b5121a232e | 5854 | } |
| pcercuei | 0:03b5121a232e | 5855 | if (content == NULL) return; |
| pcercuei | 0:03b5121a232e | 5856 | len = xmlStrlen(content); |
| pcercuei | 0:03b5121a232e | 5857 | xmlNodeAddContentLen(cur, content, len); |
| pcercuei | 0:03b5121a232e | 5858 | } |
| pcercuei | 0:03b5121a232e | 5859 | |
| pcercuei | 0:03b5121a232e | 5860 | /** |
| pcercuei | 0:03b5121a232e | 5861 | * xmlTextMerge: |
| pcercuei | 0:03b5121a232e | 5862 | * @first: the first text node |
| pcercuei | 0:03b5121a232e | 5863 | * @second: the second text node being merged |
| pcercuei | 0:03b5121a232e | 5864 | * |
| pcercuei | 0:03b5121a232e | 5865 | * Merge two text nodes into one |
| pcercuei | 0:03b5121a232e | 5866 | * Returns the first text node augmented |
| pcercuei | 0:03b5121a232e | 5867 | */ |
| pcercuei | 0:03b5121a232e | 5868 | xmlNodePtr |
| pcercuei | 0:03b5121a232e | 5869 | xmlTextMerge(xmlNodePtr first, xmlNodePtr second) { |
| pcercuei | 0:03b5121a232e | 5870 | if (first == NULL) return(second); |
| pcercuei | 0:03b5121a232e | 5871 | if (second == NULL) return(first); |
| pcercuei | 0:03b5121a232e | 5872 | if (first->type != XML_TEXT_NODE) return(first); |
| pcercuei | 0:03b5121a232e | 5873 | if (second->type != XML_TEXT_NODE) return(first); |
| pcercuei | 0:03b5121a232e | 5874 | if (second->name != first->name) |
| pcercuei | 0:03b5121a232e | 5875 | return(first); |
| pcercuei | 0:03b5121a232e | 5876 | xmlNodeAddContent(first, second->content); |
| pcercuei | 0:03b5121a232e | 5877 | xmlUnlinkNode(second); |
| pcercuei | 0:03b5121a232e | 5878 | xmlFreeNode(second); |
| pcercuei | 0:03b5121a232e | 5879 | return(first); |
| pcercuei | 0:03b5121a232e | 5880 | } |
| pcercuei | 0:03b5121a232e | 5881 | |
| pcercuei | 0:03b5121a232e | 5882 | #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) |
| pcercuei | 0:03b5121a232e | 5883 | /** |
| pcercuei | 0:03b5121a232e | 5884 | * xmlGetNsList: |
| pcercuei | 0:03b5121a232e | 5885 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 5886 | * @node: the current node |
| pcercuei | 0:03b5121a232e | 5887 | * |
| pcercuei | 0:03b5121a232e | 5888 | * Search all the namespace applying to a given element. |
| pcercuei | 0:03b5121a232e | 5889 | * Returns an NULL terminated array of all the #xmlNsPtr found |
| pcercuei | 0:03b5121a232e | 5890 | * that need to be freed by the caller or NULL if no |
| pcercuei | 0:03b5121a232e | 5891 | * namespace if defined |
| pcercuei | 0:03b5121a232e | 5892 | */ |
| pcercuei | 0:03b5121a232e | 5893 | xmlNsPtr * |
| pcercuei | 0:03b5121a232e | 5894 | xmlGetNsList(const xmlDoc *doc ATTRIBUTE_UNUSED, const xmlNode *node) |
| pcercuei | 0:03b5121a232e | 5895 | { |
| pcercuei | 0:03b5121a232e | 5896 | xmlNsPtr cur; |
| pcercuei | 0:03b5121a232e | 5897 | xmlNsPtr *ret = NULL; |
| pcercuei | 0:03b5121a232e | 5898 | int nbns = 0; |
| pcercuei | 0:03b5121a232e | 5899 | int maxns = 10; |
| pcercuei | 0:03b5121a232e | 5900 | int i; |
| pcercuei | 0:03b5121a232e | 5901 | |
| pcercuei | 0:03b5121a232e | 5902 | if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) |
| pcercuei | 0:03b5121a232e | 5903 | return(NULL); |
| pcercuei | 0:03b5121a232e | 5904 | |
| pcercuei | 0:03b5121a232e | 5905 | while (node != NULL) { |
| pcercuei | 0:03b5121a232e | 5906 | if (node->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 5907 | cur = node->nsDef; |
| pcercuei | 0:03b5121a232e | 5908 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 5909 | if (ret == NULL) { |
| pcercuei | 0:03b5121a232e | 5910 | ret = |
| pcercuei | 0:03b5121a232e | 5911 | (xmlNsPtr *) xmlMalloc((maxns + 1) * |
| pcercuei | 0:03b5121a232e | 5912 | sizeof(xmlNsPtr)); |
| pcercuei | 0:03b5121a232e | 5913 | if (ret == NULL) { |
| pcercuei | 0:03b5121a232e | 5914 | xmlTreeErrMemory("getting namespace list"); |
| pcercuei | 0:03b5121a232e | 5915 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5916 | } |
| pcercuei | 0:03b5121a232e | 5917 | ret[nbns] = NULL; |
| pcercuei | 0:03b5121a232e | 5918 | } |
| pcercuei | 0:03b5121a232e | 5919 | for (i = 0; i < nbns; i++) { |
| pcercuei | 0:03b5121a232e | 5920 | if ((cur->prefix == ret[i]->prefix) || |
| pcercuei | 0:03b5121a232e | 5921 | (xmlStrEqual(cur->prefix, ret[i]->prefix))) |
| pcercuei | 0:03b5121a232e | 5922 | break; |
| pcercuei | 0:03b5121a232e | 5923 | } |
| pcercuei | 0:03b5121a232e | 5924 | if (i >= nbns) { |
| pcercuei | 0:03b5121a232e | 5925 | if (nbns >= maxns) { |
| pcercuei | 0:03b5121a232e | 5926 | maxns *= 2; |
| pcercuei | 0:03b5121a232e | 5927 | ret = (xmlNsPtr *) xmlRealloc(ret, |
| pcercuei | 0:03b5121a232e | 5928 | (maxns + |
| pcercuei | 0:03b5121a232e | 5929 | 1) * |
| pcercuei | 0:03b5121a232e | 5930 | sizeof(xmlNsPtr)); |
| pcercuei | 0:03b5121a232e | 5931 | if (ret == NULL) { |
| pcercuei | 0:03b5121a232e | 5932 | xmlTreeErrMemory("getting namespace list"); |
| pcercuei | 0:03b5121a232e | 5933 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5934 | } |
| pcercuei | 0:03b5121a232e | 5935 | } |
| pcercuei | 0:03b5121a232e | 5936 | ret[nbns++] = cur; |
| pcercuei | 0:03b5121a232e | 5937 | ret[nbns] = NULL; |
| pcercuei | 0:03b5121a232e | 5938 | } |
| pcercuei | 0:03b5121a232e | 5939 | |
| pcercuei | 0:03b5121a232e | 5940 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 5941 | } |
| pcercuei | 0:03b5121a232e | 5942 | } |
| pcercuei | 0:03b5121a232e | 5943 | node = node->parent; |
| pcercuei | 0:03b5121a232e | 5944 | } |
| pcercuei | 0:03b5121a232e | 5945 | return (ret); |
| pcercuei | 0:03b5121a232e | 5946 | } |
| pcercuei | 0:03b5121a232e | 5947 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 5948 | |
| pcercuei | 0:03b5121a232e | 5949 | /* |
| pcercuei | 0:03b5121a232e | 5950 | * xmlTreeEnsureXMLDecl: |
| pcercuei | 0:03b5121a232e | 5951 | * @doc: the doc |
| pcercuei | 0:03b5121a232e | 5952 | * |
| pcercuei | 0:03b5121a232e | 5953 | * Ensures that there is an XML namespace declaration on the doc. |
| pcercuei | 0:03b5121a232e | 5954 | * |
| pcercuei | 0:03b5121a232e | 5955 | * Returns the XML ns-struct or NULL on API and internal errors. |
| pcercuei | 0:03b5121a232e | 5956 | */ |
| pcercuei | 0:03b5121a232e | 5957 | static xmlNsPtr |
| pcercuei | 0:03b5121a232e | 5958 | xmlTreeEnsureXMLDecl(xmlDocPtr doc) |
| pcercuei | 0:03b5121a232e | 5959 | { |
| pcercuei | 0:03b5121a232e | 5960 | if (doc == NULL) |
| pcercuei | 0:03b5121a232e | 5961 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5962 | if (doc->oldNs != NULL) |
| pcercuei | 0:03b5121a232e | 5963 | return (doc->oldNs); |
| pcercuei | 0:03b5121a232e | 5964 | { |
| pcercuei | 0:03b5121a232e | 5965 | xmlNsPtr ns; |
| pcercuei | 0:03b5121a232e | 5966 | ns = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); |
| pcercuei | 0:03b5121a232e | 5967 | if (ns == NULL) { |
| pcercuei | 0:03b5121a232e | 5968 | xmlTreeErrMemory( |
| pcercuei | 0:03b5121a232e | 5969 | "allocating the XML namespace"); |
| pcercuei | 0:03b5121a232e | 5970 | return (NULL); |
| pcercuei | 0:03b5121a232e | 5971 | } |
| pcercuei | 0:03b5121a232e | 5972 | memset(ns, 0, sizeof(xmlNs)); |
| pcercuei | 0:03b5121a232e | 5973 | ns->type = XML_LOCAL_NAMESPACE; |
| pcercuei | 0:03b5121a232e | 5974 | ns->href = xmlStrdup(XML_XML_NAMESPACE); |
| pcercuei | 0:03b5121a232e | 5975 | ns->prefix = xmlStrdup((const xmlChar *)"xml"); |
| pcercuei | 0:03b5121a232e | 5976 | doc->oldNs = ns; |
| pcercuei | 0:03b5121a232e | 5977 | return (ns); |
| pcercuei | 0:03b5121a232e | 5978 | } |
| pcercuei | 0:03b5121a232e | 5979 | } |
| pcercuei | 0:03b5121a232e | 5980 | |
| pcercuei | 0:03b5121a232e | 5981 | /** |
| pcercuei | 0:03b5121a232e | 5982 | * xmlSearchNs: |
| pcercuei | 0:03b5121a232e | 5983 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 5984 | * @node: the current node |
| pcercuei | 0:03b5121a232e | 5985 | * @nameSpace: the namespace prefix |
| pcercuei | 0:03b5121a232e | 5986 | * |
| pcercuei | 0:03b5121a232e | 5987 | * Search a Ns registered under a given name space for a document. |
| pcercuei | 0:03b5121a232e | 5988 | * recurse on the parents until it finds the defined namespace |
| pcercuei | 0:03b5121a232e | 5989 | * or return NULL otherwise. |
| pcercuei | 0:03b5121a232e | 5990 | * @nameSpace can be NULL, this is a search for the default namespace. |
| pcercuei | 0:03b5121a232e | 5991 | * We don't allow to cross entities boundaries. If you don't declare |
| pcercuei | 0:03b5121a232e | 5992 | * the namespace within those you will be in troubles !!! A warning |
| pcercuei | 0:03b5121a232e | 5993 | * is generated to cover this case. |
| pcercuei | 0:03b5121a232e | 5994 | * |
| pcercuei | 0:03b5121a232e | 5995 | * Returns the namespace pointer or NULL. |
| pcercuei | 0:03b5121a232e | 5996 | */ |
| pcercuei | 0:03b5121a232e | 5997 | xmlNsPtr |
| pcercuei | 0:03b5121a232e | 5998 | xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace) { |
| pcercuei | 0:03b5121a232e | 5999 | |
| pcercuei | 0:03b5121a232e | 6000 | xmlNsPtr cur; |
| pcercuei | 0:03b5121a232e | 6001 | const xmlNode *orig = node; |
| pcercuei | 0:03b5121a232e | 6002 | |
| pcercuei | 0:03b5121a232e | 6003 | if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) return(NULL); |
| pcercuei | 0:03b5121a232e | 6004 | if ((nameSpace != NULL) && |
| pcercuei | 0:03b5121a232e | 6005 | (xmlStrEqual(nameSpace, (const xmlChar *)"xml"))) { |
| pcercuei | 0:03b5121a232e | 6006 | if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) { |
| pcercuei | 0:03b5121a232e | 6007 | /* |
| pcercuei | 0:03b5121a232e | 6008 | * The XML-1.0 namespace is normally held on the root |
| pcercuei | 0:03b5121a232e | 6009 | * element. In this case exceptionally create it on the |
| pcercuei | 0:03b5121a232e | 6010 | * node element. |
| pcercuei | 0:03b5121a232e | 6011 | */ |
| pcercuei | 0:03b5121a232e | 6012 | cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); |
| pcercuei | 0:03b5121a232e | 6013 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 6014 | xmlTreeErrMemory("searching namespace"); |
| pcercuei | 0:03b5121a232e | 6015 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6016 | } |
| pcercuei | 0:03b5121a232e | 6017 | memset(cur, 0, sizeof(xmlNs)); |
| pcercuei | 0:03b5121a232e | 6018 | cur->type = XML_LOCAL_NAMESPACE; |
| pcercuei | 0:03b5121a232e | 6019 | cur->href = xmlStrdup(XML_XML_NAMESPACE); |
| pcercuei | 0:03b5121a232e | 6020 | cur->prefix = xmlStrdup((const xmlChar *)"xml"); |
| pcercuei | 0:03b5121a232e | 6021 | cur->next = node->nsDef; |
| pcercuei | 0:03b5121a232e | 6022 | node->nsDef = cur; |
| pcercuei | 0:03b5121a232e | 6023 | return(cur); |
| pcercuei | 0:03b5121a232e | 6024 | } |
| pcercuei | 0:03b5121a232e | 6025 | if (doc == NULL) { |
| pcercuei | 0:03b5121a232e | 6026 | doc = node->doc; |
| pcercuei | 0:03b5121a232e | 6027 | if (doc == NULL) |
| pcercuei | 0:03b5121a232e | 6028 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6029 | } |
| pcercuei | 0:03b5121a232e | 6030 | /* |
| pcercuei | 0:03b5121a232e | 6031 | * Return the XML namespace declaration held by the doc. |
| pcercuei | 0:03b5121a232e | 6032 | */ |
| pcercuei | 0:03b5121a232e | 6033 | if (doc->oldNs == NULL) |
| pcercuei | 0:03b5121a232e | 6034 | return(xmlTreeEnsureXMLDecl(doc)); |
| pcercuei | 0:03b5121a232e | 6035 | else |
| pcercuei | 0:03b5121a232e | 6036 | return(doc->oldNs); |
| pcercuei | 0:03b5121a232e | 6037 | } |
| pcercuei | 0:03b5121a232e | 6038 | while (node != NULL) { |
| pcercuei | 0:03b5121a232e | 6039 | if ((node->type == XML_ENTITY_REF_NODE) || |
| pcercuei | 0:03b5121a232e | 6040 | (node->type == XML_ENTITY_NODE) || |
| pcercuei | 0:03b5121a232e | 6041 | (node->type == XML_ENTITY_DECL)) |
| pcercuei | 0:03b5121a232e | 6042 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6043 | if (node->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 6044 | cur = node->nsDef; |
| pcercuei | 0:03b5121a232e | 6045 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 6046 | if ((cur->prefix == NULL) && (nameSpace == NULL) && |
| pcercuei | 0:03b5121a232e | 6047 | (cur->href != NULL)) |
| pcercuei | 0:03b5121a232e | 6048 | return(cur); |
| pcercuei | 0:03b5121a232e | 6049 | if ((cur->prefix != NULL) && (nameSpace != NULL) && |
| pcercuei | 0:03b5121a232e | 6050 | (cur->href != NULL) && |
| pcercuei | 0:03b5121a232e | 6051 | (xmlStrEqual(cur->prefix, nameSpace))) |
| pcercuei | 0:03b5121a232e | 6052 | return(cur); |
| pcercuei | 0:03b5121a232e | 6053 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 6054 | } |
| pcercuei | 0:03b5121a232e | 6055 | if (orig != node) { |
| pcercuei | 0:03b5121a232e | 6056 | cur = node->ns; |
| pcercuei | 0:03b5121a232e | 6057 | if (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 6058 | if ((cur->prefix == NULL) && (nameSpace == NULL) && |
| pcercuei | 0:03b5121a232e | 6059 | (cur->href != NULL)) |
| pcercuei | 0:03b5121a232e | 6060 | return(cur); |
| pcercuei | 0:03b5121a232e | 6061 | if ((cur->prefix != NULL) && (nameSpace != NULL) && |
| pcercuei | 0:03b5121a232e | 6062 | (cur->href != NULL) && |
| pcercuei | 0:03b5121a232e | 6063 | (xmlStrEqual(cur->prefix, nameSpace))) |
| pcercuei | 0:03b5121a232e | 6064 | return(cur); |
| pcercuei | 0:03b5121a232e | 6065 | } |
| pcercuei | 0:03b5121a232e | 6066 | } |
| pcercuei | 0:03b5121a232e | 6067 | } |
| pcercuei | 0:03b5121a232e | 6068 | node = node->parent; |
| pcercuei | 0:03b5121a232e | 6069 | } |
| pcercuei | 0:03b5121a232e | 6070 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6071 | } |
| pcercuei | 0:03b5121a232e | 6072 | |
| pcercuei | 0:03b5121a232e | 6073 | /** |
| pcercuei | 0:03b5121a232e | 6074 | * xmlNsInScope: |
| pcercuei | 0:03b5121a232e | 6075 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 6076 | * @node: the current node |
| pcercuei | 0:03b5121a232e | 6077 | * @ancestor: the ancestor carrying the namespace |
| pcercuei | 0:03b5121a232e | 6078 | * @prefix: the namespace prefix |
| pcercuei | 0:03b5121a232e | 6079 | * |
| pcercuei | 0:03b5121a232e | 6080 | * Verify that the given namespace held on @ancestor is still in scope |
| pcercuei | 0:03b5121a232e | 6081 | * on node. |
| pcercuei | 0:03b5121a232e | 6082 | * |
| pcercuei | 0:03b5121a232e | 6083 | * Returns 1 if true, 0 if false and -1 in case of error. |
| pcercuei | 0:03b5121a232e | 6084 | */ |
| pcercuei | 0:03b5121a232e | 6085 | static int |
| pcercuei | 0:03b5121a232e | 6086 | xmlNsInScope(xmlDocPtr doc ATTRIBUTE_UNUSED, xmlNodePtr node, |
| pcercuei | 0:03b5121a232e | 6087 | xmlNodePtr ancestor, const xmlChar * prefix) |
| pcercuei | 0:03b5121a232e | 6088 | { |
| pcercuei | 0:03b5121a232e | 6089 | xmlNsPtr tst; |
| pcercuei | 0:03b5121a232e | 6090 | |
| pcercuei | 0:03b5121a232e | 6091 | while ((node != NULL) && (node != ancestor)) { |
| pcercuei | 0:03b5121a232e | 6092 | if ((node->type == XML_ENTITY_REF_NODE) || |
| pcercuei | 0:03b5121a232e | 6093 | (node->type == XML_ENTITY_NODE) || |
| pcercuei | 0:03b5121a232e | 6094 | (node->type == XML_ENTITY_DECL)) |
| pcercuei | 0:03b5121a232e | 6095 | return (-1); |
| pcercuei | 0:03b5121a232e | 6096 | if (node->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 6097 | tst = node->nsDef; |
| pcercuei | 0:03b5121a232e | 6098 | while (tst != NULL) { |
| pcercuei | 0:03b5121a232e | 6099 | if ((tst->prefix == NULL) |
| pcercuei | 0:03b5121a232e | 6100 | && (prefix == NULL)) |
| pcercuei | 0:03b5121a232e | 6101 | return (0); |
| pcercuei | 0:03b5121a232e | 6102 | if ((tst->prefix != NULL) |
| pcercuei | 0:03b5121a232e | 6103 | && (prefix != NULL) |
| pcercuei | 0:03b5121a232e | 6104 | && (xmlStrEqual(tst->prefix, prefix))) |
| pcercuei | 0:03b5121a232e | 6105 | return (0); |
| pcercuei | 0:03b5121a232e | 6106 | tst = tst->next; |
| pcercuei | 0:03b5121a232e | 6107 | } |
| pcercuei | 0:03b5121a232e | 6108 | } |
| pcercuei | 0:03b5121a232e | 6109 | node = node->parent; |
| pcercuei | 0:03b5121a232e | 6110 | } |
| pcercuei | 0:03b5121a232e | 6111 | if (node != ancestor) |
| pcercuei | 0:03b5121a232e | 6112 | return (-1); |
| pcercuei | 0:03b5121a232e | 6113 | return (1); |
| pcercuei | 0:03b5121a232e | 6114 | } |
| pcercuei | 0:03b5121a232e | 6115 | |
| pcercuei | 0:03b5121a232e | 6116 | /** |
| pcercuei | 0:03b5121a232e | 6117 | * xmlSearchNsByHref: |
| pcercuei | 0:03b5121a232e | 6118 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 6119 | * @node: the current node |
| pcercuei | 0:03b5121a232e | 6120 | * @href: the namespace value |
| pcercuei | 0:03b5121a232e | 6121 | * |
| pcercuei | 0:03b5121a232e | 6122 | * Search a Ns aliasing a given URI. Recurse on the parents until it finds |
| pcercuei | 0:03b5121a232e | 6123 | * the defined namespace or return NULL otherwise. |
| pcercuei | 0:03b5121a232e | 6124 | * Returns the namespace pointer or NULL. |
| pcercuei | 0:03b5121a232e | 6125 | */ |
| pcercuei | 0:03b5121a232e | 6126 | xmlNsPtr |
| pcercuei | 0:03b5121a232e | 6127 | xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const xmlChar * href) |
| pcercuei | 0:03b5121a232e | 6128 | { |
| pcercuei | 0:03b5121a232e | 6129 | xmlNsPtr cur; |
| pcercuei | 0:03b5121a232e | 6130 | xmlNodePtr orig = node; |
| pcercuei | 0:03b5121a232e | 6131 | int is_attr; |
| pcercuei | 0:03b5121a232e | 6132 | |
| pcercuei | 0:03b5121a232e | 6133 | if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) || (href == NULL)) |
| pcercuei | 0:03b5121a232e | 6134 | return (NULL); |
| pcercuei | 0:03b5121a232e | 6135 | if (xmlStrEqual(href, XML_XML_NAMESPACE)) { |
| pcercuei | 0:03b5121a232e | 6136 | /* |
| pcercuei | 0:03b5121a232e | 6137 | * Only the document can hold the XML spec namespace. |
| pcercuei | 0:03b5121a232e | 6138 | */ |
| pcercuei | 0:03b5121a232e | 6139 | if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) { |
| pcercuei | 0:03b5121a232e | 6140 | /* |
| pcercuei | 0:03b5121a232e | 6141 | * The XML-1.0 namespace is normally held on the root |
| pcercuei | 0:03b5121a232e | 6142 | * element. In this case exceptionally create it on the |
| pcercuei | 0:03b5121a232e | 6143 | * node element. |
| pcercuei | 0:03b5121a232e | 6144 | */ |
| pcercuei | 0:03b5121a232e | 6145 | cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); |
| pcercuei | 0:03b5121a232e | 6146 | if (cur == NULL) { |
| pcercuei | 0:03b5121a232e | 6147 | xmlTreeErrMemory("searching namespace"); |
| pcercuei | 0:03b5121a232e | 6148 | return (NULL); |
| pcercuei | 0:03b5121a232e | 6149 | } |
| pcercuei | 0:03b5121a232e | 6150 | memset(cur, 0, sizeof(xmlNs)); |
| pcercuei | 0:03b5121a232e | 6151 | cur->type = XML_LOCAL_NAMESPACE; |
| pcercuei | 0:03b5121a232e | 6152 | cur->href = xmlStrdup(XML_XML_NAMESPACE); |
| pcercuei | 0:03b5121a232e | 6153 | cur->prefix = xmlStrdup((const xmlChar *) "xml"); |
| pcercuei | 0:03b5121a232e | 6154 | cur->next = node->nsDef; |
| pcercuei | 0:03b5121a232e | 6155 | node->nsDef = cur; |
| pcercuei | 0:03b5121a232e | 6156 | return (cur); |
| pcercuei | 0:03b5121a232e | 6157 | } |
| pcercuei | 0:03b5121a232e | 6158 | if (doc == NULL) { |
| pcercuei | 0:03b5121a232e | 6159 | doc = node->doc; |
| pcercuei | 0:03b5121a232e | 6160 | if (doc == NULL) |
| pcercuei | 0:03b5121a232e | 6161 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6162 | } |
| pcercuei | 0:03b5121a232e | 6163 | /* |
| pcercuei | 0:03b5121a232e | 6164 | * Return the XML namespace declaration held by the doc. |
| pcercuei | 0:03b5121a232e | 6165 | */ |
| pcercuei | 0:03b5121a232e | 6166 | if (doc->oldNs == NULL) |
| pcercuei | 0:03b5121a232e | 6167 | return(xmlTreeEnsureXMLDecl(doc)); |
| pcercuei | 0:03b5121a232e | 6168 | else |
| pcercuei | 0:03b5121a232e | 6169 | return(doc->oldNs); |
| pcercuei | 0:03b5121a232e | 6170 | } |
| pcercuei | 0:03b5121a232e | 6171 | is_attr = (node->type == XML_ATTRIBUTE_NODE); |
| pcercuei | 0:03b5121a232e | 6172 | while (node != NULL) { |
| pcercuei | 0:03b5121a232e | 6173 | if ((node->type == XML_ENTITY_REF_NODE) || |
| pcercuei | 0:03b5121a232e | 6174 | (node->type == XML_ENTITY_NODE) || |
| pcercuei | 0:03b5121a232e | 6175 | (node->type == XML_ENTITY_DECL)) |
| pcercuei | 0:03b5121a232e | 6176 | return (NULL); |
| pcercuei | 0:03b5121a232e | 6177 | if (node->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 6178 | cur = node->nsDef; |
| pcercuei | 0:03b5121a232e | 6179 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 6180 | if ((cur->href != NULL) && (href != NULL) && |
| pcercuei | 0:03b5121a232e | 6181 | (xmlStrEqual(cur->href, href))) { |
| pcercuei | 0:03b5121a232e | 6182 | if (((!is_attr) || (cur->prefix != NULL)) && |
| pcercuei | 0:03b5121a232e | 6183 | (xmlNsInScope(doc, orig, node, cur->prefix) == 1)) |
| pcercuei | 0:03b5121a232e | 6184 | return (cur); |
| pcercuei | 0:03b5121a232e | 6185 | } |
| pcercuei | 0:03b5121a232e | 6186 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 6187 | } |
| pcercuei | 0:03b5121a232e | 6188 | if (orig != node) { |
| pcercuei | 0:03b5121a232e | 6189 | cur = node->ns; |
| pcercuei | 0:03b5121a232e | 6190 | if (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 6191 | if ((cur->href != NULL) && (href != NULL) && |
| pcercuei | 0:03b5121a232e | 6192 | (xmlStrEqual(cur->href, href))) { |
| pcercuei | 0:03b5121a232e | 6193 | if (((!is_attr) || (cur->prefix != NULL)) && |
| pcercuei | 0:03b5121a232e | 6194 | (xmlNsInScope(doc, orig, node, cur->prefix) == 1)) |
| pcercuei | 0:03b5121a232e | 6195 | return (cur); |
| pcercuei | 0:03b5121a232e | 6196 | } |
| pcercuei | 0:03b5121a232e | 6197 | } |
| pcercuei | 0:03b5121a232e | 6198 | } |
| pcercuei | 0:03b5121a232e | 6199 | } |
| pcercuei | 0:03b5121a232e | 6200 | node = node->parent; |
| pcercuei | 0:03b5121a232e | 6201 | } |
| pcercuei | 0:03b5121a232e | 6202 | return (NULL); |
| pcercuei | 0:03b5121a232e | 6203 | } |
| pcercuei | 0:03b5121a232e | 6204 | |
| pcercuei | 0:03b5121a232e | 6205 | /** |
| pcercuei | 0:03b5121a232e | 6206 | * xmlNewReconciliedNs: |
| pcercuei | 0:03b5121a232e | 6207 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 6208 | * @tree: a node expected to hold the new namespace |
| pcercuei | 0:03b5121a232e | 6209 | * @ns: the original namespace |
| pcercuei | 0:03b5121a232e | 6210 | * |
| pcercuei | 0:03b5121a232e | 6211 | * This function tries to locate a namespace definition in a tree |
| pcercuei | 0:03b5121a232e | 6212 | * ancestors, or create a new namespace definition node similar to |
| pcercuei | 0:03b5121a232e | 6213 | * @ns trying to reuse the same prefix. However if the given prefix is |
| pcercuei | 0:03b5121a232e | 6214 | * null (default namespace) or reused within the subtree defined by |
| pcercuei | 0:03b5121a232e | 6215 | * @tree or on one of its ancestors then a new prefix is generated. |
| pcercuei | 0:03b5121a232e | 6216 | * Returns the (new) namespace definition or NULL in case of error |
| pcercuei | 0:03b5121a232e | 6217 | */ |
| pcercuei | 0:03b5121a232e | 6218 | static xmlNsPtr |
| pcercuei | 0:03b5121a232e | 6219 | xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) { |
| pcercuei | 0:03b5121a232e | 6220 | xmlNsPtr def; |
| pcercuei | 0:03b5121a232e | 6221 | xmlChar prefix[50]; |
| pcercuei | 0:03b5121a232e | 6222 | int counter = 1; |
| pcercuei | 0:03b5121a232e | 6223 | |
| pcercuei | 0:03b5121a232e | 6224 | if ((tree == NULL) || (tree->type != XML_ELEMENT_NODE)) { |
| pcercuei | 0:03b5121a232e | 6225 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 6226 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 6227 | "xmlNewReconciliedNs : tree == NULL\n"); |
| pcercuei | 0:03b5121a232e | 6228 | #endif |
| pcercuei | 0:03b5121a232e | 6229 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6230 | } |
| pcercuei | 0:03b5121a232e | 6231 | if ((ns == NULL) || (ns->type != XML_NAMESPACE_DECL)) { |
| pcercuei | 0:03b5121a232e | 6232 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 6233 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 6234 | "xmlNewReconciliedNs : ns == NULL\n"); |
| pcercuei | 0:03b5121a232e | 6235 | #endif |
| pcercuei | 0:03b5121a232e | 6236 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6237 | } |
| pcercuei | 0:03b5121a232e | 6238 | /* |
| pcercuei | 0:03b5121a232e | 6239 | * Search an existing namespace definition inherited. |
| pcercuei | 0:03b5121a232e | 6240 | */ |
| pcercuei | 0:03b5121a232e | 6241 | def = xmlSearchNsByHref(doc, tree, ns->href); |
| pcercuei | 0:03b5121a232e | 6242 | if (def != NULL) |
| pcercuei | 0:03b5121a232e | 6243 | return(def); |
| pcercuei | 0:03b5121a232e | 6244 | |
| pcercuei | 0:03b5121a232e | 6245 | /* |
| pcercuei | 0:03b5121a232e | 6246 | * Find a close prefix which is not already in use. |
| pcercuei | 0:03b5121a232e | 6247 | * Let's strip namespace prefixes longer than 20 chars ! |
| pcercuei | 0:03b5121a232e | 6248 | */ |
| pcercuei | 0:03b5121a232e | 6249 | if (ns->prefix == NULL) |
| pcercuei | 0:03b5121a232e | 6250 | snprintf((char *) prefix, sizeof(prefix), "default"); |
| pcercuei | 0:03b5121a232e | 6251 | else |
| pcercuei | 0:03b5121a232e | 6252 | snprintf((char *) prefix, sizeof(prefix), "%.20s", (char *)ns->prefix); |
| pcercuei | 0:03b5121a232e | 6253 | |
| pcercuei | 0:03b5121a232e | 6254 | def = xmlSearchNs(doc, tree, prefix); |
| pcercuei | 0:03b5121a232e | 6255 | while (def != NULL) { |
| pcercuei | 0:03b5121a232e | 6256 | if (counter > 1000) return(NULL); |
| pcercuei | 0:03b5121a232e | 6257 | if (ns->prefix == NULL) |
| pcercuei | 0:03b5121a232e | 6258 | snprintf((char *) prefix, sizeof(prefix), "default%d", counter++); |
| pcercuei | 0:03b5121a232e | 6259 | else |
| pcercuei | 0:03b5121a232e | 6260 | snprintf((char *) prefix, sizeof(prefix), "%.20s%d", |
| pcercuei | 0:03b5121a232e | 6261 | (char *)ns->prefix, counter++); |
| pcercuei | 0:03b5121a232e | 6262 | def = xmlSearchNs(doc, tree, prefix); |
| pcercuei | 0:03b5121a232e | 6263 | } |
| pcercuei | 0:03b5121a232e | 6264 | |
| pcercuei | 0:03b5121a232e | 6265 | /* |
| pcercuei | 0:03b5121a232e | 6266 | * OK, now we are ready to create a new one. |
| pcercuei | 0:03b5121a232e | 6267 | */ |
| pcercuei | 0:03b5121a232e | 6268 | def = xmlNewNs(tree, ns->href, prefix); |
| pcercuei | 0:03b5121a232e | 6269 | return(def); |
| pcercuei | 0:03b5121a232e | 6270 | } |
| pcercuei | 0:03b5121a232e | 6271 | |
| pcercuei | 0:03b5121a232e | 6272 | #ifdef LIBXML_TREE_ENABLED |
| pcercuei | 0:03b5121a232e | 6273 | /** |
| pcercuei | 0:03b5121a232e | 6274 | * xmlReconciliateNs: |
| pcercuei | 0:03b5121a232e | 6275 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 6276 | * @tree: a node defining the subtree to reconciliate |
| pcercuei | 0:03b5121a232e | 6277 | * |
| pcercuei | 0:03b5121a232e | 6278 | * This function checks that all the namespaces declared within the given |
| pcercuei | 0:03b5121a232e | 6279 | * tree are properly declared. This is needed for example after Copy or Cut |
| pcercuei | 0:03b5121a232e | 6280 | * and then paste operations. The subtree may still hold pointers to |
| pcercuei | 0:03b5121a232e | 6281 | * namespace declarations outside the subtree or invalid/masked. As much |
| pcercuei | 0:03b5121a232e | 6282 | * as possible the function try to reuse the existing namespaces found in |
| pcercuei | 0:03b5121a232e | 6283 | * the new environment. If not possible the new namespaces are redeclared |
| pcercuei | 0:03b5121a232e | 6284 | * on @tree at the top of the given subtree. |
| pcercuei | 0:03b5121a232e | 6285 | * Returns the number of namespace declarations created or -1 in case of error. |
| pcercuei | 0:03b5121a232e | 6286 | */ |
| pcercuei | 0:03b5121a232e | 6287 | int |
| pcercuei | 0:03b5121a232e | 6288 | xmlReconciliateNs(xmlDocPtr doc, xmlNodePtr tree) { |
| pcercuei | 0:03b5121a232e | 6289 | xmlNsPtr *oldNs = NULL; |
| pcercuei | 0:03b5121a232e | 6290 | xmlNsPtr *newNs = NULL; |
| pcercuei | 0:03b5121a232e | 6291 | int sizeCache = 0; |
| pcercuei | 0:03b5121a232e | 6292 | int nbCache = 0; |
| pcercuei | 0:03b5121a232e | 6293 | |
| pcercuei | 0:03b5121a232e | 6294 | xmlNsPtr n; |
| pcercuei | 0:03b5121a232e | 6295 | xmlNodePtr node = tree; |
| pcercuei | 0:03b5121a232e | 6296 | xmlAttrPtr attr; |
| pcercuei | 0:03b5121a232e | 6297 | int ret = 0, i; |
| pcercuei | 0:03b5121a232e | 6298 | |
| pcercuei | 0:03b5121a232e | 6299 | if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) return(-1); |
| pcercuei | 0:03b5121a232e | 6300 | if ((doc == NULL) || (doc->type != XML_DOCUMENT_NODE)) return(-1); |
| pcercuei | 0:03b5121a232e | 6301 | if (node->doc != doc) return(-1); |
| pcercuei | 0:03b5121a232e | 6302 | while (node != NULL) { |
| pcercuei | 0:03b5121a232e | 6303 | /* |
| pcercuei | 0:03b5121a232e | 6304 | * Reconciliate the node namespace |
| pcercuei | 0:03b5121a232e | 6305 | */ |
| pcercuei | 0:03b5121a232e | 6306 | if (node->ns != NULL) { |
| pcercuei | 0:03b5121a232e | 6307 | /* |
| pcercuei | 0:03b5121a232e | 6308 | * initialize the cache if needed |
| pcercuei | 0:03b5121a232e | 6309 | */ |
| pcercuei | 0:03b5121a232e | 6310 | if (sizeCache == 0) { |
| pcercuei | 0:03b5121a232e | 6311 | sizeCache = 10; |
| pcercuei | 0:03b5121a232e | 6312 | oldNs = (xmlNsPtr *) xmlMalloc(sizeCache * |
| pcercuei | 0:03b5121a232e | 6313 | sizeof(xmlNsPtr)); |
| pcercuei | 0:03b5121a232e | 6314 | if (oldNs == NULL) { |
| pcercuei | 0:03b5121a232e | 6315 | xmlTreeErrMemory("fixing namespaces"); |
| pcercuei | 0:03b5121a232e | 6316 | return(-1); |
| pcercuei | 0:03b5121a232e | 6317 | } |
| pcercuei | 0:03b5121a232e | 6318 | newNs = (xmlNsPtr *) xmlMalloc(sizeCache * |
| pcercuei | 0:03b5121a232e | 6319 | sizeof(xmlNsPtr)); |
| pcercuei | 0:03b5121a232e | 6320 | if (newNs == NULL) { |
| pcercuei | 0:03b5121a232e | 6321 | xmlTreeErrMemory("fixing namespaces"); |
| pcercuei | 0:03b5121a232e | 6322 | xmlFree(oldNs); |
| pcercuei | 0:03b5121a232e | 6323 | return(-1); |
| pcercuei | 0:03b5121a232e | 6324 | } |
| pcercuei | 0:03b5121a232e | 6325 | } |
| pcercuei | 0:03b5121a232e | 6326 | for (i = 0;i < nbCache;i++) { |
| pcercuei | 0:03b5121a232e | 6327 | if (oldNs[i] == node->ns) { |
| pcercuei | 0:03b5121a232e | 6328 | node->ns = newNs[i]; |
| pcercuei | 0:03b5121a232e | 6329 | break; |
| pcercuei | 0:03b5121a232e | 6330 | } |
| pcercuei | 0:03b5121a232e | 6331 | } |
| pcercuei | 0:03b5121a232e | 6332 | if (i == nbCache) { |
| pcercuei | 0:03b5121a232e | 6333 | /* |
| pcercuei | 0:03b5121a232e | 6334 | * OK we need to recreate a new namespace definition |
| pcercuei | 0:03b5121a232e | 6335 | */ |
| pcercuei | 0:03b5121a232e | 6336 | n = xmlNewReconciliedNs(doc, tree, node->ns); |
| pcercuei | 0:03b5121a232e | 6337 | if (n != NULL) { /* :-( what if else ??? */ |
| pcercuei | 0:03b5121a232e | 6338 | /* |
| pcercuei | 0:03b5121a232e | 6339 | * check if we need to grow the cache buffers. |
| pcercuei | 0:03b5121a232e | 6340 | */ |
| pcercuei | 0:03b5121a232e | 6341 | if (sizeCache <= nbCache) { |
| pcercuei | 0:03b5121a232e | 6342 | sizeCache *= 2; |
| pcercuei | 0:03b5121a232e | 6343 | oldNs = (xmlNsPtr *) xmlRealloc(oldNs, sizeCache * |
| pcercuei | 0:03b5121a232e | 6344 | sizeof(xmlNsPtr)); |
| pcercuei | 0:03b5121a232e | 6345 | if (oldNs == NULL) { |
| pcercuei | 0:03b5121a232e | 6346 | xmlTreeErrMemory("fixing namespaces"); |
| pcercuei | 0:03b5121a232e | 6347 | xmlFree(newNs); |
| pcercuei | 0:03b5121a232e | 6348 | return(-1); |
| pcercuei | 0:03b5121a232e | 6349 | } |
| pcercuei | 0:03b5121a232e | 6350 | newNs = (xmlNsPtr *) xmlRealloc(newNs, sizeCache * |
| pcercuei | 0:03b5121a232e | 6351 | sizeof(xmlNsPtr)); |
| pcercuei | 0:03b5121a232e | 6352 | if (newNs == NULL) { |
| pcercuei | 0:03b5121a232e | 6353 | xmlTreeErrMemory("fixing namespaces"); |
| pcercuei | 0:03b5121a232e | 6354 | xmlFree(oldNs); |
| pcercuei | 0:03b5121a232e | 6355 | return(-1); |
| pcercuei | 0:03b5121a232e | 6356 | } |
| pcercuei | 0:03b5121a232e | 6357 | } |
| pcercuei | 0:03b5121a232e | 6358 | newNs[nbCache] = n; |
| pcercuei | 0:03b5121a232e | 6359 | oldNs[nbCache++] = node->ns; |
| pcercuei | 0:03b5121a232e | 6360 | node->ns = n; |
| pcercuei | 0:03b5121a232e | 6361 | } |
| pcercuei | 0:03b5121a232e | 6362 | } |
| pcercuei | 0:03b5121a232e | 6363 | } |
| pcercuei | 0:03b5121a232e | 6364 | /* |
| pcercuei | 0:03b5121a232e | 6365 | * now check for namespace hold by attributes on the node. |
| pcercuei | 0:03b5121a232e | 6366 | */ |
| pcercuei | 0:03b5121a232e | 6367 | if (node->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 6368 | attr = node->properties; |
| pcercuei | 0:03b5121a232e | 6369 | while (attr != NULL) { |
| pcercuei | 0:03b5121a232e | 6370 | if (attr->ns != NULL) { |
| pcercuei | 0:03b5121a232e | 6371 | /* |
| pcercuei | 0:03b5121a232e | 6372 | * initialize the cache if needed |
| pcercuei | 0:03b5121a232e | 6373 | */ |
| pcercuei | 0:03b5121a232e | 6374 | if (sizeCache == 0) { |
| pcercuei | 0:03b5121a232e | 6375 | sizeCache = 10; |
| pcercuei | 0:03b5121a232e | 6376 | oldNs = (xmlNsPtr *) xmlMalloc(sizeCache * |
| pcercuei | 0:03b5121a232e | 6377 | sizeof(xmlNsPtr)); |
| pcercuei | 0:03b5121a232e | 6378 | if (oldNs == NULL) { |
| pcercuei | 0:03b5121a232e | 6379 | xmlTreeErrMemory("fixing namespaces"); |
| pcercuei | 0:03b5121a232e | 6380 | return(-1); |
| pcercuei | 0:03b5121a232e | 6381 | } |
| pcercuei | 0:03b5121a232e | 6382 | newNs = (xmlNsPtr *) xmlMalloc(sizeCache * |
| pcercuei | 0:03b5121a232e | 6383 | sizeof(xmlNsPtr)); |
| pcercuei | 0:03b5121a232e | 6384 | if (newNs == NULL) { |
| pcercuei | 0:03b5121a232e | 6385 | xmlTreeErrMemory("fixing namespaces"); |
| pcercuei | 0:03b5121a232e | 6386 | xmlFree(oldNs); |
| pcercuei | 0:03b5121a232e | 6387 | return(-1); |
| pcercuei | 0:03b5121a232e | 6388 | } |
| pcercuei | 0:03b5121a232e | 6389 | } |
| pcercuei | 0:03b5121a232e | 6390 | for (i = 0;i < nbCache;i++) { |
| pcercuei | 0:03b5121a232e | 6391 | if (oldNs[i] == attr->ns) { |
| pcercuei | 0:03b5121a232e | 6392 | attr->ns = newNs[i]; |
| pcercuei | 0:03b5121a232e | 6393 | break; |
| pcercuei | 0:03b5121a232e | 6394 | } |
| pcercuei | 0:03b5121a232e | 6395 | } |
| pcercuei | 0:03b5121a232e | 6396 | if (i == nbCache) { |
| pcercuei | 0:03b5121a232e | 6397 | /* |
| pcercuei | 0:03b5121a232e | 6398 | * OK we need to recreate a new namespace definition |
| pcercuei | 0:03b5121a232e | 6399 | */ |
| pcercuei | 0:03b5121a232e | 6400 | n = xmlNewReconciliedNs(doc, tree, attr->ns); |
| pcercuei | 0:03b5121a232e | 6401 | if (n != NULL) { /* :-( what if else ??? */ |
| pcercuei | 0:03b5121a232e | 6402 | /* |
| pcercuei | 0:03b5121a232e | 6403 | * check if we need to grow the cache buffers. |
| pcercuei | 0:03b5121a232e | 6404 | */ |
| pcercuei | 0:03b5121a232e | 6405 | if (sizeCache <= nbCache) { |
| pcercuei | 0:03b5121a232e | 6406 | sizeCache *= 2; |
| pcercuei | 0:03b5121a232e | 6407 | oldNs = (xmlNsPtr *) xmlRealloc(oldNs, |
| pcercuei | 0:03b5121a232e | 6408 | sizeCache * sizeof(xmlNsPtr)); |
| pcercuei | 0:03b5121a232e | 6409 | if (oldNs == NULL) { |
| pcercuei | 0:03b5121a232e | 6410 | xmlTreeErrMemory("fixing namespaces"); |
| pcercuei | 0:03b5121a232e | 6411 | xmlFree(newNs); |
| pcercuei | 0:03b5121a232e | 6412 | return(-1); |
| pcercuei | 0:03b5121a232e | 6413 | } |
| pcercuei | 0:03b5121a232e | 6414 | newNs = (xmlNsPtr *) xmlRealloc(newNs, |
| pcercuei | 0:03b5121a232e | 6415 | sizeCache * sizeof(xmlNsPtr)); |
| pcercuei | 0:03b5121a232e | 6416 | if (newNs == NULL) { |
| pcercuei | 0:03b5121a232e | 6417 | xmlTreeErrMemory("fixing namespaces"); |
| pcercuei | 0:03b5121a232e | 6418 | xmlFree(oldNs); |
| pcercuei | 0:03b5121a232e | 6419 | return(-1); |
| pcercuei | 0:03b5121a232e | 6420 | } |
| pcercuei | 0:03b5121a232e | 6421 | } |
| pcercuei | 0:03b5121a232e | 6422 | newNs[nbCache] = n; |
| pcercuei | 0:03b5121a232e | 6423 | oldNs[nbCache++] = attr->ns; |
| pcercuei | 0:03b5121a232e | 6424 | attr->ns = n; |
| pcercuei | 0:03b5121a232e | 6425 | } |
| pcercuei | 0:03b5121a232e | 6426 | } |
| pcercuei | 0:03b5121a232e | 6427 | } |
| pcercuei | 0:03b5121a232e | 6428 | attr = attr->next; |
| pcercuei | 0:03b5121a232e | 6429 | } |
| pcercuei | 0:03b5121a232e | 6430 | } |
| pcercuei | 0:03b5121a232e | 6431 | |
| pcercuei | 0:03b5121a232e | 6432 | /* |
| pcercuei | 0:03b5121a232e | 6433 | * Browse the full subtree, deep first |
| pcercuei | 0:03b5121a232e | 6434 | */ |
| pcercuei | 0:03b5121a232e | 6435 | if ((node->children != NULL) && (node->type != XML_ENTITY_REF_NODE)) { |
| pcercuei | 0:03b5121a232e | 6436 | /* deep first */ |
| pcercuei | 0:03b5121a232e | 6437 | node = node->children; |
| pcercuei | 0:03b5121a232e | 6438 | } else if ((node != tree) && (node->next != NULL)) { |
| pcercuei | 0:03b5121a232e | 6439 | /* then siblings */ |
| pcercuei | 0:03b5121a232e | 6440 | node = node->next; |
| pcercuei | 0:03b5121a232e | 6441 | } else if (node != tree) { |
| pcercuei | 0:03b5121a232e | 6442 | /* go up to parents->next if needed */ |
| pcercuei | 0:03b5121a232e | 6443 | while (node != tree) { |
| pcercuei | 0:03b5121a232e | 6444 | if (node->parent != NULL) |
| pcercuei | 0:03b5121a232e | 6445 | node = node->parent; |
| pcercuei | 0:03b5121a232e | 6446 | if ((node != tree) && (node->next != NULL)) { |
| pcercuei | 0:03b5121a232e | 6447 | node = node->next; |
| pcercuei | 0:03b5121a232e | 6448 | break; |
| pcercuei | 0:03b5121a232e | 6449 | } |
| pcercuei | 0:03b5121a232e | 6450 | if (node->parent == NULL) { |
| pcercuei | 0:03b5121a232e | 6451 | node = NULL; |
| pcercuei | 0:03b5121a232e | 6452 | break; |
| pcercuei | 0:03b5121a232e | 6453 | } |
| pcercuei | 0:03b5121a232e | 6454 | } |
| pcercuei | 0:03b5121a232e | 6455 | /* exit condition */ |
| pcercuei | 0:03b5121a232e | 6456 | if (node == tree) |
| pcercuei | 0:03b5121a232e | 6457 | node = NULL; |
| pcercuei | 0:03b5121a232e | 6458 | } else |
| pcercuei | 0:03b5121a232e | 6459 | break; |
| pcercuei | 0:03b5121a232e | 6460 | } |
| pcercuei | 0:03b5121a232e | 6461 | if (oldNs != NULL) |
| pcercuei | 0:03b5121a232e | 6462 | xmlFree(oldNs); |
| pcercuei | 0:03b5121a232e | 6463 | if (newNs != NULL) |
| pcercuei | 0:03b5121a232e | 6464 | xmlFree(newNs); |
| pcercuei | 0:03b5121a232e | 6465 | return(ret); |
| pcercuei | 0:03b5121a232e | 6466 | } |
| pcercuei | 0:03b5121a232e | 6467 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 6468 | |
| pcercuei | 0:03b5121a232e | 6469 | static xmlAttrPtr |
| pcercuei | 0:03b5121a232e | 6470 | xmlGetPropNodeInternal(const xmlNode *node, const xmlChar *name, |
| pcercuei | 0:03b5121a232e | 6471 | const xmlChar *nsName, int useDTD) |
| pcercuei | 0:03b5121a232e | 6472 | { |
| pcercuei | 0:03b5121a232e | 6473 | xmlAttrPtr prop; |
| pcercuei | 0:03b5121a232e | 6474 | |
| pcercuei | 0:03b5121a232e | 6475 | if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) |
| pcercuei | 0:03b5121a232e | 6476 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6477 | |
| pcercuei | 0:03b5121a232e | 6478 | if (node->properties != NULL) { |
| pcercuei | 0:03b5121a232e | 6479 | prop = node->properties; |
| pcercuei | 0:03b5121a232e | 6480 | if (nsName == NULL) { |
| pcercuei | 0:03b5121a232e | 6481 | /* |
| pcercuei | 0:03b5121a232e | 6482 | * We want the attr to be in no namespace. |
| pcercuei | 0:03b5121a232e | 6483 | */ |
| pcercuei | 0:03b5121a232e | 6484 | do { |
| pcercuei | 0:03b5121a232e | 6485 | if ((prop->ns == NULL) && xmlStrEqual(prop->name, name)) { |
| pcercuei | 0:03b5121a232e | 6486 | return(prop); |
| pcercuei | 0:03b5121a232e | 6487 | } |
| pcercuei | 0:03b5121a232e | 6488 | prop = prop->next; |
| pcercuei | 0:03b5121a232e | 6489 | } while (prop != NULL); |
| pcercuei | 0:03b5121a232e | 6490 | } else { |
| pcercuei | 0:03b5121a232e | 6491 | /* |
| pcercuei | 0:03b5121a232e | 6492 | * We want the attr to be in the specified namespace. |
| pcercuei | 0:03b5121a232e | 6493 | */ |
| pcercuei | 0:03b5121a232e | 6494 | do { |
| pcercuei | 0:03b5121a232e | 6495 | if ((prop->ns != NULL) && xmlStrEqual(prop->name, name) && |
| pcercuei | 0:03b5121a232e | 6496 | ((prop->ns->href == nsName) || |
| pcercuei | 0:03b5121a232e | 6497 | xmlStrEqual(prop->ns->href, nsName))) |
| pcercuei | 0:03b5121a232e | 6498 | { |
| pcercuei | 0:03b5121a232e | 6499 | return(prop); |
| pcercuei | 0:03b5121a232e | 6500 | } |
| pcercuei | 0:03b5121a232e | 6501 | prop = prop->next; |
| pcercuei | 0:03b5121a232e | 6502 | } while (prop != NULL); |
| pcercuei | 0:03b5121a232e | 6503 | } |
| pcercuei | 0:03b5121a232e | 6504 | } |
| pcercuei | 0:03b5121a232e | 6505 | |
| pcercuei | 0:03b5121a232e | 6506 | #ifdef LIBXML_TREE_ENABLED |
| pcercuei | 0:03b5121a232e | 6507 | if (! useDTD) |
| pcercuei | 0:03b5121a232e | 6508 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6509 | /* |
| pcercuei | 0:03b5121a232e | 6510 | * Check if there is a default/fixed attribute declaration in |
| pcercuei | 0:03b5121a232e | 6511 | * the internal or external subset. |
| pcercuei | 0:03b5121a232e | 6512 | */ |
| pcercuei | 0:03b5121a232e | 6513 | if ((node->doc != NULL) && (node->doc->intSubset != NULL)) { |
| pcercuei | 0:03b5121a232e | 6514 | xmlDocPtr doc = node->doc; |
| pcercuei | 0:03b5121a232e | 6515 | xmlAttributePtr attrDecl = NULL; |
| pcercuei | 0:03b5121a232e | 6516 | xmlChar *elemQName, *tmpstr = NULL; |
| pcercuei | 0:03b5121a232e | 6517 | |
| pcercuei | 0:03b5121a232e | 6518 | /* |
| pcercuei | 0:03b5121a232e | 6519 | * We need the QName of the element for the DTD-lookup. |
| pcercuei | 0:03b5121a232e | 6520 | */ |
| pcercuei | 0:03b5121a232e | 6521 | if ((node->ns != NULL) && (node->ns->prefix != NULL)) { |
| pcercuei | 0:03b5121a232e | 6522 | tmpstr = xmlStrdup(node->ns->prefix); |
| pcercuei | 0:03b5121a232e | 6523 | tmpstr = xmlStrcat(tmpstr, BAD_CAST ":"); |
| pcercuei | 0:03b5121a232e | 6524 | tmpstr = xmlStrcat(tmpstr, node->name); |
| pcercuei | 0:03b5121a232e | 6525 | if (tmpstr == NULL) |
| pcercuei | 0:03b5121a232e | 6526 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6527 | elemQName = tmpstr; |
| pcercuei | 0:03b5121a232e | 6528 | } else |
| pcercuei | 0:03b5121a232e | 6529 | elemQName = (xmlChar *) node->name; |
| pcercuei | 0:03b5121a232e | 6530 | if (nsName == NULL) { |
| pcercuei | 0:03b5121a232e | 6531 | /* |
| pcercuei | 0:03b5121a232e | 6532 | * The common and nice case: Attr in no namespace. |
| pcercuei | 0:03b5121a232e | 6533 | */ |
| pcercuei | 0:03b5121a232e | 6534 | attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, |
| pcercuei | 0:03b5121a232e | 6535 | elemQName, name, NULL); |
| pcercuei | 0:03b5121a232e | 6536 | if ((attrDecl == NULL) && (doc->extSubset != NULL)) { |
| pcercuei | 0:03b5121a232e | 6537 | attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, |
| pcercuei | 0:03b5121a232e | 6538 | elemQName, name, NULL); |
| pcercuei | 0:03b5121a232e | 6539 | } |
| pcercuei | 0:03b5121a232e | 6540 | } else { |
| pcercuei | 0:03b5121a232e | 6541 | xmlNsPtr *nsList, *cur; |
| pcercuei | 0:03b5121a232e | 6542 | |
| pcercuei | 0:03b5121a232e | 6543 | /* |
| pcercuei | 0:03b5121a232e | 6544 | * The ugly case: Search using the prefixes of in-scope |
| pcercuei | 0:03b5121a232e | 6545 | * ns-decls corresponding to @nsName. |
| pcercuei | 0:03b5121a232e | 6546 | */ |
| pcercuei | 0:03b5121a232e | 6547 | nsList = xmlGetNsList(node->doc, node); |
| pcercuei | 0:03b5121a232e | 6548 | if (nsList == NULL) { |
| pcercuei | 0:03b5121a232e | 6549 | if (tmpstr != NULL) |
| pcercuei | 0:03b5121a232e | 6550 | xmlFree(tmpstr); |
| pcercuei | 0:03b5121a232e | 6551 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6552 | } |
| pcercuei | 0:03b5121a232e | 6553 | cur = nsList; |
| pcercuei | 0:03b5121a232e | 6554 | while (*cur != NULL) { |
| pcercuei | 0:03b5121a232e | 6555 | if (xmlStrEqual((*cur)->href, nsName)) { |
| pcercuei | 0:03b5121a232e | 6556 | attrDecl = xmlGetDtdQAttrDesc(doc->intSubset, elemQName, |
| pcercuei | 0:03b5121a232e | 6557 | name, (*cur)->prefix); |
| pcercuei | 0:03b5121a232e | 6558 | if (attrDecl) |
| pcercuei | 0:03b5121a232e | 6559 | break; |
| pcercuei | 0:03b5121a232e | 6560 | if (doc->extSubset != NULL) { |
| pcercuei | 0:03b5121a232e | 6561 | attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, elemQName, |
| pcercuei | 0:03b5121a232e | 6562 | name, (*cur)->prefix); |
| pcercuei | 0:03b5121a232e | 6563 | if (attrDecl) |
| pcercuei | 0:03b5121a232e | 6564 | break; |
| pcercuei | 0:03b5121a232e | 6565 | } |
| pcercuei | 0:03b5121a232e | 6566 | } |
| pcercuei | 0:03b5121a232e | 6567 | cur++; |
| pcercuei | 0:03b5121a232e | 6568 | } |
| pcercuei | 0:03b5121a232e | 6569 | xmlFree(nsList); |
| pcercuei | 0:03b5121a232e | 6570 | } |
| pcercuei | 0:03b5121a232e | 6571 | if (tmpstr != NULL) |
| pcercuei | 0:03b5121a232e | 6572 | xmlFree(tmpstr); |
| pcercuei | 0:03b5121a232e | 6573 | /* |
| pcercuei | 0:03b5121a232e | 6574 | * Only default/fixed attrs are relevant. |
| pcercuei | 0:03b5121a232e | 6575 | */ |
| pcercuei | 0:03b5121a232e | 6576 | if ((attrDecl != NULL) && (attrDecl->defaultValue != NULL)) |
| pcercuei | 0:03b5121a232e | 6577 | return((xmlAttrPtr) attrDecl); |
| pcercuei | 0:03b5121a232e | 6578 | } |
| pcercuei | 0:03b5121a232e | 6579 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 6580 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6581 | } |
| pcercuei | 0:03b5121a232e | 6582 | |
| pcercuei | 0:03b5121a232e | 6583 | static xmlChar* |
| pcercuei | 0:03b5121a232e | 6584 | xmlGetPropNodeValueInternal(const xmlAttr *prop) |
| pcercuei | 0:03b5121a232e | 6585 | { |
| pcercuei | 0:03b5121a232e | 6586 | if (prop == NULL) |
| pcercuei | 0:03b5121a232e | 6587 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6588 | if (prop->type == XML_ATTRIBUTE_NODE) { |
| pcercuei | 0:03b5121a232e | 6589 | /* |
| pcercuei | 0:03b5121a232e | 6590 | * Note that we return at least the empty string. |
| pcercuei | 0:03b5121a232e | 6591 | * TODO: Do we really always want that? |
| pcercuei | 0:03b5121a232e | 6592 | */ |
| pcercuei | 0:03b5121a232e | 6593 | if (prop->children != NULL) { |
| pcercuei | 0:03b5121a232e | 6594 | if ((prop->children->next == NULL) && |
| pcercuei | 0:03b5121a232e | 6595 | ((prop->children->type == XML_TEXT_NODE) || |
| pcercuei | 0:03b5121a232e | 6596 | (prop->children->type == XML_CDATA_SECTION_NODE))) |
| pcercuei | 0:03b5121a232e | 6597 | { |
| pcercuei | 0:03b5121a232e | 6598 | /* |
| pcercuei | 0:03b5121a232e | 6599 | * Optimization for the common case: only 1 text node. |
| pcercuei | 0:03b5121a232e | 6600 | */ |
| pcercuei | 0:03b5121a232e | 6601 | return(xmlStrdup(prop->children->content)); |
| pcercuei | 0:03b5121a232e | 6602 | } else { |
| pcercuei | 0:03b5121a232e | 6603 | xmlChar *ret; |
| pcercuei | 0:03b5121a232e | 6604 | |
| pcercuei | 0:03b5121a232e | 6605 | ret = xmlNodeListGetString(prop->doc, prop->children, 1); |
| pcercuei | 0:03b5121a232e | 6606 | if (ret != NULL) |
| pcercuei | 0:03b5121a232e | 6607 | return(ret); |
| pcercuei | 0:03b5121a232e | 6608 | } |
| pcercuei | 0:03b5121a232e | 6609 | } |
| pcercuei | 0:03b5121a232e | 6610 | return(xmlStrdup((xmlChar *)"")); |
| pcercuei | 0:03b5121a232e | 6611 | } else if (prop->type == XML_ATTRIBUTE_DECL) { |
| pcercuei | 0:03b5121a232e | 6612 | return(xmlStrdup(((xmlAttributePtr)prop)->defaultValue)); |
| pcercuei | 0:03b5121a232e | 6613 | } |
| pcercuei | 0:03b5121a232e | 6614 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6615 | } |
| pcercuei | 0:03b5121a232e | 6616 | |
| pcercuei | 0:03b5121a232e | 6617 | /** |
| pcercuei | 0:03b5121a232e | 6618 | * xmlHasProp: |
| pcercuei | 0:03b5121a232e | 6619 | * @node: the node |
| pcercuei | 0:03b5121a232e | 6620 | * @name: the attribute name |
| pcercuei | 0:03b5121a232e | 6621 | * |
| pcercuei | 0:03b5121a232e | 6622 | * Search an attribute associated to a node |
| pcercuei | 0:03b5121a232e | 6623 | * This function also looks in DTD attribute declaration for #FIXED or |
| pcercuei | 0:03b5121a232e | 6624 | * default declaration values unless DTD use has been turned off. |
| pcercuei | 0:03b5121a232e | 6625 | * |
| pcercuei | 0:03b5121a232e | 6626 | * Returns the attribute or the attribute declaration or NULL if |
| pcercuei | 0:03b5121a232e | 6627 | * neither was found. |
| pcercuei | 0:03b5121a232e | 6628 | */ |
| pcercuei | 0:03b5121a232e | 6629 | xmlAttrPtr |
| pcercuei | 0:03b5121a232e | 6630 | xmlHasProp(const xmlNode *node, const xmlChar *name) { |
| pcercuei | 0:03b5121a232e | 6631 | xmlAttrPtr prop; |
| pcercuei | 0:03b5121a232e | 6632 | xmlDocPtr doc; |
| pcercuei | 0:03b5121a232e | 6633 | |
| pcercuei | 0:03b5121a232e | 6634 | if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) |
| pcercuei | 0:03b5121a232e | 6635 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6636 | /* |
| pcercuei | 0:03b5121a232e | 6637 | * Check on the properties attached to the node |
| pcercuei | 0:03b5121a232e | 6638 | */ |
| pcercuei | 0:03b5121a232e | 6639 | prop = node->properties; |
| pcercuei | 0:03b5121a232e | 6640 | while (prop != NULL) { |
| pcercuei | 0:03b5121a232e | 6641 | if (xmlStrEqual(prop->name, name)) { |
| pcercuei | 0:03b5121a232e | 6642 | return(prop); |
| pcercuei | 0:03b5121a232e | 6643 | } |
| pcercuei | 0:03b5121a232e | 6644 | prop = prop->next; |
| pcercuei | 0:03b5121a232e | 6645 | } |
| pcercuei | 0:03b5121a232e | 6646 | if (!xmlCheckDTD) return(NULL); |
| pcercuei | 0:03b5121a232e | 6647 | |
| pcercuei | 0:03b5121a232e | 6648 | /* |
| pcercuei | 0:03b5121a232e | 6649 | * Check if there is a default declaration in the internal |
| pcercuei | 0:03b5121a232e | 6650 | * or external subsets |
| pcercuei | 0:03b5121a232e | 6651 | */ |
| pcercuei | 0:03b5121a232e | 6652 | doc = node->doc; |
| pcercuei | 0:03b5121a232e | 6653 | if (doc != NULL) { |
| pcercuei | 0:03b5121a232e | 6654 | xmlAttributePtr attrDecl; |
| pcercuei | 0:03b5121a232e | 6655 | if (doc->intSubset != NULL) { |
| pcercuei | 0:03b5121a232e | 6656 | attrDecl = xmlGetDtdAttrDesc(doc->intSubset, node->name, name); |
| pcercuei | 0:03b5121a232e | 6657 | if ((attrDecl == NULL) && (doc->extSubset != NULL)) |
| pcercuei | 0:03b5121a232e | 6658 | attrDecl = xmlGetDtdAttrDesc(doc->extSubset, node->name, name); |
| pcercuei | 0:03b5121a232e | 6659 | if ((attrDecl != NULL) && (attrDecl->defaultValue != NULL)) |
| pcercuei | 0:03b5121a232e | 6660 | /* return attribute declaration only if a default value is given |
| pcercuei | 0:03b5121a232e | 6661 | (that includes #FIXED declarations) */ |
| pcercuei | 0:03b5121a232e | 6662 | return((xmlAttrPtr) attrDecl); |
| pcercuei | 0:03b5121a232e | 6663 | } |
| pcercuei | 0:03b5121a232e | 6664 | } |
| pcercuei | 0:03b5121a232e | 6665 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6666 | } |
| pcercuei | 0:03b5121a232e | 6667 | |
| pcercuei | 0:03b5121a232e | 6668 | /** |
| pcercuei | 0:03b5121a232e | 6669 | * xmlHasNsProp: |
| pcercuei | 0:03b5121a232e | 6670 | * @node: the node |
| pcercuei | 0:03b5121a232e | 6671 | * @name: the attribute name |
| pcercuei | 0:03b5121a232e | 6672 | * @nameSpace: the URI of the namespace |
| pcercuei | 0:03b5121a232e | 6673 | * |
| pcercuei | 0:03b5121a232e | 6674 | * Search for an attribute associated to a node |
| pcercuei | 0:03b5121a232e | 6675 | * This attribute has to be anchored in the namespace specified. |
| pcercuei | 0:03b5121a232e | 6676 | * This does the entity substitution. |
| pcercuei | 0:03b5121a232e | 6677 | * This function looks in DTD attribute declaration for #FIXED or |
| pcercuei | 0:03b5121a232e | 6678 | * default declaration values unless DTD use has been turned off. |
| pcercuei | 0:03b5121a232e | 6679 | * Note that a namespace of NULL indicates to use the default namespace. |
| pcercuei | 0:03b5121a232e | 6680 | * |
| pcercuei | 0:03b5121a232e | 6681 | * Returns the attribute or the attribute declaration or NULL |
| pcercuei | 0:03b5121a232e | 6682 | * if neither was found. |
| pcercuei | 0:03b5121a232e | 6683 | */ |
| pcercuei | 0:03b5121a232e | 6684 | xmlAttrPtr |
| pcercuei | 0:03b5121a232e | 6685 | xmlHasNsProp(const xmlNode *node, const xmlChar *name, const xmlChar *nameSpace) { |
| pcercuei | 0:03b5121a232e | 6686 | |
| pcercuei | 0:03b5121a232e | 6687 | return(xmlGetPropNodeInternal(node, name, nameSpace, xmlCheckDTD)); |
| pcercuei | 0:03b5121a232e | 6688 | } |
| pcercuei | 0:03b5121a232e | 6689 | |
| pcercuei | 0:03b5121a232e | 6690 | /** |
| pcercuei | 0:03b5121a232e | 6691 | * xmlGetProp: |
| pcercuei | 0:03b5121a232e | 6692 | * @node: the node |
| pcercuei | 0:03b5121a232e | 6693 | * @name: the attribute name |
| pcercuei | 0:03b5121a232e | 6694 | * |
| pcercuei | 0:03b5121a232e | 6695 | * Search and get the value of an attribute associated to a node |
| pcercuei | 0:03b5121a232e | 6696 | * This does the entity substitution. |
| pcercuei | 0:03b5121a232e | 6697 | * This function looks in DTD attribute declaration for #FIXED or |
| pcercuei | 0:03b5121a232e | 6698 | * default declaration values unless DTD use has been turned off. |
| pcercuei | 0:03b5121a232e | 6699 | * NOTE: this function acts independently of namespaces associated |
| pcercuei | 0:03b5121a232e | 6700 | * to the attribute. Use xmlGetNsProp() or xmlGetNoNsProp() |
| pcercuei | 0:03b5121a232e | 6701 | * for namespace aware processing. |
| pcercuei | 0:03b5121a232e | 6702 | * |
| pcercuei | 0:03b5121a232e | 6703 | * Returns the attribute value or NULL if not found. |
| pcercuei | 0:03b5121a232e | 6704 | * It's up to the caller to free the memory with xmlFree(). |
| pcercuei | 0:03b5121a232e | 6705 | */ |
| pcercuei | 0:03b5121a232e | 6706 | xmlChar * |
| pcercuei | 0:03b5121a232e | 6707 | xmlGetProp(const xmlNode *node, const xmlChar *name) { |
| pcercuei | 0:03b5121a232e | 6708 | xmlAttrPtr prop; |
| pcercuei | 0:03b5121a232e | 6709 | |
| pcercuei | 0:03b5121a232e | 6710 | prop = xmlHasProp(node, name); |
| pcercuei | 0:03b5121a232e | 6711 | if (prop == NULL) |
| pcercuei | 0:03b5121a232e | 6712 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6713 | return(xmlGetPropNodeValueInternal(prop)); |
| pcercuei | 0:03b5121a232e | 6714 | } |
| pcercuei | 0:03b5121a232e | 6715 | |
| pcercuei | 0:03b5121a232e | 6716 | /** |
| pcercuei | 0:03b5121a232e | 6717 | * xmlGetNoNsProp: |
| pcercuei | 0:03b5121a232e | 6718 | * @node: the node |
| pcercuei | 0:03b5121a232e | 6719 | * @name: the attribute name |
| pcercuei | 0:03b5121a232e | 6720 | * |
| pcercuei | 0:03b5121a232e | 6721 | * Search and get the value of an attribute associated to a node |
| pcercuei | 0:03b5121a232e | 6722 | * This does the entity substitution. |
| pcercuei | 0:03b5121a232e | 6723 | * This function looks in DTD attribute declaration for #FIXED or |
| pcercuei | 0:03b5121a232e | 6724 | * default declaration values unless DTD use has been turned off. |
| pcercuei | 0:03b5121a232e | 6725 | * This function is similar to xmlGetProp except it will accept only |
| pcercuei | 0:03b5121a232e | 6726 | * an attribute in no namespace. |
| pcercuei | 0:03b5121a232e | 6727 | * |
| pcercuei | 0:03b5121a232e | 6728 | * Returns the attribute value or NULL if not found. |
| pcercuei | 0:03b5121a232e | 6729 | * It's up to the caller to free the memory with xmlFree(). |
| pcercuei | 0:03b5121a232e | 6730 | */ |
| pcercuei | 0:03b5121a232e | 6731 | xmlChar * |
| pcercuei | 0:03b5121a232e | 6732 | xmlGetNoNsProp(const xmlNode *node, const xmlChar *name) { |
| pcercuei | 0:03b5121a232e | 6733 | xmlAttrPtr prop; |
| pcercuei | 0:03b5121a232e | 6734 | |
| pcercuei | 0:03b5121a232e | 6735 | prop = xmlGetPropNodeInternal(node, name, NULL, xmlCheckDTD); |
| pcercuei | 0:03b5121a232e | 6736 | if (prop == NULL) |
| pcercuei | 0:03b5121a232e | 6737 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6738 | return(xmlGetPropNodeValueInternal(prop)); |
| pcercuei | 0:03b5121a232e | 6739 | } |
| pcercuei | 0:03b5121a232e | 6740 | |
| pcercuei | 0:03b5121a232e | 6741 | /** |
| pcercuei | 0:03b5121a232e | 6742 | * xmlGetNsProp: |
| pcercuei | 0:03b5121a232e | 6743 | * @node: the node |
| pcercuei | 0:03b5121a232e | 6744 | * @name: the attribute name |
| pcercuei | 0:03b5121a232e | 6745 | * @nameSpace: the URI of the namespace |
| pcercuei | 0:03b5121a232e | 6746 | * |
| pcercuei | 0:03b5121a232e | 6747 | * Search and get the value of an attribute associated to a node |
| pcercuei | 0:03b5121a232e | 6748 | * This attribute has to be anchored in the namespace specified. |
| pcercuei | 0:03b5121a232e | 6749 | * This does the entity substitution. |
| pcercuei | 0:03b5121a232e | 6750 | * This function looks in DTD attribute declaration for #FIXED or |
| pcercuei | 0:03b5121a232e | 6751 | * default declaration values unless DTD use has been turned off. |
| pcercuei | 0:03b5121a232e | 6752 | * |
| pcercuei | 0:03b5121a232e | 6753 | * Returns the attribute value or NULL if not found. |
| pcercuei | 0:03b5121a232e | 6754 | * It's up to the caller to free the memory with xmlFree(). |
| pcercuei | 0:03b5121a232e | 6755 | */ |
| pcercuei | 0:03b5121a232e | 6756 | xmlChar * |
| pcercuei | 0:03b5121a232e | 6757 | xmlGetNsProp(const xmlNode *node, const xmlChar *name, const xmlChar *nameSpace) { |
| pcercuei | 0:03b5121a232e | 6758 | xmlAttrPtr prop; |
| pcercuei | 0:03b5121a232e | 6759 | |
| pcercuei | 0:03b5121a232e | 6760 | prop = xmlGetPropNodeInternal(node, name, nameSpace, xmlCheckDTD); |
| pcercuei | 0:03b5121a232e | 6761 | if (prop == NULL) |
| pcercuei | 0:03b5121a232e | 6762 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6763 | return(xmlGetPropNodeValueInternal(prop)); |
| pcercuei | 0:03b5121a232e | 6764 | } |
| pcercuei | 0:03b5121a232e | 6765 | |
| pcercuei | 0:03b5121a232e | 6766 | #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) |
| pcercuei | 0:03b5121a232e | 6767 | /** |
| pcercuei | 0:03b5121a232e | 6768 | * xmlUnsetProp: |
| pcercuei | 0:03b5121a232e | 6769 | * @node: the node |
| pcercuei | 0:03b5121a232e | 6770 | * @name: the attribute name |
| pcercuei | 0:03b5121a232e | 6771 | * |
| pcercuei | 0:03b5121a232e | 6772 | * Remove an attribute carried by a node. |
| pcercuei | 0:03b5121a232e | 6773 | * This handles only attributes in no namespace. |
| pcercuei | 0:03b5121a232e | 6774 | * Returns 0 if successful, -1 if not found |
| pcercuei | 0:03b5121a232e | 6775 | */ |
| pcercuei | 0:03b5121a232e | 6776 | int |
| pcercuei | 0:03b5121a232e | 6777 | xmlUnsetProp(xmlNodePtr node, const xmlChar *name) { |
| pcercuei | 0:03b5121a232e | 6778 | xmlAttrPtr prop; |
| pcercuei | 0:03b5121a232e | 6779 | |
| pcercuei | 0:03b5121a232e | 6780 | prop = xmlGetPropNodeInternal(node, name, NULL, 0); |
| pcercuei | 0:03b5121a232e | 6781 | if (prop == NULL) |
| pcercuei | 0:03b5121a232e | 6782 | return(-1); |
| pcercuei | 0:03b5121a232e | 6783 | xmlUnlinkNode((xmlNodePtr) prop); |
| pcercuei | 0:03b5121a232e | 6784 | xmlFreeProp(prop); |
| pcercuei | 0:03b5121a232e | 6785 | return(0); |
| pcercuei | 0:03b5121a232e | 6786 | } |
| pcercuei | 0:03b5121a232e | 6787 | |
| pcercuei | 0:03b5121a232e | 6788 | /** |
| pcercuei | 0:03b5121a232e | 6789 | * xmlUnsetNsProp: |
| pcercuei | 0:03b5121a232e | 6790 | * @node: the node |
| pcercuei | 0:03b5121a232e | 6791 | * @ns: the namespace definition |
| pcercuei | 0:03b5121a232e | 6792 | * @name: the attribute name |
| pcercuei | 0:03b5121a232e | 6793 | * |
| pcercuei | 0:03b5121a232e | 6794 | * Remove an attribute carried by a node. |
| pcercuei | 0:03b5121a232e | 6795 | * Returns 0 if successful, -1 if not found |
| pcercuei | 0:03b5121a232e | 6796 | */ |
| pcercuei | 0:03b5121a232e | 6797 | int |
| pcercuei | 0:03b5121a232e | 6798 | xmlUnsetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name) { |
| pcercuei | 0:03b5121a232e | 6799 | xmlAttrPtr prop; |
| pcercuei | 0:03b5121a232e | 6800 | |
| pcercuei | 0:03b5121a232e | 6801 | prop = xmlGetPropNodeInternal(node, name, (ns != NULL) ? ns->href : NULL, 0); |
| pcercuei | 0:03b5121a232e | 6802 | if (prop == NULL) |
| pcercuei | 0:03b5121a232e | 6803 | return(-1); |
| pcercuei | 0:03b5121a232e | 6804 | xmlUnlinkNode((xmlNodePtr) prop); |
| pcercuei | 0:03b5121a232e | 6805 | xmlFreeProp(prop); |
| pcercuei | 0:03b5121a232e | 6806 | return(0); |
| pcercuei | 0:03b5121a232e | 6807 | } |
| pcercuei | 0:03b5121a232e | 6808 | #endif |
| pcercuei | 0:03b5121a232e | 6809 | |
| pcercuei | 0:03b5121a232e | 6810 | #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_HTML_ENABLED) |
| pcercuei | 0:03b5121a232e | 6811 | /** |
| pcercuei | 0:03b5121a232e | 6812 | * xmlSetProp: |
| pcercuei | 0:03b5121a232e | 6813 | * @node: the node |
| pcercuei | 0:03b5121a232e | 6814 | * @name: the attribute name (a QName) |
| pcercuei | 0:03b5121a232e | 6815 | * @value: the attribute value |
| pcercuei | 0:03b5121a232e | 6816 | * |
| pcercuei | 0:03b5121a232e | 6817 | * Set (or reset) an attribute carried by a node. |
| pcercuei | 0:03b5121a232e | 6818 | * If @name has a prefix, then the corresponding |
| pcercuei | 0:03b5121a232e | 6819 | * namespace-binding will be used, if in scope; it is an |
| pcercuei | 0:03b5121a232e | 6820 | * error it there's no such ns-binding for the prefix in |
| pcercuei | 0:03b5121a232e | 6821 | * scope. |
| pcercuei | 0:03b5121a232e | 6822 | * Returns the attribute pointer. |
| pcercuei | 0:03b5121a232e | 6823 | * |
| pcercuei | 0:03b5121a232e | 6824 | */ |
| pcercuei | 0:03b5121a232e | 6825 | xmlAttrPtr |
| pcercuei | 0:03b5121a232e | 6826 | xmlSetProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { |
| pcercuei | 0:03b5121a232e | 6827 | int len; |
| pcercuei | 0:03b5121a232e | 6828 | const xmlChar *nqname; |
| pcercuei | 0:03b5121a232e | 6829 | |
| pcercuei | 0:03b5121a232e | 6830 | if ((node == NULL) || (name == NULL) || (node->type != XML_ELEMENT_NODE)) |
| pcercuei | 0:03b5121a232e | 6831 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6832 | |
| pcercuei | 0:03b5121a232e | 6833 | /* |
| pcercuei | 0:03b5121a232e | 6834 | * handle QNames |
| pcercuei | 0:03b5121a232e | 6835 | */ |
| pcercuei | 0:03b5121a232e | 6836 | nqname = xmlSplitQName3(name, &len); |
| pcercuei | 0:03b5121a232e | 6837 | if (nqname != NULL) { |
| pcercuei | 0:03b5121a232e | 6838 | xmlNsPtr ns; |
| pcercuei | 0:03b5121a232e | 6839 | xmlChar *prefix = xmlStrndup(name, len); |
| pcercuei | 0:03b5121a232e | 6840 | ns = xmlSearchNs(node->doc, node, prefix); |
| pcercuei | 0:03b5121a232e | 6841 | if (prefix != NULL) |
| pcercuei | 0:03b5121a232e | 6842 | xmlFree(prefix); |
| pcercuei | 0:03b5121a232e | 6843 | if (ns != NULL) |
| pcercuei | 0:03b5121a232e | 6844 | return(xmlSetNsProp(node, ns, nqname, value)); |
| pcercuei | 0:03b5121a232e | 6845 | } |
| pcercuei | 0:03b5121a232e | 6846 | return(xmlSetNsProp(node, NULL, name, value)); |
| pcercuei | 0:03b5121a232e | 6847 | } |
| pcercuei | 0:03b5121a232e | 6848 | |
| pcercuei | 0:03b5121a232e | 6849 | /** |
| pcercuei | 0:03b5121a232e | 6850 | * xmlSetNsProp: |
| pcercuei | 0:03b5121a232e | 6851 | * @node: the node |
| pcercuei | 0:03b5121a232e | 6852 | * @ns: the namespace definition |
| pcercuei | 0:03b5121a232e | 6853 | * @name: the attribute name |
| pcercuei | 0:03b5121a232e | 6854 | * @value: the attribute value |
| pcercuei | 0:03b5121a232e | 6855 | * |
| pcercuei | 0:03b5121a232e | 6856 | * Set (or reset) an attribute carried by a node. |
| pcercuei | 0:03b5121a232e | 6857 | * The ns structure must be in scope, this is not checked |
| pcercuei | 0:03b5121a232e | 6858 | * |
| pcercuei | 0:03b5121a232e | 6859 | * Returns the attribute pointer. |
| pcercuei | 0:03b5121a232e | 6860 | */ |
| pcercuei | 0:03b5121a232e | 6861 | xmlAttrPtr |
| pcercuei | 0:03b5121a232e | 6862 | xmlSetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name, |
| pcercuei | 0:03b5121a232e | 6863 | const xmlChar *value) |
| pcercuei | 0:03b5121a232e | 6864 | { |
| pcercuei | 0:03b5121a232e | 6865 | xmlAttrPtr prop; |
| pcercuei | 0:03b5121a232e | 6866 | |
| pcercuei | 0:03b5121a232e | 6867 | if (ns && (ns->href == NULL)) |
| pcercuei | 0:03b5121a232e | 6868 | return(NULL); |
| pcercuei | 0:03b5121a232e | 6869 | prop = xmlGetPropNodeInternal(node, name, (ns != NULL) ? ns->href : NULL, 0); |
| pcercuei | 0:03b5121a232e | 6870 | if (prop != NULL) { |
| pcercuei | 0:03b5121a232e | 6871 | /* |
| pcercuei | 0:03b5121a232e | 6872 | * Modify the attribute's value. |
| pcercuei | 0:03b5121a232e | 6873 | */ |
| pcercuei | 0:03b5121a232e | 6874 | if (prop->atype == XML_ATTRIBUTE_ID) { |
| pcercuei | 0:03b5121a232e | 6875 | xmlRemoveID(node->doc, prop); |
| pcercuei | 0:03b5121a232e | 6876 | prop->atype = XML_ATTRIBUTE_ID; |
| pcercuei | 0:03b5121a232e | 6877 | } |
| pcercuei | 0:03b5121a232e | 6878 | if (prop->children != NULL) |
| pcercuei | 0:03b5121a232e | 6879 | xmlFreeNodeList(prop->children); |
| pcercuei | 0:03b5121a232e | 6880 | prop->children = NULL; |
| pcercuei | 0:03b5121a232e | 6881 | prop->last = NULL; |
| pcercuei | 0:03b5121a232e | 6882 | prop->ns = ns; |
| pcercuei | 0:03b5121a232e | 6883 | if (value != NULL) { |
| pcercuei | 0:03b5121a232e | 6884 | xmlNodePtr tmp; |
| pcercuei | 0:03b5121a232e | 6885 | |
| pcercuei | 0:03b5121a232e | 6886 | if(!xmlCheckUTF8(value)) { |
| pcercuei | 0:03b5121a232e | 6887 | xmlTreeErr(XML_TREE_NOT_UTF8, (xmlNodePtr) node->doc, |
| pcercuei | 0:03b5121a232e | 6888 | NULL); |
| pcercuei | 0:03b5121a232e | 6889 | if (node->doc != NULL) |
| pcercuei | 0:03b5121a232e | 6890 | node->doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); |
| pcercuei | 0:03b5121a232e | 6891 | } |
| pcercuei | 0:03b5121a232e | 6892 | prop->children = xmlNewDocText(node->doc, value); |
| pcercuei | 0:03b5121a232e | 6893 | prop->last = NULL; |
| pcercuei | 0:03b5121a232e | 6894 | tmp = prop->children; |
| pcercuei | 0:03b5121a232e | 6895 | while (tmp != NULL) { |
| pcercuei | 0:03b5121a232e | 6896 | tmp->parent = (xmlNodePtr) prop; |
| pcercuei | 0:03b5121a232e | 6897 | if (tmp->next == NULL) |
| pcercuei | 0:03b5121a232e | 6898 | prop->last = tmp; |
| pcercuei | 0:03b5121a232e | 6899 | tmp = tmp->next; |
| pcercuei | 0:03b5121a232e | 6900 | } |
| pcercuei | 0:03b5121a232e | 6901 | } |
| pcercuei | 0:03b5121a232e | 6902 | if (prop->atype == XML_ATTRIBUTE_ID) |
| pcercuei | 0:03b5121a232e | 6903 | xmlAddID(NULL, node->doc, value, prop); |
| pcercuei | 0:03b5121a232e | 6904 | return(prop); |
| pcercuei | 0:03b5121a232e | 6905 | } |
| pcercuei | 0:03b5121a232e | 6906 | /* |
| pcercuei | 0:03b5121a232e | 6907 | * No equal attr found; create a new one. |
| pcercuei | 0:03b5121a232e | 6908 | */ |
| pcercuei | 0:03b5121a232e | 6909 | return(xmlNewPropInternal(node, ns, name, value, 0)); |
| pcercuei | 0:03b5121a232e | 6910 | } |
| pcercuei | 0:03b5121a232e | 6911 | |
| pcercuei | 0:03b5121a232e | 6912 | #endif /* LIBXML_TREE_ENABLED */ |
| pcercuei | 0:03b5121a232e | 6913 | |
| pcercuei | 0:03b5121a232e | 6914 | /** |
| pcercuei | 0:03b5121a232e | 6915 | * xmlNodeIsText: |
| pcercuei | 0:03b5121a232e | 6916 | * @node: the node |
| pcercuei | 0:03b5121a232e | 6917 | * |
| pcercuei | 0:03b5121a232e | 6918 | * Is this node a Text node ? |
| pcercuei | 0:03b5121a232e | 6919 | * Returns 1 yes, 0 no |
| pcercuei | 0:03b5121a232e | 6920 | */ |
| pcercuei | 0:03b5121a232e | 6921 | int |
| pcercuei | 0:03b5121a232e | 6922 | xmlNodeIsText(const xmlNode *node) { |
| pcercuei | 0:03b5121a232e | 6923 | if (node == NULL) return(0); |
| pcercuei | 0:03b5121a232e | 6924 | |
| pcercuei | 0:03b5121a232e | 6925 | if (node->type == XML_TEXT_NODE) return(1); |
| pcercuei | 0:03b5121a232e | 6926 | return(0); |
| pcercuei | 0:03b5121a232e | 6927 | } |
| pcercuei | 0:03b5121a232e | 6928 | |
| pcercuei | 0:03b5121a232e | 6929 | /** |
| pcercuei | 0:03b5121a232e | 6930 | * xmlIsBlankNode: |
| pcercuei | 0:03b5121a232e | 6931 | * @node: the node |
| pcercuei | 0:03b5121a232e | 6932 | * |
| pcercuei | 0:03b5121a232e | 6933 | * Checks whether this node is an empty or whitespace only |
| pcercuei | 0:03b5121a232e | 6934 | * (and possibly ignorable) text-node. |
| pcercuei | 0:03b5121a232e | 6935 | * |
| pcercuei | 0:03b5121a232e | 6936 | * Returns 1 yes, 0 no |
| pcercuei | 0:03b5121a232e | 6937 | */ |
| pcercuei | 0:03b5121a232e | 6938 | int |
| pcercuei | 0:03b5121a232e | 6939 | xmlIsBlankNode(const xmlNode *node) { |
| pcercuei | 0:03b5121a232e | 6940 | const xmlChar *cur; |
| pcercuei | 0:03b5121a232e | 6941 | if (node == NULL) return(0); |
| pcercuei | 0:03b5121a232e | 6942 | |
| pcercuei | 0:03b5121a232e | 6943 | if ((node->type != XML_TEXT_NODE) && |
| pcercuei | 0:03b5121a232e | 6944 | (node->type != XML_CDATA_SECTION_NODE)) |
| pcercuei | 0:03b5121a232e | 6945 | return(0); |
| pcercuei | 0:03b5121a232e | 6946 | if (node->content == NULL) return(1); |
| pcercuei | 0:03b5121a232e | 6947 | cur = node->content; |
| pcercuei | 0:03b5121a232e | 6948 | while (*cur != 0) { |
| pcercuei | 0:03b5121a232e | 6949 | if (!IS_BLANK_CH(*cur)) return(0); |
| pcercuei | 0:03b5121a232e | 6950 | cur++; |
| pcercuei | 0:03b5121a232e | 6951 | } |
| pcercuei | 0:03b5121a232e | 6952 | |
| pcercuei | 0:03b5121a232e | 6953 | return(1); |
| pcercuei | 0:03b5121a232e | 6954 | } |
| pcercuei | 0:03b5121a232e | 6955 | |
| pcercuei | 0:03b5121a232e | 6956 | /** |
| pcercuei | 0:03b5121a232e | 6957 | * xmlTextConcat: |
| pcercuei | 0:03b5121a232e | 6958 | * @node: the node |
| pcercuei | 0:03b5121a232e | 6959 | * @content: the content |
| pcercuei | 0:03b5121a232e | 6960 | * @len: @content length |
| pcercuei | 0:03b5121a232e | 6961 | * |
| pcercuei | 0:03b5121a232e | 6962 | * Concat the given string at the end of the existing node content |
| pcercuei | 0:03b5121a232e | 6963 | * |
| pcercuei | 0:03b5121a232e | 6964 | * Returns -1 in case of error, 0 otherwise |
| pcercuei | 0:03b5121a232e | 6965 | */ |
| pcercuei | 0:03b5121a232e | 6966 | |
| pcercuei | 0:03b5121a232e | 6967 | int |
| pcercuei | 0:03b5121a232e | 6968 | xmlTextConcat(xmlNodePtr node, const xmlChar *content, int len) { |
| pcercuei | 0:03b5121a232e | 6969 | if (node == NULL) return(-1); |
| pcercuei | 0:03b5121a232e | 6970 | |
| pcercuei | 0:03b5121a232e | 6971 | if ((node->type != XML_TEXT_NODE) && |
| pcercuei | 0:03b5121a232e | 6972 | (node->type != XML_CDATA_SECTION_NODE) && |
| pcercuei | 0:03b5121a232e | 6973 | (node->type != XML_COMMENT_NODE) && |
| pcercuei | 0:03b5121a232e | 6974 | (node->type != XML_PI_NODE)) { |
| pcercuei | 0:03b5121a232e | 6975 | #ifdef DEBUG_TREE |
| pcercuei | 0:03b5121a232e | 6976 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 6977 | "xmlTextConcat: node is not text nor CDATA\n"); |
| pcercuei | 0:03b5121a232e | 6978 | #endif |
| pcercuei | 0:03b5121a232e | 6979 | return(-1); |
| pcercuei | 0:03b5121a232e | 6980 | } |
| pcercuei | 0:03b5121a232e | 6981 | /* need to check if content is currently in the dictionary */ |
| pcercuei | 0:03b5121a232e | 6982 | if ((node->content == (xmlChar *) &(node->properties)) || |
| pcercuei | 0:03b5121a232e | 6983 | ((node->doc != NULL) && (node->doc->dict != NULL) && |
| pcercuei | 0:03b5121a232e | 6984 | xmlDictOwns(node->doc->dict, node->content))) { |
| pcercuei | 0:03b5121a232e | 6985 | node->content = xmlStrncatNew(node->content, content, len); |
| pcercuei | 0:03b5121a232e | 6986 | } else { |
| pcercuei | 0:03b5121a232e | 6987 | node->content = xmlStrncat(node->content, content, len); |
| pcercuei | 0:03b5121a232e | 6988 | } |
| pcercuei | 0:03b5121a232e | 6989 | node->properties = NULL; |
| pcercuei | 0:03b5121a232e | 6990 | if (node->content == NULL) |
| pcercuei | 0:03b5121a232e | 6991 | return(-1); |
| pcercuei | 0:03b5121a232e | 6992 | return(0); |
| pcercuei | 0:03b5121a232e | 6993 | } |
| pcercuei | 0:03b5121a232e | 6994 | |
| pcercuei | 0:03b5121a232e | 6995 | /************************************************************************ |
| pcercuei | 0:03b5121a232e | 6996 | * * |
| pcercuei | 0:03b5121a232e | 6997 | * Output : to a FILE or in memory * |
| pcercuei | 0:03b5121a232e | 6998 | * * |
| pcercuei | 0:03b5121a232e | 6999 | ************************************************************************/ |
| pcercuei | 0:03b5121a232e | 7000 | |
| pcercuei | 0:03b5121a232e | 7001 | /** |
| pcercuei | 0:03b5121a232e | 7002 | * xmlBufferCreate: |
| pcercuei | 0:03b5121a232e | 7003 | * |
| pcercuei | 0:03b5121a232e | 7004 | * routine to create an XML buffer. |
| pcercuei | 0:03b5121a232e | 7005 | * returns the new structure. |
| pcercuei | 0:03b5121a232e | 7006 | */ |
| pcercuei | 0:03b5121a232e | 7007 | xmlBufferPtr |
| pcercuei | 0:03b5121a232e | 7008 | xmlBufferCreate(void) { |
| pcercuei | 0:03b5121a232e | 7009 | xmlBufferPtr ret; |
| pcercuei | 0:03b5121a232e | 7010 | |
| pcercuei | 0:03b5121a232e | 7011 | ret = (xmlBufferPtr) xmlMalloc(sizeof(xmlBuffer)); |
| pcercuei | 0:03b5121a232e | 7012 | if (ret == NULL) { |
| pcercuei | 0:03b5121a232e | 7013 | xmlTreeErrMemory("creating buffer"); |
| pcercuei | 0:03b5121a232e | 7014 | return(NULL); |
| pcercuei | 0:03b5121a232e | 7015 | } |
| pcercuei | 0:03b5121a232e | 7016 | ret->use = 0; |
| pcercuei | 0:03b5121a232e | 7017 | ret->size = xmlDefaultBufferSize; |
| pcercuei | 0:03b5121a232e | 7018 | ret->alloc = xmlBufferAllocScheme; |
| pcercuei | 0:03b5121a232e | 7019 | ret->content = (xmlChar *) xmlMallocAtomic(ret->size * sizeof(xmlChar)); |
| pcercuei | 0:03b5121a232e | 7020 | if (ret->content == NULL) { |
| pcercuei | 0:03b5121a232e | 7021 | xmlTreeErrMemory("creating buffer"); |
| pcercuei | 0:03b5121a232e | 7022 | xmlFree(ret); |
| pcercuei | 0:03b5121a232e | 7023 | return(NULL); |
| pcercuei | 0:03b5121a232e | 7024 | } |
| pcercuei | 0:03b5121a232e | 7025 | ret->content[0] = 0; |
| pcercuei | 0:03b5121a232e | 7026 | ret->contentIO = NULL; |
| pcercuei | 0:03b5121a232e | 7027 | return(ret); |
| pcercuei | 0:03b5121a232e | 7028 | } |
| pcercuei | 0:03b5121a232e | 7029 | |
| pcercuei | 0:03b5121a232e | 7030 | /** |
| pcercuei | 0:03b5121a232e | 7031 | * xmlBufferCreateSize: |
| pcercuei | 0:03b5121a232e | 7032 | * @size: initial size of buffer |
| pcercuei | 0:03b5121a232e | 7033 | * |
| pcercuei | 0:03b5121a232e | 7034 | * routine to create an XML buffer. |
| pcercuei | 0:03b5121a232e | 7035 | * returns the new structure. |
| pcercuei | 0:03b5121a232e | 7036 | */ |
| pcercuei | 0:03b5121a232e | 7037 | xmlBufferPtr |
| pcercuei | 0:03b5121a232e | 7038 | xmlBufferCreateSize(size_t size) { |
| pcercuei | 0:03b5121a232e | 7039 | xmlBufferPtr ret; |
| pcercuei | 0:03b5121a232e | 7040 | |
| pcercuei | 0:03b5121a232e | 7041 | ret = (xmlBufferPtr) xmlMalloc(sizeof(xmlBuffer)); |
| pcercuei | 0:03b5121a232e | 7042 | if (ret == NULL) { |
| pcercuei | 0:03b5121a232e | 7043 | xmlTreeErrMemory("creating buffer"); |
| pcercuei | 0:03b5121a232e | 7044 | return(NULL); |
| pcercuei | 0:03b5121a232e | 7045 | } |
| pcercuei | 0:03b5121a232e | 7046 | ret->use = 0; |
| pcercuei | 0:03b5121a232e | 7047 | ret->alloc = xmlBufferAllocScheme; |
| pcercuei | 0:03b5121a232e | 7048 | ret->size = (size ? size+2 : 0); /* +1 for ending null */ |
| pcercuei | 0:03b5121a232e | 7049 | if (ret->size){ |
| pcercuei | 0:03b5121a232e | 7050 | ret->content = (xmlChar *) xmlMallocAtomic(ret->size * sizeof(xmlChar)); |
| pcercuei | 0:03b5121a232e | 7051 | if (ret->content == NULL) { |
| pcercuei | 0:03b5121a232e | 7052 | xmlTreeErrMemory("creating buffer"); |
| pcercuei | 0:03b5121a232e | 7053 | xmlFree(ret); |
| pcercuei | 0:03b5121a232e | 7054 | return(NULL); |
| pcercuei | 0:03b5121a232e | 7055 | } |
| pcercuei | 0:03b5121a232e | 7056 | ret->content[0] = 0; |
| pcercuei | 0:03b5121a232e | 7057 | } else |
| pcercuei | 0:03b5121a232e | 7058 | ret->content = NULL; |
| pcercuei | 0:03b5121a232e | 7059 | ret->contentIO = NULL; |
| pcercuei | 0:03b5121a232e | 7060 | return(ret); |
| pcercuei | 0:03b5121a232e | 7061 | } |
| pcercuei | 0:03b5121a232e | 7062 | |
| pcercuei | 0:03b5121a232e | 7063 | /** |
| pcercuei | 0:03b5121a232e | 7064 | * xmlBufferDetach: |
| pcercuei | 0:03b5121a232e | 7065 | * @buf: the buffer |
| pcercuei | 0:03b5121a232e | 7066 | * |
| pcercuei | 0:03b5121a232e | 7067 | * Remove the string contained in a buffer and gie it back to the |
| pcercuei | 0:03b5121a232e | 7068 | * caller. The buffer is reset to an empty content. |
| pcercuei | 0:03b5121a232e | 7069 | * This doesn't work with immutable buffers as they can't be reset. |
| pcercuei | 0:03b5121a232e | 7070 | * |
| pcercuei | 0:03b5121a232e | 7071 | * Returns the previous string contained by the buffer. |
| pcercuei | 0:03b5121a232e | 7072 | */ |
| pcercuei | 0:03b5121a232e | 7073 | xmlChar * |
| pcercuei | 0:03b5121a232e | 7074 | xmlBufferDetach(xmlBufferPtr buf) { |
| pcercuei | 0:03b5121a232e | 7075 | xmlChar *ret; |
| pcercuei | 0:03b5121a232e | 7076 | |
| pcercuei | 0:03b5121a232e | 7077 | if (buf == NULL) |
| pcercuei | 0:03b5121a232e | 7078 | return(NULL); |
| pcercuei | 0:03b5121a232e | 7079 | if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) |
| pcercuei | 0:03b5121a232e | 7080 | return(NULL); |
| pcercuei | 0:03b5121a232e | 7081 | |
| pcercuei | 0:03b5121a232e | 7082 | ret = buf->content; |
| pcercuei | 0:03b5121a232e | 7083 | buf->content = NULL; |
| pcercuei | 0:03b5121a232e | 7084 | buf->size = 0; |
| pcercuei | 0:03b5121a232e | 7085 | buf->use = 0; |
| pcercuei | 0:03b5121a232e | 7086 | |
| pcercuei | 0:03b5121a232e | 7087 | return ret; |
| pcercuei | 0:03b5121a232e | 7088 | } |
| pcercuei | 0:03b5121a232e | 7089 | |
| pcercuei | 0:03b5121a232e | 7090 | |
| pcercuei | 0:03b5121a232e | 7091 | /** |
| pcercuei | 0:03b5121a232e | 7092 | * xmlBufferCreateStatic: |
| pcercuei | 0:03b5121a232e | 7093 | * @mem: the memory area |
| pcercuei | 0:03b5121a232e | 7094 | * @size: the size in byte |
| pcercuei | 0:03b5121a232e | 7095 | * |
| pcercuei | 0:03b5121a232e | 7096 | * routine to create an XML buffer from an immutable memory area. |
| pcercuei | 0:03b5121a232e | 7097 | * The area won't be modified nor copied, and is expected to be |
| pcercuei | 0:03b5121a232e | 7098 | * present until the end of the buffer lifetime. |
| pcercuei | 0:03b5121a232e | 7099 | * |
| pcercuei | 0:03b5121a232e | 7100 | * returns the new structure. |
| pcercuei | 0:03b5121a232e | 7101 | */ |
| pcercuei | 0:03b5121a232e | 7102 | xmlBufferPtr |
| pcercuei | 0:03b5121a232e | 7103 | xmlBufferCreateStatic(void *mem, size_t size) { |
| pcercuei | 0:03b5121a232e | 7104 | xmlBufferPtr ret; |
| pcercuei | 0:03b5121a232e | 7105 | |
| pcercuei | 0:03b5121a232e | 7106 | if ((mem == NULL) || (size == 0)) |
| pcercuei | 0:03b5121a232e | 7107 | return(NULL); |
| pcercuei | 0:03b5121a232e | 7108 | |
| pcercuei | 0:03b5121a232e | 7109 | ret = (xmlBufferPtr) xmlMalloc(sizeof(xmlBuffer)); |
| pcercuei | 0:03b5121a232e | 7110 | if (ret == NULL) { |
| pcercuei | 0:03b5121a232e | 7111 | xmlTreeErrMemory("creating buffer"); |
| pcercuei | 0:03b5121a232e | 7112 | return(NULL); |
| pcercuei | 0:03b5121a232e | 7113 | } |
| pcercuei | 0:03b5121a232e | 7114 | ret->use = size; |
| pcercuei | 0:03b5121a232e | 7115 | ret->size = size; |
| pcercuei | 0:03b5121a232e | 7116 | ret->alloc = XML_BUFFER_ALLOC_IMMUTABLE; |
| pcercuei | 0:03b5121a232e | 7117 | ret->content = (xmlChar *) mem; |
| pcercuei | 0:03b5121a232e | 7118 | return(ret); |
| pcercuei | 0:03b5121a232e | 7119 | } |
| pcercuei | 0:03b5121a232e | 7120 | |
| pcercuei | 0:03b5121a232e | 7121 | /** |
| pcercuei | 0:03b5121a232e | 7122 | * xmlBufferSetAllocationScheme: |
| pcercuei | 0:03b5121a232e | 7123 | * @buf: the buffer to tune |
| pcercuei | 0:03b5121a232e | 7124 | * @scheme: allocation scheme to use |
| pcercuei | 0:03b5121a232e | 7125 | * |
| pcercuei | 0:03b5121a232e | 7126 | * Sets the allocation scheme for this buffer |
| pcercuei | 0:03b5121a232e | 7127 | */ |
| pcercuei | 0:03b5121a232e | 7128 | void |
| pcercuei | 0:03b5121a232e | 7129 | xmlBufferSetAllocationScheme(xmlBufferPtr buf, |
| pcercuei | 0:03b5121a232e | 7130 | xmlBufferAllocationScheme scheme) { |
| pcercuei | 0:03b5121a232e | 7131 | if (buf == NULL) { |
| pcercuei | 0:03b5121a232e | 7132 | #ifdef DEBUG_BUFFER |
| pcercuei | 0:03b5121a232e | 7133 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 7134 | "xmlBufferSetAllocationScheme: buf == NULL\n"); |
| pcercuei | 0:03b5121a232e | 7135 | #endif |
| pcercuei | 0:03b5121a232e | 7136 | return; |
| pcercuei | 0:03b5121a232e | 7137 | } |
| pcercuei | 0:03b5121a232e | 7138 | if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) || |
| pcercuei | 0:03b5121a232e | 7139 | (buf->alloc == XML_BUFFER_ALLOC_IO)) return; |
| pcercuei | 0:03b5121a232e | 7140 | if ((scheme == XML_BUFFER_ALLOC_DOUBLEIT) || |
| pcercuei | 0:03b5121a232e | 7141 | (scheme == XML_BUFFER_ALLOC_EXACT) || |
| pcercuei | 0:03b5121a232e | 7142 | (scheme == XML_BUFFER_ALLOC_HYBRID) || |
| pcercuei | 0:03b5121a232e | 7143 | (scheme == XML_BUFFER_ALLOC_IMMUTABLE)) |
| pcercuei | 0:03b5121a232e | 7144 | buf->alloc = scheme; |
| pcercuei | 0:03b5121a232e | 7145 | } |
| pcercuei | 0:03b5121a232e | 7146 | |
| pcercuei | 0:03b5121a232e | 7147 | /** |
| pcercuei | 0:03b5121a232e | 7148 | * xmlBufferFree: |
| pcercuei | 0:03b5121a232e | 7149 | * @buf: the buffer to free |
| pcercuei | 0:03b5121a232e | 7150 | * |
| pcercuei | 0:03b5121a232e | 7151 | * Frees an XML buffer. It frees both the content and the structure which |
| pcercuei | 0:03b5121a232e | 7152 | * encapsulate it. |
| pcercuei | 0:03b5121a232e | 7153 | */ |
| pcercuei | 0:03b5121a232e | 7154 | void |
| pcercuei | 0:03b5121a232e | 7155 | xmlBufferFree(xmlBufferPtr buf) { |
| pcercuei | 0:03b5121a232e | 7156 | if (buf == NULL) { |
| pcercuei | 0:03b5121a232e | 7157 | #ifdef DEBUG_BUFFER |
| pcercuei | 0:03b5121a232e | 7158 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 7159 | "xmlBufferFree: buf == NULL\n"); |
| pcercuei | 0:03b5121a232e | 7160 | #endif |
| pcercuei | 0:03b5121a232e | 7161 | return; |
| pcercuei | 0:03b5121a232e | 7162 | } |
| pcercuei | 0:03b5121a232e | 7163 | |
| pcercuei | 0:03b5121a232e | 7164 | if ((buf->alloc == XML_BUFFER_ALLOC_IO) && |
| pcercuei | 0:03b5121a232e | 7165 | (buf->contentIO != NULL)) { |
| pcercuei | 0:03b5121a232e | 7166 | xmlFree(buf->contentIO); |
| pcercuei | 0:03b5121a232e | 7167 | } else if ((buf->content != NULL) && |
| pcercuei | 0:03b5121a232e | 7168 | (buf->alloc != XML_BUFFER_ALLOC_IMMUTABLE)) { |
| pcercuei | 0:03b5121a232e | 7169 | xmlFree(buf->content); |
| pcercuei | 0:03b5121a232e | 7170 | } |
| pcercuei | 0:03b5121a232e | 7171 | xmlFree(buf); |
| pcercuei | 0:03b5121a232e | 7172 | } |
| pcercuei | 0:03b5121a232e | 7173 | |
| pcercuei | 0:03b5121a232e | 7174 | /** |
| pcercuei | 0:03b5121a232e | 7175 | * xmlBufferEmpty: |
| pcercuei | 0:03b5121a232e | 7176 | * @buf: the buffer |
| pcercuei | 0:03b5121a232e | 7177 | * |
| pcercuei | 0:03b5121a232e | 7178 | * empty a buffer. |
| pcercuei | 0:03b5121a232e | 7179 | */ |
| pcercuei | 0:03b5121a232e | 7180 | void |
| pcercuei | 0:03b5121a232e | 7181 | xmlBufferEmpty(xmlBufferPtr buf) { |
| pcercuei | 0:03b5121a232e | 7182 | if (buf == NULL) return; |
| pcercuei | 0:03b5121a232e | 7183 | if (buf->content == NULL) return; |
| pcercuei | 0:03b5121a232e | 7184 | buf->use = 0; |
| pcercuei | 0:03b5121a232e | 7185 | if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) { |
| pcercuei | 0:03b5121a232e | 7186 | buf->content = BAD_CAST ""; |
| pcercuei | 0:03b5121a232e | 7187 | } else if ((buf->alloc == XML_BUFFER_ALLOC_IO) && |
| pcercuei | 0:03b5121a232e | 7188 | (buf->contentIO != NULL)) { |
| pcercuei | 0:03b5121a232e | 7189 | size_t start_buf = buf->content - buf->contentIO; |
| pcercuei | 0:03b5121a232e | 7190 | |
| pcercuei | 0:03b5121a232e | 7191 | buf->size += start_buf; |
| pcercuei | 0:03b5121a232e | 7192 | buf->content = buf->contentIO; |
| pcercuei | 0:03b5121a232e | 7193 | buf->content[0] = 0; |
| pcercuei | 0:03b5121a232e | 7194 | } else { |
| pcercuei | 0:03b5121a232e | 7195 | buf->content[0] = 0; |
| pcercuei | 0:03b5121a232e | 7196 | } |
| pcercuei | 0:03b5121a232e | 7197 | } |
| pcercuei | 0:03b5121a232e | 7198 | |
| pcercuei | 0:03b5121a232e | 7199 | /** |
| pcercuei | 0:03b5121a232e | 7200 | * xmlBufferShrink: |
| pcercuei | 0:03b5121a232e | 7201 | * @buf: the buffer to dump |
| pcercuei | 0:03b5121a232e | 7202 | * @len: the number of xmlChar to remove |
| pcercuei | 0:03b5121a232e | 7203 | * |
| pcercuei | 0:03b5121a232e | 7204 | * Remove the beginning of an XML buffer. |
| pcercuei | 0:03b5121a232e | 7205 | * |
| pcercuei | 0:03b5121a232e | 7206 | * Returns the number of #xmlChar removed, or -1 in case of failure. |
| pcercuei | 0:03b5121a232e | 7207 | */ |
| pcercuei | 0:03b5121a232e | 7208 | int |
| pcercuei | 0:03b5121a232e | 7209 | xmlBufferShrink(xmlBufferPtr buf, unsigned int len) { |
| pcercuei | 0:03b5121a232e | 7210 | if (buf == NULL) return(-1); |
| pcercuei | 0:03b5121a232e | 7211 | if (len == 0) return(0); |
| pcercuei | 0:03b5121a232e | 7212 | if (len > buf->use) return(-1); |
| pcercuei | 0:03b5121a232e | 7213 | |
| pcercuei | 0:03b5121a232e | 7214 | buf->use -= len; |
| pcercuei | 0:03b5121a232e | 7215 | if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) || |
| pcercuei | 0:03b5121a232e | 7216 | ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL))) { |
| pcercuei | 0:03b5121a232e | 7217 | /* |
| pcercuei | 0:03b5121a232e | 7218 | * we just move the content pointer, but also make sure |
| pcercuei | 0:03b5121a232e | 7219 | * the perceived buffer size has shrinked accordingly |
| pcercuei | 0:03b5121a232e | 7220 | */ |
| pcercuei | 0:03b5121a232e | 7221 | buf->content += len; |
| pcercuei | 0:03b5121a232e | 7222 | buf->size -= len; |
| pcercuei | 0:03b5121a232e | 7223 | |
| pcercuei | 0:03b5121a232e | 7224 | /* |
| pcercuei | 0:03b5121a232e | 7225 | * sometimes though it maybe be better to really shrink |
| pcercuei | 0:03b5121a232e | 7226 | * on IO buffers |
| pcercuei | 0:03b5121a232e | 7227 | */ |
| pcercuei | 0:03b5121a232e | 7228 | if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { |
| pcercuei | 0:03b5121a232e | 7229 | size_t start_buf = buf->content - buf->contentIO; |
| pcercuei | 0:03b5121a232e | 7230 | if (start_buf >= buf->size) { |
| pcercuei | 0:03b5121a232e | 7231 | memmove(buf->contentIO, &buf->content[0], buf->use); |
| pcercuei | 0:03b5121a232e | 7232 | buf->content = buf->contentIO; |
| pcercuei | 0:03b5121a232e | 7233 | buf->content[buf->use] = 0; |
| pcercuei | 0:03b5121a232e | 7234 | buf->size += start_buf; |
| pcercuei | 0:03b5121a232e | 7235 | } |
| pcercuei | 0:03b5121a232e | 7236 | } |
| pcercuei | 0:03b5121a232e | 7237 | } else { |
| pcercuei | 0:03b5121a232e | 7238 | memmove(buf->content, &buf->content[len], buf->use); |
| pcercuei | 0:03b5121a232e | 7239 | buf->content[buf->use] = 0; |
| pcercuei | 0:03b5121a232e | 7240 | } |
| pcercuei | 0:03b5121a232e | 7241 | return(len); |
| pcercuei | 0:03b5121a232e | 7242 | } |
| pcercuei | 0:03b5121a232e | 7243 | |
| pcercuei | 0:03b5121a232e | 7244 | /** |
| pcercuei | 0:03b5121a232e | 7245 | * xmlBufferGrow: |
| pcercuei | 0:03b5121a232e | 7246 | * @buf: the buffer |
| pcercuei | 0:03b5121a232e | 7247 | * @len: the minimum free size to allocate |
| pcercuei | 0:03b5121a232e | 7248 | * |
| pcercuei | 0:03b5121a232e | 7249 | * Grow the available space of an XML buffer. |
| pcercuei | 0:03b5121a232e | 7250 | * |
| pcercuei | 0:03b5121a232e | 7251 | * Returns the new available space or -1 in case of error |
| pcercuei | 0:03b5121a232e | 7252 | */ |
| pcercuei | 0:03b5121a232e | 7253 | int |
| pcercuei | 0:03b5121a232e | 7254 | xmlBufferGrow(xmlBufferPtr buf, unsigned int len) { |
| pcercuei | 0:03b5121a232e | 7255 | int size; |
| pcercuei | 0:03b5121a232e | 7256 | xmlChar *newbuf; |
| pcercuei | 0:03b5121a232e | 7257 | |
| pcercuei | 0:03b5121a232e | 7258 | if (buf == NULL) return(-1); |
| pcercuei | 0:03b5121a232e | 7259 | |
| pcercuei | 0:03b5121a232e | 7260 | if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0); |
| pcercuei | 0:03b5121a232e | 7261 | if (len + buf->use < buf->size) return(0); |
| pcercuei | 0:03b5121a232e | 7262 | |
| pcercuei | 0:03b5121a232e | 7263 | /* |
| pcercuei | 0:03b5121a232e | 7264 | * Windows has a BIG problem on realloc timing, so we try to double |
| pcercuei | 0:03b5121a232e | 7265 | * the buffer size (if that's enough) (bug 146697) |
| pcercuei | 0:03b5121a232e | 7266 | * Apparently BSD too, and it's probably best for linux too |
| pcercuei | 0:03b5121a232e | 7267 | * On an embedded system this may be something to change |
| pcercuei | 0:03b5121a232e | 7268 | */ |
| pcercuei | 0:03b5121a232e | 7269 | #if 1 |
| pcercuei | 0:03b5121a232e | 7270 | if (buf->size > len) |
| pcercuei | 0:03b5121a232e | 7271 | size = buf->size * 2; |
| pcercuei | 0:03b5121a232e | 7272 | else |
| pcercuei | 0:03b5121a232e | 7273 | size = buf->use + len + 100; |
| pcercuei | 0:03b5121a232e | 7274 | #else |
| pcercuei | 0:03b5121a232e | 7275 | size = buf->use + len + 100; |
| pcercuei | 0:03b5121a232e | 7276 | #endif |
| pcercuei | 0:03b5121a232e | 7277 | |
| pcercuei | 0:03b5121a232e | 7278 | if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { |
| pcercuei | 0:03b5121a232e | 7279 | size_t start_buf = buf->content - buf->contentIO; |
| pcercuei | 0:03b5121a232e | 7280 | |
| pcercuei | 0:03b5121a232e | 7281 | newbuf = (xmlChar *) xmlRealloc(buf->contentIO, start_buf + size); |
| pcercuei | 0:03b5121a232e | 7282 | if (newbuf == NULL) { |
| pcercuei | 0:03b5121a232e | 7283 | xmlTreeErrMemory("growing buffer"); |
| pcercuei | 0:03b5121a232e | 7284 | return(-1); |
| pcercuei | 0:03b5121a232e | 7285 | } |
| pcercuei | 0:03b5121a232e | 7286 | buf->contentIO = newbuf; |
| pcercuei | 0:03b5121a232e | 7287 | buf->content = newbuf + start_buf; |
| pcercuei | 0:03b5121a232e | 7288 | } else { |
| pcercuei | 0:03b5121a232e | 7289 | newbuf = (xmlChar *) xmlRealloc(buf->content, size); |
| pcercuei | 0:03b5121a232e | 7290 | if (newbuf == NULL) { |
| pcercuei | 0:03b5121a232e | 7291 | xmlTreeErrMemory("growing buffer"); |
| pcercuei | 0:03b5121a232e | 7292 | return(-1); |
| pcercuei | 0:03b5121a232e | 7293 | } |
| pcercuei | 0:03b5121a232e | 7294 | buf->content = newbuf; |
| pcercuei | 0:03b5121a232e | 7295 | } |
| pcercuei | 0:03b5121a232e | 7296 | buf->size = size; |
| pcercuei | 0:03b5121a232e | 7297 | return(buf->size - buf->use); |
| pcercuei | 0:03b5121a232e | 7298 | } |
| pcercuei | 0:03b5121a232e | 7299 | |
| pcercuei | 0:03b5121a232e | 7300 | /** |
| pcercuei | 0:03b5121a232e | 7301 | * xmlBufferDump: |
| pcercuei | 0:03b5121a232e | 7302 | * @file: the file output |
| pcercuei | 0:03b5121a232e | 7303 | * @buf: the buffer to dump |
| pcercuei | 0:03b5121a232e | 7304 | * |
| pcercuei | 0:03b5121a232e | 7305 | * Dumps an XML buffer to a FILE *. |
| pcercuei | 0:03b5121a232e | 7306 | * Returns the number of #xmlChar written |
| pcercuei | 0:03b5121a232e | 7307 | */ |
| pcercuei | 0:03b5121a232e | 7308 | int |
| pcercuei | 0:03b5121a232e | 7309 | xmlBufferDump(FILE *file, xmlBufferPtr buf) { |
| pcercuei | 0:03b5121a232e | 7310 | int ret; |
| pcercuei | 0:03b5121a232e | 7311 | |
| pcercuei | 0:03b5121a232e | 7312 | if (buf == NULL) { |
| pcercuei | 0:03b5121a232e | 7313 | #ifdef DEBUG_BUFFER |
| pcercuei | 0:03b5121a232e | 7314 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 7315 | "xmlBufferDump: buf == NULL\n"); |
| pcercuei | 0:03b5121a232e | 7316 | #endif |
| pcercuei | 0:03b5121a232e | 7317 | return(0); |
| pcercuei | 0:03b5121a232e | 7318 | } |
| pcercuei | 0:03b5121a232e | 7319 | if (buf->content == NULL) { |
| pcercuei | 0:03b5121a232e | 7320 | #ifdef DEBUG_BUFFER |
| pcercuei | 0:03b5121a232e | 7321 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 7322 | "xmlBufferDump: buf->content == NULL\n"); |
| pcercuei | 0:03b5121a232e | 7323 | #endif |
| pcercuei | 0:03b5121a232e | 7324 | return(0); |
| pcercuei | 0:03b5121a232e | 7325 | } |
| pcercuei | 0:03b5121a232e | 7326 | if (file == NULL) |
| pcercuei | 0:03b5121a232e | 7327 | file = stdout; |
| pcercuei | 0:03b5121a232e | 7328 | ret = fwrite(buf->content, sizeof(xmlChar), buf->use, file); |
| pcercuei | 0:03b5121a232e | 7329 | return(ret); |
| pcercuei | 0:03b5121a232e | 7330 | } |
| pcercuei | 0:03b5121a232e | 7331 | |
| pcercuei | 0:03b5121a232e | 7332 | /** |
| pcercuei | 0:03b5121a232e | 7333 | * xmlBufferContent: |
| pcercuei | 0:03b5121a232e | 7334 | * @buf: the buffer |
| pcercuei | 0:03b5121a232e | 7335 | * |
| pcercuei | 0:03b5121a232e | 7336 | * Function to extract the content of a buffer |
| pcercuei | 0:03b5121a232e | 7337 | * |
| pcercuei | 0:03b5121a232e | 7338 | * Returns the internal content |
| pcercuei | 0:03b5121a232e | 7339 | */ |
| pcercuei | 0:03b5121a232e | 7340 | |
| pcercuei | 0:03b5121a232e | 7341 | const xmlChar * |
| pcercuei | 0:03b5121a232e | 7342 | xmlBufferContent(const xmlBuffer *buf) |
| pcercuei | 0:03b5121a232e | 7343 | { |
| pcercuei | 0:03b5121a232e | 7344 | if(!buf) |
| pcercuei | 0:03b5121a232e | 7345 | return NULL; |
| pcercuei | 0:03b5121a232e | 7346 | |
| pcercuei | 0:03b5121a232e | 7347 | return buf->content; |
| pcercuei | 0:03b5121a232e | 7348 | } |
| pcercuei | 0:03b5121a232e | 7349 | |
| pcercuei | 0:03b5121a232e | 7350 | /** |
| pcercuei | 0:03b5121a232e | 7351 | * xmlBufferLength: |
| pcercuei | 0:03b5121a232e | 7352 | * @buf: the buffer |
| pcercuei | 0:03b5121a232e | 7353 | * |
| pcercuei | 0:03b5121a232e | 7354 | * Function to get the length of a buffer |
| pcercuei | 0:03b5121a232e | 7355 | * |
| pcercuei | 0:03b5121a232e | 7356 | * Returns the length of data in the internal content |
| pcercuei | 0:03b5121a232e | 7357 | */ |
| pcercuei | 0:03b5121a232e | 7358 | |
| pcercuei | 0:03b5121a232e | 7359 | int |
| pcercuei | 0:03b5121a232e | 7360 | xmlBufferLength(const xmlBuffer *buf) |
| pcercuei | 0:03b5121a232e | 7361 | { |
| pcercuei | 0:03b5121a232e | 7362 | if(!buf) |
| pcercuei | 0:03b5121a232e | 7363 | return 0; |
| pcercuei | 0:03b5121a232e | 7364 | |
| pcercuei | 0:03b5121a232e | 7365 | return buf->use; |
| pcercuei | 0:03b5121a232e | 7366 | } |
| pcercuei | 0:03b5121a232e | 7367 | |
| pcercuei | 0:03b5121a232e | 7368 | /** |
| pcercuei | 0:03b5121a232e | 7369 | * xmlBufferResize: |
| pcercuei | 0:03b5121a232e | 7370 | * @buf: the buffer to resize |
| pcercuei | 0:03b5121a232e | 7371 | * @size: the desired size |
| pcercuei | 0:03b5121a232e | 7372 | * |
| pcercuei | 0:03b5121a232e | 7373 | * Resize a buffer to accommodate minimum size of @size. |
| pcercuei | 0:03b5121a232e | 7374 | * |
| pcercuei | 0:03b5121a232e | 7375 | * Returns 0 in case of problems, 1 otherwise |
| pcercuei | 0:03b5121a232e | 7376 | */ |
| pcercuei | 0:03b5121a232e | 7377 | int |
| pcercuei | 0:03b5121a232e | 7378 | xmlBufferResize(xmlBufferPtr buf, unsigned int size) |
| pcercuei | 0:03b5121a232e | 7379 | { |
| pcercuei | 0:03b5121a232e | 7380 | unsigned int newSize; |
| pcercuei | 0:03b5121a232e | 7381 | xmlChar* rebuf = NULL; |
| pcercuei | 0:03b5121a232e | 7382 | size_t start_buf; |
| pcercuei | 0:03b5121a232e | 7383 | |
| pcercuei | 0:03b5121a232e | 7384 | if (buf == NULL) |
| pcercuei | 0:03b5121a232e | 7385 | return(0); |
| pcercuei | 0:03b5121a232e | 7386 | |
| pcercuei | 0:03b5121a232e | 7387 | if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0); |
| pcercuei | 0:03b5121a232e | 7388 | |
| pcercuei | 0:03b5121a232e | 7389 | /* Don't resize if we don't have to */ |
| pcercuei | 0:03b5121a232e | 7390 | if (size < buf->size) |
| pcercuei | 0:03b5121a232e | 7391 | return 1; |
| pcercuei | 0:03b5121a232e | 7392 | |
| pcercuei | 0:03b5121a232e | 7393 | /* figure out new size */ |
| pcercuei | 0:03b5121a232e | 7394 | switch (buf->alloc){ |
| pcercuei | 0:03b5121a232e | 7395 | case XML_BUFFER_ALLOC_IO: |
| pcercuei | 0:03b5121a232e | 7396 | case XML_BUFFER_ALLOC_DOUBLEIT: |
| pcercuei | 0:03b5121a232e | 7397 | /*take care of empty case*/ |
| pcercuei | 0:03b5121a232e | 7398 | newSize = (buf->size ? buf->size*2 : size + 10); |
| pcercuei | 0:03b5121a232e | 7399 | while (size > newSize) { |
| pcercuei | 0:03b5121a232e | 7400 | if (newSize > UINT_MAX / 2) { |
| pcercuei | 0:03b5121a232e | 7401 | xmlTreeErrMemory("growing buffer"); |
| pcercuei | 0:03b5121a232e | 7402 | return 0; |
| pcercuei | 0:03b5121a232e | 7403 | } |
| pcercuei | 0:03b5121a232e | 7404 | newSize *= 2; |
| pcercuei | 0:03b5121a232e | 7405 | } |
| pcercuei | 0:03b5121a232e | 7406 | break; |
| pcercuei | 0:03b5121a232e | 7407 | case XML_BUFFER_ALLOC_EXACT: |
| pcercuei | 0:03b5121a232e | 7408 | newSize = size+10; |
| pcercuei | 0:03b5121a232e | 7409 | break; |
| pcercuei | 0:03b5121a232e | 7410 | case XML_BUFFER_ALLOC_HYBRID: |
| pcercuei | 0:03b5121a232e | 7411 | if (buf->use < BASE_BUFFER_SIZE) |
| pcercuei | 0:03b5121a232e | 7412 | newSize = size; |
| pcercuei | 0:03b5121a232e | 7413 | else { |
| pcercuei | 0:03b5121a232e | 7414 | newSize = buf->size * 2; |
| pcercuei | 0:03b5121a232e | 7415 | while (size > newSize) { |
| pcercuei | 0:03b5121a232e | 7416 | if (newSize > UINT_MAX / 2) { |
| pcercuei | 0:03b5121a232e | 7417 | xmlTreeErrMemory("growing buffer"); |
| pcercuei | 0:03b5121a232e | 7418 | return 0; |
| pcercuei | 0:03b5121a232e | 7419 | } |
| pcercuei | 0:03b5121a232e | 7420 | newSize *= 2; |
| pcercuei | 0:03b5121a232e | 7421 | } |
| pcercuei | 0:03b5121a232e | 7422 | } |
| pcercuei | 0:03b5121a232e | 7423 | break; |
| pcercuei | 0:03b5121a232e | 7424 | |
| pcercuei | 0:03b5121a232e | 7425 | default: |
| pcercuei | 0:03b5121a232e | 7426 | newSize = size+10; |
| pcercuei | 0:03b5121a232e | 7427 | break; |
| pcercuei | 0:03b5121a232e | 7428 | } |
| pcercuei | 0:03b5121a232e | 7429 | |
| pcercuei | 0:03b5121a232e | 7430 | if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { |
| pcercuei | 0:03b5121a232e | 7431 | start_buf = buf->content - buf->contentIO; |
| pcercuei | 0:03b5121a232e | 7432 | |
| pcercuei | 0:03b5121a232e | 7433 | if (start_buf > newSize) { |
| pcercuei | 0:03b5121a232e | 7434 | /* move data back to start */ |
| pcercuei | 0:03b5121a232e | 7435 | memmove(buf->contentIO, buf->content, buf->use); |
| pcercuei | 0:03b5121a232e | 7436 | buf->content = buf->contentIO; |
| pcercuei | 0:03b5121a232e | 7437 | buf->content[buf->use] = 0; |
| pcercuei | 0:03b5121a232e | 7438 | buf->size += start_buf; |
| pcercuei | 0:03b5121a232e | 7439 | } else { |
| pcercuei | 0:03b5121a232e | 7440 | rebuf = (xmlChar *) xmlRealloc(buf->contentIO, start_buf + newSize); |
| pcercuei | 0:03b5121a232e | 7441 | if (rebuf == NULL) { |
| pcercuei | 0:03b5121a232e | 7442 | xmlTreeErrMemory("growing buffer"); |
| pcercuei | 0:03b5121a232e | 7443 | return 0; |
| pcercuei | 0:03b5121a232e | 7444 | } |
| pcercuei | 0:03b5121a232e | 7445 | buf->contentIO = rebuf; |
| pcercuei | 0:03b5121a232e | 7446 | buf->content = rebuf + start_buf; |
| pcercuei | 0:03b5121a232e | 7447 | } |
| pcercuei | 0:03b5121a232e | 7448 | } else { |
| pcercuei | 0:03b5121a232e | 7449 | if (buf->content == NULL) { |
| pcercuei | 0:03b5121a232e | 7450 | rebuf = (xmlChar *) xmlMallocAtomic(newSize); |
| pcercuei | 0:03b5121a232e | 7451 | } else if (buf->size - buf->use < 100) { |
| pcercuei | 0:03b5121a232e | 7452 | rebuf = (xmlChar *) xmlRealloc(buf->content, newSize); |
| pcercuei | 0:03b5121a232e | 7453 | } else { |
| pcercuei | 0:03b5121a232e | 7454 | /* |
| pcercuei | 0:03b5121a232e | 7455 | * if we are reallocating a buffer far from being full, it's |
| pcercuei | 0:03b5121a232e | 7456 | * better to make a new allocation and copy only the used range |
| pcercuei | 0:03b5121a232e | 7457 | * and free the old one. |
| pcercuei | 0:03b5121a232e | 7458 | */ |
| pcercuei | 0:03b5121a232e | 7459 | rebuf = (xmlChar *) xmlMallocAtomic(newSize); |
| pcercuei | 0:03b5121a232e | 7460 | if (rebuf != NULL) { |
| pcercuei | 0:03b5121a232e | 7461 | memcpy(rebuf, buf->content, buf->use); |
| pcercuei | 0:03b5121a232e | 7462 | xmlFree(buf->content); |
| pcercuei | 0:03b5121a232e | 7463 | rebuf[buf->use] = 0; |
| pcercuei | 0:03b5121a232e | 7464 | } |
| pcercuei | 0:03b5121a232e | 7465 | } |
| pcercuei | 0:03b5121a232e | 7466 | if (rebuf == NULL) { |
| pcercuei | 0:03b5121a232e | 7467 | xmlTreeErrMemory("growing buffer"); |
| pcercuei | 0:03b5121a232e | 7468 | return 0; |
| pcercuei | 0:03b5121a232e | 7469 | } |
| pcercuei | 0:03b5121a232e | 7470 | buf->content = rebuf; |
| pcercuei | 0:03b5121a232e | 7471 | } |
| pcercuei | 0:03b5121a232e | 7472 | buf->size = newSize; |
| pcercuei | 0:03b5121a232e | 7473 | |
| pcercuei | 0:03b5121a232e | 7474 | return 1; |
| pcercuei | 0:03b5121a232e | 7475 | } |
| pcercuei | 0:03b5121a232e | 7476 | |
| pcercuei | 0:03b5121a232e | 7477 | /** |
| pcercuei | 0:03b5121a232e | 7478 | * xmlBufferAdd: |
| pcercuei | 0:03b5121a232e | 7479 | * @buf: the buffer to dump |
| pcercuei | 0:03b5121a232e | 7480 | * @str: the #xmlChar string |
| pcercuei | 0:03b5121a232e | 7481 | * @len: the number of #xmlChar to add |
| pcercuei | 0:03b5121a232e | 7482 | * |
| pcercuei | 0:03b5121a232e | 7483 | * Add a string range to an XML buffer. if len == -1, the length of |
| pcercuei | 0:03b5121a232e | 7484 | * str is recomputed. |
| pcercuei | 0:03b5121a232e | 7485 | * |
| pcercuei | 0:03b5121a232e | 7486 | * Returns 0 successful, a positive error code number otherwise |
| pcercuei | 0:03b5121a232e | 7487 | * and -1 in case of internal or API error. |
| pcercuei | 0:03b5121a232e | 7488 | */ |
| pcercuei | 0:03b5121a232e | 7489 | int |
| pcercuei | 0:03b5121a232e | 7490 | xmlBufferAdd(xmlBufferPtr buf, const xmlChar *str, int len) { |
| pcercuei | 0:03b5121a232e | 7491 | unsigned int needSize; |
| pcercuei | 0:03b5121a232e | 7492 | |
| pcercuei | 0:03b5121a232e | 7493 | if ((str == NULL) || (buf == NULL)) { |
| pcercuei | 0:03b5121a232e | 7494 | return -1; |
| pcercuei | 0:03b5121a232e | 7495 | } |
| pcercuei | 0:03b5121a232e | 7496 | if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; |
| pcercuei | 0:03b5121a232e | 7497 | if (len < -1) { |
| pcercuei | 0:03b5121a232e | 7498 | #ifdef DEBUG_BUFFER |
| pcercuei | 0:03b5121a232e | 7499 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 7500 | "xmlBufferAdd: len < 0\n"); |
| pcercuei | 0:03b5121a232e | 7501 | #endif |
| pcercuei | 0:03b5121a232e | 7502 | return -1; |
| pcercuei | 0:03b5121a232e | 7503 | } |
| pcercuei | 0:03b5121a232e | 7504 | if (len == 0) return 0; |
| pcercuei | 0:03b5121a232e | 7505 | |
| pcercuei | 0:03b5121a232e | 7506 | if (len < 0) |
| pcercuei | 0:03b5121a232e | 7507 | len = xmlStrlen(str); |
| pcercuei | 0:03b5121a232e | 7508 | |
| pcercuei | 0:03b5121a232e | 7509 | if (len < 0) return -1; |
| pcercuei | 0:03b5121a232e | 7510 | if (len == 0) return 0; |
| pcercuei | 0:03b5121a232e | 7511 | |
| pcercuei | 0:03b5121a232e | 7512 | needSize = buf->use + len + 2; |
| pcercuei | 0:03b5121a232e | 7513 | if (needSize > buf->size){ |
| pcercuei | 0:03b5121a232e | 7514 | if (!xmlBufferResize(buf, needSize)){ |
| pcercuei | 0:03b5121a232e | 7515 | xmlTreeErrMemory("growing buffer"); |
| pcercuei | 0:03b5121a232e | 7516 | return XML_ERR_NO_MEMORY; |
| pcercuei | 0:03b5121a232e | 7517 | } |
| pcercuei | 0:03b5121a232e | 7518 | } |
| pcercuei | 0:03b5121a232e | 7519 | |
| pcercuei | 0:03b5121a232e | 7520 | memmove(&buf->content[buf->use], str, len*sizeof(xmlChar)); |
| pcercuei | 0:03b5121a232e | 7521 | buf->use += len; |
| pcercuei | 0:03b5121a232e | 7522 | buf->content[buf->use] = 0; |
| pcercuei | 0:03b5121a232e | 7523 | return 0; |
| pcercuei | 0:03b5121a232e | 7524 | } |
| pcercuei | 0:03b5121a232e | 7525 | |
| pcercuei | 0:03b5121a232e | 7526 | /** |
| pcercuei | 0:03b5121a232e | 7527 | * xmlBufferAddHead: |
| pcercuei | 0:03b5121a232e | 7528 | * @buf: the buffer |
| pcercuei | 0:03b5121a232e | 7529 | * @str: the #xmlChar string |
| pcercuei | 0:03b5121a232e | 7530 | * @len: the number of #xmlChar to add |
| pcercuei | 0:03b5121a232e | 7531 | * |
| pcercuei | 0:03b5121a232e | 7532 | * Add a string range to the beginning of an XML buffer. |
| pcercuei | 0:03b5121a232e | 7533 | * if len == -1, the length of @str is recomputed. |
| pcercuei | 0:03b5121a232e | 7534 | * |
| pcercuei | 0:03b5121a232e | 7535 | * Returns 0 successful, a positive error code number otherwise |
| pcercuei | 0:03b5121a232e | 7536 | * and -1 in case of internal or API error. |
| pcercuei | 0:03b5121a232e | 7537 | */ |
| pcercuei | 0:03b5121a232e | 7538 | int |
| pcercuei | 0:03b5121a232e | 7539 | xmlBufferAddHead(xmlBufferPtr buf, const xmlChar *str, int len) { |
| pcercuei | 0:03b5121a232e | 7540 | unsigned int needSize; |
| pcercuei | 0:03b5121a232e | 7541 | |
| pcercuei | 0:03b5121a232e | 7542 | if (buf == NULL) |
| pcercuei | 0:03b5121a232e | 7543 | return(-1); |
| pcercuei | 0:03b5121a232e | 7544 | if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; |
| pcercuei | 0:03b5121a232e | 7545 | if (str == NULL) { |
| pcercuei | 0:03b5121a232e | 7546 | #ifdef DEBUG_BUFFER |
| pcercuei | 0:03b5121a232e | 7547 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 7548 | "xmlBufferAddHead: str == NULL\n"); |
| pcercuei | 0:03b5121a232e | 7549 | #endif |
| pcercuei | 0:03b5121a232e | 7550 | return -1; |
| pcercuei | 0:03b5121a232e | 7551 | } |
| pcercuei | 0:03b5121a232e | 7552 | if (len < -1) { |
| pcercuei | 0:03b5121a232e | 7553 | #ifdef DEBUG_BUFFER |
| pcercuei | 0:03b5121a232e | 7554 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 7555 | "xmlBufferAddHead: len < 0\n"); |
| pcercuei | 0:03b5121a232e | 7556 | #endif |
| pcercuei | 0:03b5121a232e | 7557 | return -1; |
| pcercuei | 0:03b5121a232e | 7558 | } |
| pcercuei | 0:03b5121a232e | 7559 | if (len == 0) return 0; |
| pcercuei | 0:03b5121a232e | 7560 | |
| pcercuei | 0:03b5121a232e | 7561 | if (len < 0) |
| pcercuei | 0:03b5121a232e | 7562 | len = xmlStrlen(str); |
| pcercuei | 0:03b5121a232e | 7563 | |
| pcercuei | 0:03b5121a232e | 7564 | if (len <= 0) return -1; |
| pcercuei | 0:03b5121a232e | 7565 | |
| pcercuei | 0:03b5121a232e | 7566 | if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { |
| pcercuei | 0:03b5121a232e | 7567 | size_t start_buf = buf->content - buf->contentIO; |
| pcercuei | 0:03b5121a232e | 7568 | |
| pcercuei | 0:03b5121a232e | 7569 | if (start_buf > (unsigned int) len) { |
| pcercuei | 0:03b5121a232e | 7570 | /* |
| pcercuei | 0:03b5121a232e | 7571 | * We can add it in the space previously shrinked |
| pcercuei | 0:03b5121a232e | 7572 | */ |
| pcercuei | 0:03b5121a232e | 7573 | buf->content -= len; |
| pcercuei | 0:03b5121a232e | 7574 | memmove(&buf->content[0], str, len); |
| pcercuei | 0:03b5121a232e | 7575 | buf->use += len; |
| pcercuei | 0:03b5121a232e | 7576 | buf->size += len; |
| pcercuei | 0:03b5121a232e | 7577 | return(0); |
| pcercuei | 0:03b5121a232e | 7578 | } |
| pcercuei | 0:03b5121a232e | 7579 | } |
| pcercuei | 0:03b5121a232e | 7580 | needSize = buf->use + len + 2; |
| pcercuei | 0:03b5121a232e | 7581 | if (needSize > buf->size){ |
| pcercuei | 0:03b5121a232e | 7582 | if (!xmlBufferResize(buf, needSize)){ |
| pcercuei | 0:03b5121a232e | 7583 | xmlTreeErrMemory("growing buffer"); |
| pcercuei | 0:03b5121a232e | 7584 | return XML_ERR_NO_MEMORY; |
| pcercuei | 0:03b5121a232e | 7585 | } |
| pcercuei | 0:03b5121a232e | 7586 | } |
| pcercuei | 0:03b5121a232e | 7587 | |
| pcercuei | 0:03b5121a232e | 7588 | memmove(&buf->content[len], &buf->content[0], buf->use); |
| pcercuei | 0:03b5121a232e | 7589 | memmove(&buf->content[0], str, len); |
| pcercuei | 0:03b5121a232e | 7590 | buf->use += len; |
| pcercuei | 0:03b5121a232e | 7591 | buf->content[buf->use] = 0; |
| pcercuei | 0:03b5121a232e | 7592 | return 0; |
| pcercuei | 0:03b5121a232e | 7593 | } |
| pcercuei | 0:03b5121a232e | 7594 | |
| pcercuei | 0:03b5121a232e | 7595 | /** |
| pcercuei | 0:03b5121a232e | 7596 | * xmlBufferCat: |
| pcercuei | 0:03b5121a232e | 7597 | * @buf: the buffer to add to |
| pcercuei | 0:03b5121a232e | 7598 | * @str: the #xmlChar string |
| pcercuei | 0:03b5121a232e | 7599 | * |
| pcercuei | 0:03b5121a232e | 7600 | * Append a zero terminated string to an XML buffer. |
| pcercuei | 0:03b5121a232e | 7601 | * |
| pcercuei | 0:03b5121a232e | 7602 | * Returns 0 successful, a positive error code number otherwise |
| pcercuei | 0:03b5121a232e | 7603 | * and -1 in case of internal or API error. |
| pcercuei | 0:03b5121a232e | 7604 | */ |
| pcercuei | 0:03b5121a232e | 7605 | int |
| pcercuei | 0:03b5121a232e | 7606 | xmlBufferCat(xmlBufferPtr buf, const xmlChar *str) { |
| pcercuei | 0:03b5121a232e | 7607 | if (buf == NULL) |
| pcercuei | 0:03b5121a232e | 7608 | return(-1); |
| pcercuei | 0:03b5121a232e | 7609 | if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; |
| pcercuei | 0:03b5121a232e | 7610 | if (str == NULL) return -1; |
| pcercuei | 0:03b5121a232e | 7611 | return xmlBufferAdd(buf, str, -1); |
| pcercuei | 0:03b5121a232e | 7612 | } |
| pcercuei | 0:03b5121a232e | 7613 | |
| pcercuei | 0:03b5121a232e | 7614 | /** |
| pcercuei | 0:03b5121a232e | 7615 | * xmlBufferCCat: |
| pcercuei | 0:03b5121a232e | 7616 | * @buf: the buffer to dump |
| pcercuei | 0:03b5121a232e | 7617 | * @str: the C char string |
| pcercuei | 0:03b5121a232e | 7618 | * |
| pcercuei | 0:03b5121a232e | 7619 | * Append a zero terminated C string to an XML buffer. |
| pcercuei | 0:03b5121a232e | 7620 | * |
| pcercuei | 0:03b5121a232e | 7621 | * Returns 0 successful, a positive error code number otherwise |
| pcercuei | 0:03b5121a232e | 7622 | * and -1 in case of internal or API error. |
| pcercuei | 0:03b5121a232e | 7623 | */ |
| pcercuei | 0:03b5121a232e | 7624 | int |
| pcercuei | 0:03b5121a232e | 7625 | xmlBufferCCat(xmlBufferPtr buf, const char *str) { |
| pcercuei | 0:03b5121a232e | 7626 | const char *cur; |
| pcercuei | 0:03b5121a232e | 7627 | |
| pcercuei | 0:03b5121a232e | 7628 | if (buf == NULL) |
| pcercuei | 0:03b5121a232e | 7629 | return(-1); |
| pcercuei | 0:03b5121a232e | 7630 | if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return -1; |
| pcercuei | 0:03b5121a232e | 7631 | if (str == NULL) { |
| pcercuei | 0:03b5121a232e | 7632 | #ifdef DEBUG_BUFFER |
| pcercuei | 0:03b5121a232e | 7633 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 7634 | "xmlBufferCCat: str == NULL\n"); |
| pcercuei | 0:03b5121a232e | 7635 | #endif |
| pcercuei | 0:03b5121a232e | 7636 | return -1; |
| pcercuei | 0:03b5121a232e | 7637 | } |
| pcercuei | 0:03b5121a232e | 7638 | for (cur = str;*cur != 0;cur++) { |
| pcercuei | 0:03b5121a232e | 7639 | if (buf->use + 10 >= buf->size) { |
| pcercuei | 0:03b5121a232e | 7640 | if (!xmlBufferResize(buf, buf->use+10)){ |
| pcercuei | 0:03b5121a232e | 7641 | xmlTreeErrMemory("growing buffer"); |
| pcercuei | 0:03b5121a232e | 7642 | return XML_ERR_NO_MEMORY; |
| pcercuei | 0:03b5121a232e | 7643 | } |
| pcercuei | 0:03b5121a232e | 7644 | } |
| pcercuei | 0:03b5121a232e | 7645 | buf->content[buf->use++] = *cur; |
| pcercuei | 0:03b5121a232e | 7646 | } |
| pcercuei | 0:03b5121a232e | 7647 | buf->content[buf->use] = 0; |
| pcercuei | 0:03b5121a232e | 7648 | return 0; |
| pcercuei | 0:03b5121a232e | 7649 | } |
| pcercuei | 0:03b5121a232e | 7650 | |
| pcercuei | 0:03b5121a232e | 7651 | /** |
| pcercuei | 0:03b5121a232e | 7652 | * xmlBufferWriteCHAR: |
| pcercuei | 0:03b5121a232e | 7653 | * @buf: the XML buffer |
| pcercuei | 0:03b5121a232e | 7654 | * @string: the string to add |
| pcercuei | 0:03b5121a232e | 7655 | * |
| pcercuei | 0:03b5121a232e | 7656 | * routine which manages and grows an output buffer. This one adds |
| pcercuei | 0:03b5121a232e | 7657 | * xmlChars at the end of the buffer. |
| pcercuei | 0:03b5121a232e | 7658 | */ |
| pcercuei | 0:03b5121a232e | 7659 | void |
| pcercuei | 0:03b5121a232e | 7660 | xmlBufferWriteCHAR(xmlBufferPtr buf, const xmlChar *string) { |
| pcercuei | 0:03b5121a232e | 7661 | if (buf == NULL) |
| pcercuei | 0:03b5121a232e | 7662 | return; |
| pcercuei | 0:03b5121a232e | 7663 | if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return; |
| pcercuei | 0:03b5121a232e | 7664 | xmlBufferCat(buf, string); |
| pcercuei | 0:03b5121a232e | 7665 | } |
| pcercuei | 0:03b5121a232e | 7666 | |
| pcercuei | 0:03b5121a232e | 7667 | /** |
| pcercuei | 0:03b5121a232e | 7668 | * xmlBufferWriteChar: |
| pcercuei | 0:03b5121a232e | 7669 | * @buf: the XML buffer output |
| pcercuei | 0:03b5121a232e | 7670 | * @string: the string to add |
| pcercuei | 0:03b5121a232e | 7671 | * |
| pcercuei | 0:03b5121a232e | 7672 | * routine which manage and grows an output buffer. This one add |
| pcercuei | 0:03b5121a232e | 7673 | * C chars at the end of the array. |
| pcercuei | 0:03b5121a232e | 7674 | */ |
| pcercuei | 0:03b5121a232e | 7675 | void |
| pcercuei | 0:03b5121a232e | 7676 | xmlBufferWriteChar(xmlBufferPtr buf, const char *string) { |
| pcercuei | 0:03b5121a232e | 7677 | if (buf == NULL) |
| pcercuei | 0:03b5121a232e | 7678 | return; |
| pcercuei | 0:03b5121a232e | 7679 | if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return; |
| pcercuei | 0:03b5121a232e | 7680 | xmlBufferCCat(buf, string); |
| pcercuei | 0:03b5121a232e | 7681 | } |
| pcercuei | 0:03b5121a232e | 7682 | |
| pcercuei | 0:03b5121a232e | 7683 | |
| pcercuei | 0:03b5121a232e | 7684 | /** |
| pcercuei | 0:03b5121a232e | 7685 | * xmlBufferWriteQuotedString: |
| pcercuei | 0:03b5121a232e | 7686 | * @buf: the XML buffer output |
| pcercuei | 0:03b5121a232e | 7687 | * @string: the string to add |
| pcercuei | 0:03b5121a232e | 7688 | * |
| pcercuei | 0:03b5121a232e | 7689 | * routine which manage and grows an output buffer. This one writes |
| pcercuei | 0:03b5121a232e | 7690 | * a quoted or double quoted #xmlChar string, checking first if it holds |
| pcercuei | 0:03b5121a232e | 7691 | * quote or double-quotes internally |
| pcercuei | 0:03b5121a232e | 7692 | */ |
| pcercuei | 0:03b5121a232e | 7693 | void |
| pcercuei | 0:03b5121a232e | 7694 | xmlBufferWriteQuotedString(xmlBufferPtr buf, const xmlChar *string) { |
| pcercuei | 0:03b5121a232e | 7695 | const xmlChar *cur, *base; |
| pcercuei | 0:03b5121a232e | 7696 | if (buf == NULL) |
| pcercuei | 0:03b5121a232e | 7697 | return; |
| pcercuei | 0:03b5121a232e | 7698 | if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return; |
| pcercuei | 0:03b5121a232e | 7699 | if (xmlStrchr(string, '\"')) { |
| pcercuei | 0:03b5121a232e | 7700 | if (xmlStrchr(string, '\'')) { |
| pcercuei | 0:03b5121a232e | 7701 | #ifdef DEBUG_BUFFER |
| pcercuei | 0:03b5121a232e | 7702 | xmlGenericError(xmlGenericErrorContext, |
| pcercuei | 0:03b5121a232e | 7703 | "xmlBufferWriteQuotedString: string contains quote and double-quotes !\n"); |
| pcercuei | 0:03b5121a232e | 7704 | #endif |
| pcercuei | 0:03b5121a232e | 7705 | xmlBufferCCat(buf, "\""); |
| pcercuei | 0:03b5121a232e | 7706 | base = cur = string; |
| pcercuei | 0:03b5121a232e | 7707 | while(*cur != 0){ |
| pcercuei | 0:03b5121a232e | 7708 | if(*cur == '"'){ |
| pcercuei | 0:03b5121a232e | 7709 | if (base != cur) |
| pcercuei | 0:03b5121a232e | 7710 | xmlBufferAdd(buf, base, cur - base); |
| pcercuei | 0:03b5121a232e | 7711 | xmlBufferAdd(buf, BAD_CAST """, 6); |
| pcercuei | 0:03b5121a232e | 7712 | cur++; |
| pcercuei | 0:03b5121a232e | 7713 | base = cur; |
| pcercuei | 0:03b5121a232e | 7714 | } |
| pcercuei | 0:03b5121a232e | 7715 | else { |
| pcercuei | 0:03b5121a232e | 7716 | cur++; |
| pcercuei | 0:03b5121a232e | 7717 | } |
| pcercuei | 0:03b5121a232e | 7718 | } |
| pcercuei | 0:03b5121a232e | 7719 | if (base != cur) |
| pcercuei | 0:03b5121a232e | 7720 | xmlBufferAdd(buf, base, cur - base); |
| pcercuei | 0:03b5121a232e | 7721 | xmlBufferCCat(buf, "\""); |
| pcercuei | 0:03b5121a232e | 7722 | } |
| pcercuei | 0:03b5121a232e | 7723 | else{ |
| pcercuei | 0:03b5121a232e | 7724 | xmlBufferCCat(buf, "\'"); |
| pcercuei | 0:03b5121a232e | 7725 | xmlBufferCat(buf, string); |
| pcercuei | 0:03b5121a232e | 7726 | xmlBufferCCat(buf, "\'"); |
| pcercuei | 0:03b5121a232e | 7727 | } |
| pcercuei | 0:03b5121a232e | 7728 | } else { |
| pcercuei | 0:03b5121a232e | 7729 | xmlBufferCCat(buf, "\""); |
| pcercuei | 0:03b5121a232e | 7730 | xmlBufferCat(buf, string); |
| pcercuei | 0:03b5121a232e | 7731 | xmlBufferCCat(buf, "\""); |
| pcercuei | 0:03b5121a232e | 7732 | } |
| pcercuei | 0:03b5121a232e | 7733 | } |
| pcercuei | 0:03b5121a232e | 7734 | |
| pcercuei | 0:03b5121a232e | 7735 | |
| pcercuei | 0:03b5121a232e | 7736 | /** |
| pcercuei | 0:03b5121a232e | 7737 | * xmlGetDocCompressMode: |
| pcercuei | 0:03b5121a232e | 7738 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 7739 | * |
| pcercuei | 0:03b5121a232e | 7740 | * get the compression ratio for a document, ZLIB based |
| pcercuei | 0:03b5121a232e | 7741 | * Returns 0 (uncompressed) to 9 (max compression) |
| pcercuei | 0:03b5121a232e | 7742 | */ |
| pcercuei | 0:03b5121a232e | 7743 | int |
| pcercuei | 0:03b5121a232e | 7744 | xmlGetDocCompressMode (const xmlDoc *doc) { |
| pcercuei | 0:03b5121a232e | 7745 | if (doc == NULL) return(-1); |
| pcercuei | 0:03b5121a232e | 7746 | return(doc->compression); |
| pcercuei | 0:03b5121a232e | 7747 | } |
| pcercuei | 0:03b5121a232e | 7748 | |
| pcercuei | 0:03b5121a232e | 7749 | /** |
| pcercuei | 0:03b5121a232e | 7750 | * xmlSetDocCompressMode: |
| pcercuei | 0:03b5121a232e | 7751 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 7752 | * @mode: the compression ratio |
| pcercuei | 0:03b5121a232e | 7753 | * |
| pcercuei | 0:03b5121a232e | 7754 | * set the compression ratio for a document, ZLIB based |
| pcercuei | 0:03b5121a232e | 7755 | * Correct values: 0 (uncompressed) to 9 (max compression) |
| pcercuei | 0:03b5121a232e | 7756 | */ |
| pcercuei | 0:03b5121a232e | 7757 | void |
| pcercuei | 0:03b5121a232e | 7758 | xmlSetDocCompressMode (xmlDocPtr doc, int mode) { |
| pcercuei | 0:03b5121a232e | 7759 | if (doc == NULL) return; |
| pcercuei | 0:03b5121a232e | 7760 | if (mode < 0) doc->compression = 0; |
| pcercuei | 0:03b5121a232e | 7761 | else if (mode > 9) doc->compression = 9; |
| pcercuei | 0:03b5121a232e | 7762 | else doc->compression = mode; |
| pcercuei | 0:03b5121a232e | 7763 | } |
| pcercuei | 0:03b5121a232e | 7764 | |
| pcercuei | 0:03b5121a232e | 7765 | /** |
| pcercuei | 0:03b5121a232e | 7766 | * xmlGetCompressMode: |
| pcercuei | 0:03b5121a232e | 7767 | * |
| pcercuei | 0:03b5121a232e | 7768 | * get the default compression mode used, ZLIB based. |
| pcercuei | 0:03b5121a232e | 7769 | * Returns 0 (uncompressed) to 9 (max compression) |
| pcercuei | 0:03b5121a232e | 7770 | */ |
| pcercuei | 0:03b5121a232e | 7771 | int |
| pcercuei | 0:03b5121a232e | 7772 | xmlGetCompressMode(void) |
| pcercuei | 0:03b5121a232e | 7773 | { |
| pcercuei | 0:03b5121a232e | 7774 | return (xmlCompressMode); |
| pcercuei | 0:03b5121a232e | 7775 | } |
| pcercuei | 0:03b5121a232e | 7776 | |
| pcercuei | 0:03b5121a232e | 7777 | /** |
| pcercuei | 0:03b5121a232e | 7778 | * xmlSetCompressMode: |
| pcercuei | 0:03b5121a232e | 7779 | * @mode: the compression ratio |
| pcercuei | 0:03b5121a232e | 7780 | * |
| pcercuei | 0:03b5121a232e | 7781 | * set the default compression mode used, ZLIB based |
| pcercuei | 0:03b5121a232e | 7782 | * Correct values: 0 (uncompressed) to 9 (max compression) |
| pcercuei | 0:03b5121a232e | 7783 | */ |
| pcercuei | 0:03b5121a232e | 7784 | void |
| pcercuei | 0:03b5121a232e | 7785 | xmlSetCompressMode(int mode) { |
| pcercuei | 0:03b5121a232e | 7786 | if (mode < 0) xmlCompressMode = 0; |
| pcercuei | 0:03b5121a232e | 7787 | else if (mode > 9) xmlCompressMode = 9; |
| pcercuei | 0:03b5121a232e | 7788 | else xmlCompressMode = mode; |
| pcercuei | 0:03b5121a232e | 7789 | } |
| pcercuei | 0:03b5121a232e | 7790 | |
| pcercuei | 0:03b5121a232e | 7791 | #define XML_TREE_NSMAP_PARENT -1 |
| pcercuei | 0:03b5121a232e | 7792 | #define XML_TREE_NSMAP_XML -2 |
| pcercuei | 0:03b5121a232e | 7793 | #define XML_TREE_NSMAP_DOC -3 |
| pcercuei | 0:03b5121a232e | 7794 | #define XML_TREE_NSMAP_CUSTOM -4 |
| pcercuei | 0:03b5121a232e | 7795 | |
| pcercuei | 0:03b5121a232e | 7796 | typedef struct xmlNsMapItem *xmlNsMapItemPtr; |
| pcercuei | 0:03b5121a232e | 7797 | struct xmlNsMapItem { |
| pcercuei | 0:03b5121a232e | 7798 | xmlNsMapItemPtr next; |
| pcercuei | 0:03b5121a232e | 7799 | xmlNsMapItemPtr prev; |
| pcercuei | 0:03b5121a232e | 7800 | xmlNsPtr oldNs; /* old ns decl reference */ |
| pcercuei | 0:03b5121a232e | 7801 | xmlNsPtr newNs; /* new ns decl reference */ |
| pcercuei | 0:03b5121a232e | 7802 | int shadowDepth; /* Shadowed at this depth */ |
| pcercuei | 0:03b5121a232e | 7803 | /* |
| pcercuei | 0:03b5121a232e | 7804 | * depth: |
| pcercuei | 0:03b5121a232e | 7805 | * >= 0 == @node's ns-decls |
| pcercuei | 0:03b5121a232e | 7806 | * -1 == @parent's ns-decls |
| pcercuei | 0:03b5121a232e | 7807 | * -2 == the doc->oldNs XML ns-decl |
| pcercuei | 0:03b5121a232e | 7808 | * -3 == the doc->oldNs storage ns-decls |
| pcercuei | 0:03b5121a232e | 7809 | * -4 == ns-decls provided via custom ns-handling |
| pcercuei | 0:03b5121a232e | 7810 | */ |
| pcercuei | 0:03b5121a232e | 7811 | int depth; |
| pcercuei | 0:03b5121a232e | 7812 | }; |
| pcercuei | 0:03b5121a232e | 7813 | |
| pcercuei | 0:03b5121a232e | 7814 | typedef struct xmlNsMap *xmlNsMapPtr; |
| pcercuei | 0:03b5121a232e | 7815 | struct xmlNsMap { |
| pcercuei | 0:03b5121a232e | 7816 | xmlNsMapItemPtr first; |
| pcercuei | 0:03b5121a232e | 7817 | xmlNsMapItemPtr last; |
| pcercuei | 0:03b5121a232e | 7818 | xmlNsMapItemPtr pool; |
| pcercuei | 0:03b5121a232e | 7819 | }; |
| pcercuei | 0:03b5121a232e | 7820 | |
| pcercuei | 0:03b5121a232e | 7821 | #define XML_NSMAP_NOTEMPTY(m) (((m) != NULL) && ((m)->first != NULL)) |
| pcercuei | 0:03b5121a232e | 7822 | #define XML_NSMAP_FOREACH(m, i) for (i = (m)->first; i != NULL; i = (i)->next) |
| pcercuei | 0:03b5121a232e | 7823 | #define XML_NSMAP_POP(m, i) \ |
| pcercuei | 0:03b5121a232e | 7824 | i = (m)->last; \ |
| pcercuei | 0:03b5121a232e | 7825 | (m)->last = (i)->prev; \ |
| pcercuei | 0:03b5121a232e | 7826 | if ((m)->last == NULL) \ |
| pcercuei | 0:03b5121a232e | 7827 | (m)->first = NULL; \ |
| pcercuei | 0:03b5121a232e | 7828 | else \ |
| pcercuei | 0:03b5121a232e | 7829 | (m)->last->next = NULL; \ |
| pcercuei | 0:03b5121a232e | 7830 | (i)->next = (m)->pool; \ |
| pcercuei | 0:03b5121a232e | 7831 | (m)->pool = i; |
| pcercuei | 0:03b5121a232e | 7832 | |
| pcercuei | 0:03b5121a232e | 7833 | /* |
| pcercuei | 0:03b5121a232e | 7834 | * xmlDOMWrapNsMapFree: |
| pcercuei | 0:03b5121a232e | 7835 | * @map: the ns-map |
| pcercuei | 0:03b5121a232e | 7836 | * |
| pcercuei | 0:03b5121a232e | 7837 | * Frees the ns-map |
| pcercuei | 0:03b5121a232e | 7838 | */ |
| pcercuei | 0:03b5121a232e | 7839 | static void |
| pcercuei | 0:03b5121a232e | 7840 | xmlDOMWrapNsMapFree(xmlNsMapPtr nsmap) |
| pcercuei | 0:03b5121a232e | 7841 | { |
| pcercuei | 0:03b5121a232e | 7842 | xmlNsMapItemPtr cur, tmp; |
| pcercuei | 0:03b5121a232e | 7843 | |
| pcercuei | 0:03b5121a232e | 7844 | if (nsmap == NULL) |
| pcercuei | 0:03b5121a232e | 7845 | return; |
| pcercuei | 0:03b5121a232e | 7846 | cur = nsmap->pool; |
| pcercuei | 0:03b5121a232e | 7847 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 7848 | tmp = cur; |
| pcercuei | 0:03b5121a232e | 7849 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 7850 | xmlFree(tmp); |
| pcercuei | 0:03b5121a232e | 7851 | } |
| pcercuei | 0:03b5121a232e | 7852 | cur = nsmap->first; |
| pcercuei | 0:03b5121a232e | 7853 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 7854 | tmp = cur; |
| pcercuei | 0:03b5121a232e | 7855 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 7856 | xmlFree(tmp); |
| pcercuei | 0:03b5121a232e | 7857 | } |
| pcercuei | 0:03b5121a232e | 7858 | xmlFree(nsmap); |
| pcercuei | 0:03b5121a232e | 7859 | } |
| pcercuei | 0:03b5121a232e | 7860 | |
| pcercuei | 0:03b5121a232e | 7861 | /* |
| pcercuei | 0:03b5121a232e | 7862 | * xmlDOMWrapNsMapAddItem: |
| pcercuei | 0:03b5121a232e | 7863 | * @map: the ns-map |
| pcercuei | 0:03b5121a232e | 7864 | * @oldNs: the old ns-struct |
| pcercuei | 0:03b5121a232e | 7865 | * @newNs: the new ns-struct |
| pcercuei | 0:03b5121a232e | 7866 | * @depth: depth and ns-kind information |
| pcercuei | 0:03b5121a232e | 7867 | * |
| pcercuei | 0:03b5121a232e | 7868 | * Adds an ns-mapping item. |
| pcercuei | 0:03b5121a232e | 7869 | */ |
| pcercuei | 0:03b5121a232e | 7870 | static xmlNsMapItemPtr |
| pcercuei | 0:03b5121a232e | 7871 | xmlDOMWrapNsMapAddItem(xmlNsMapPtr *nsmap, int position, |
| pcercuei | 0:03b5121a232e | 7872 | xmlNsPtr oldNs, xmlNsPtr newNs, int depth) |
| pcercuei | 0:03b5121a232e | 7873 | { |
| pcercuei | 0:03b5121a232e | 7874 | xmlNsMapItemPtr ret; |
| pcercuei | 0:03b5121a232e | 7875 | xmlNsMapPtr map; |
| pcercuei | 0:03b5121a232e | 7876 | |
| pcercuei | 0:03b5121a232e | 7877 | if (nsmap == NULL) |
| pcercuei | 0:03b5121a232e | 7878 | return(NULL); |
| pcercuei | 0:03b5121a232e | 7879 | if ((position != -1) && (position != 0)) |
| pcercuei | 0:03b5121a232e | 7880 | return(NULL); |
| pcercuei | 0:03b5121a232e | 7881 | map = *nsmap; |
| pcercuei | 0:03b5121a232e | 7882 | |
| pcercuei | 0:03b5121a232e | 7883 | if (map == NULL) { |
| pcercuei | 0:03b5121a232e | 7884 | /* |
| pcercuei | 0:03b5121a232e | 7885 | * Create the ns-map. |
| pcercuei | 0:03b5121a232e | 7886 | */ |
| pcercuei | 0:03b5121a232e | 7887 | map = (xmlNsMapPtr) xmlMalloc(sizeof(struct xmlNsMap)); |
| pcercuei | 0:03b5121a232e | 7888 | if (map == NULL) { |
| pcercuei | 0:03b5121a232e | 7889 | xmlTreeErrMemory("allocating namespace map"); |
| pcercuei | 0:03b5121a232e | 7890 | return (NULL); |
| pcercuei | 0:03b5121a232e | 7891 | } |
| pcercuei | 0:03b5121a232e | 7892 | memset(map, 0, sizeof(struct xmlNsMap)); |
| pcercuei | 0:03b5121a232e | 7893 | *nsmap = map; |
| pcercuei | 0:03b5121a232e | 7894 | } |
| pcercuei | 0:03b5121a232e | 7895 | |
| pcercuei | 0:03b5121a232e | 7896 | if (map->pool != NULL) { |
| pcercuei | 0:03b5121a232e | 7897 | /* |
| pcercuei | 0:03b5121a232e | 7898 | * Reuse an item from the pool. |
| pcercuei | 0:03b5121a232e | 7899 | */ |
| pcercuei | 0:03b5121a232e | 7900 | ret = map->pool; |
| pcercuei | 0:03b5121a232e | 7901 | map->pool = ret->next; |
| pcercuei | 0:03b5121a232e | 7902 | memset(ret, 0, sizeof(struct xmlNsMapItem)); |
| pcercuei | 0:03b5121a232e | 7903 | } else { |
| pcercuei | 0:03b5121a232e | 7904 | /* |
| pcercuei | 0:03b5121a232e | 7905 | * Create a new item. |
| pcercuei | 0:03b5121a232e | 7906 | */ |
| pcercuei | 0:03b5121a232e | 7907 | ret = (xmlNsMapItemPtr) xmlMalloc(sizeof(struct xmlNsMapItem)); |
| pcercuei | 0:03b5121a232e | 7908 | if (ret == NULL) { |
| pcercuei | 0:03b5121a232e | 7909 | xmlTreeErrMemory("allocating namespace map item"); |
| pcercuei | 0:03b5121a232e | 7910 | return (NULL); |
| pcercuei | 0:03b5121a232e | 7911 | } |
| pcercuei | 0:03b5121a232e | 7912 | memset(ret, 0, sizeof(struct xmlNsMapItem)); |
| pcercuei | 0:03b5121a232e | 7913 | } |
| pcercuei | 0:03b5121a232e | 7914 | |
| pcercuei | 0:03b5121a232e | 7915 | if (map->first == NULL) { |
| pcercuei | 0:03b5121a232e | 7916 | /* |
| pcercuei | 0:03b5121a232e | 7917 | * First ever. |
| pcercuei | 0:03b5121a232e | 7918 | */ |
| pcercuei | 0:03b5121a232e | 7919 | map->first = ret; |
| pcercuei | 0:03b5121a232e | 7920 | map->last = ret; |
| pcercuei | 0:03b5121a232e | 7921 | } else if (position == -1) { |
| pcercuei | 0:03b5121a232e | 7922 | /* |
| pcercuei | 0:03b5121a232e | 7923 | * Append. |
| pcercuei | 0:03b5121a232e | 7924 | */ |
| pcercuei | 0:03b5121a232e | 7925 | ret->prev = map->last; |
| pcercuei | 0:03b5121a232e | 7926 | map->last->next = ret; |
| pcercuei | 0:03b5121a232e | 7927 | map->last = ret; |
| pcercuei | 0:03b5121a232e | 7928 | } else if (position == 0) { |
| pcercuei | 0:03b5121a232e | 7929 | /* |
| pcercuei | 0:03b5121a232e | 7930 | * Set on first position. |
| pcercuei | 0:03b5121a232e | 7931 | */ |
| pcercuei | 0:03b5121a232e | 7932 | map->first->prev = ret; |
| pcercuei | 0:03b5121a232e | 7933 | ret->next = map->first; |
| pcercuei | 0:03b5121a232e | 7934 | map->first = ret; |
| pcercuei | 0:03b5121a232e | 7935 | } |
| pcercuei | 0:03b5121a232e | 7936 | |
| pcercuei | 0:03b5121a232e | 7937 | ret->oldNs = oldNs; |
| pcercuei | 0:03b5121a232e | 7938 | ret->newNs = newNs; |
| pcercuei | 0:03b5121a232e | 7939 | ret->shadowDepth = -1; |
| pcercuei | 0:03b5121a232e | 7940 | ret->depth = depth; |
| pcercuei | 0:03b5121a232e | 7941 | return (ret); |
| pcercuei | 0:03b5121a232e | 7942 | } |
| pcercuei | 0:03b5121a232e | 7943 | |
| pcercuei | 0:03b5121a232e | 7944 | /* |
| pcercuei | 0:03b5121a232e | 7945 | * xmlDOMWrapStoreNs: |
| pcercuei | 0:03b5121a232e | 7946 | * @doc: the doc |
| pcercuei | 0:03b5121a232e | 7947 | * @nsName: the namespace name |
| pcercuei | 0:03b5121a232e | 7948 | * @prefix: the prefix |
| pcercuei | 0:03b5121a232e | 7949 | * |
| pcercuei | 0:03b5121a232e | 7950 | * Creates or reuses an xmlNs struct on doc->oldNs with |
| pcercuei | 0:03b5121a232e | 7951 | * the given prefix and namespace name. |
| pcercuei | 0:03b5121a232e | 7952 | * |
| pcercuei | 0:03b5121a232e | 7953 | * Returns the aquired ns struct or NULL in case of an API |
| pcercuei | 0:03b5121a232e | 7954 | * or internal error. |
| pcercuei | 0:03b5121a232e | 7955 | */ |
| pcercuei | 0:03b5121a232e | 7956 | static xmlNsPtr |
| pcercuei | 0:03b5121a232e | 7957 | xmlDOMWrapStoreNs(xmlDocPtr doc, |
| pcercuei | 0:03b5121a232e | 7958 | const xmlChar *nsName, |
| pcercuei | 0:03b5121a232e | 7959 | const xmlChar *prefix) |
| pcercuei | 0:03b5121a232e | 7960 | { |
| pcercuei | 0:03b5121a232e | 7961 | xmlNsPtr ns; |
| pcercuei | 0:03b5121a232e | 7962 | |
| pcercuei | 0:03b5121a232e | 7963 | if (doc == NULL) |
| pcercuei | 0:03b5121a232e | 7964 | return (NULL); |
| pcercuei | 0:03b5121a232e | 7965 | ns = xmlTreeEnsureXMLDecl(doc); |
| pcercuei | 0:03b5121a232e | 7966 | if (ns == NULL) |
| pcercuei | 0:03b5121a232e | 7967 | return (NULL); |
| pcercuei | 0:03b5121a232e | 7968 | if (ns->next != NULL) { |
| pcercuei | 0:03b5121a232e | 7969 | /* Reuse. */ |
| pcercuei | 0:03b5121a232e | 7970 | ns = ns->next; |
| pcercuei | 0:03b5121a232e | 7971 | while (ns != NULL) { |
| pcercuei | 0:03b5121a232e | 7972 | if (((ns->prefix == prefix) || |
| pcercuei | 0:03b5121a232e | 7973 | xmlStrEqual(ns->prefix, prefix)) && |
| pcercuei | 0:03b5121a232e | 7974 | xmlStrEqual(ns->href, nsName)) { |
| pcercuei | 0:03b5121a232e | 7975 | return (ns); |
| pcercuei | 0:03b5121a232e | 7976 | } |
| pcercuei | 0:03b5121a232e | 7977 | if (ns->next == NULL) |
| pcercuei | 0:03b5121a232e | 7978 | break; |
| pcercuei | 0:03b5121a232e | 7979 | ns = ns->next; |
| pcercuei | 0:03b5121a232e | 7980 | } |
| pcercuei | 0:03b5121a232e | 7981 | } |
| pcercuei | 0:03b5121a232e | 7982 | /* Create. */ |
| pcercuei | 0:03b5121a232e | 7983 | if (ns != NULL) { |
| pcercuei | 0:03b5121a232e | 7984 | ns->next = xmlNewNs(NULL, nsName, prefix); |
| pcercuei | 0:03b5121a232e | 7985 | return (ns->next); |
| pcercuei | 0:03b5121a232e | 7986 | } |
| pcercuei | 0:03b5121a232e | 7987 | return(NULL); |
| pcercuei | 0:03b5121a232e | 7988 | } |
| pcercuei | 0:03b5121a232e | 7989 | |
| pcercuei | 0:03b5121a232e | 7990 | /* |
| pcercuei | 0:03b5121a232e | 7991 | * xmlDOMWrapNewCtxt: |
| pcercuei | 0:03b5121a232e | 7992 | * |
| pcercuei | 0:03b5121a232e | 7993 | * Allocates and initializes a new DOM-wrapper context. |
| pcercuei | 0:03b5121a232e | 7994 | * |
| pcercuei | 0:03b5121a232e | 7995 | * Returns the xmlDOMWrapCtxtPtr or NULL in case of an internal error. |
| pcercuei | 0:03b5121a232e | 7996 | */ |
| pcercuei | 0:03b5121a232e | 7997 | xmlDOMWrapCtxtPtr |
| pcercuei | 0:03b5121a232e | 7998 | xmlDOMWrapNewCtxt(void) |
| pcercuei | 0:03b5121a232e | 7999 | { |
| pcercuei | 0:03b5121a232e | 8000 | xmlDOMWrapCtxtPtr ret; |
| pcercuei | 0:03b5121a232e | 8001 | |
| pcercuei | 0:03b5121a232e | 8002 | ret = xmlMalloc(sizeof(xmlDOMWrapCtxt)); |
| pcercuei | 0:03b5121a232e | 8003 | if (ret == NULL) { |
| pcercuei | 0:03b5121a232e | 8004 | xmlTreeErrMemory("allocating DOM-wrapper context"); |
| pcercuei | 0:03b5121a232e | 8005 | return (NULL); |
| pcercuei | 0:03b5121a232e | 8006 | } |
| pcercuei | 0:03b5121a232e | 8007 | memset(ret, 0, sizeof(xmlDOMWrapCtxt)); |
| pcercuei | 0:03b5121a232e | 8008 | return (ret); |
| pcercuei | 0:03b5121a232e | 8009 | } |
| pcercuei | 0:03b5121a232e | 8010 | |
| pcercuei | 0:03b5121a232e | 8011 | /* |
| pcercuei | 0:03b5121a232e | 8012 | * xmlDOMWrapFreeCtxt: |
| pcercuei | 0:03b5121a232e | 8013 | * @ctxt: the DOM-wrapper context |
| pcercuei | 0:03b5121a232e | 8014 | * |
| pcercuei | 0:03b5121a232e | 8015 | * Frees the DOM-wrapper context. |
| pcercuei | 0:03b5121a232e | 8016 | */ |
| pcercuei | 0:03b5121a232e | 8017 | void |
| pcercuei | 0:03b5121a232e | 8018 | xmlDOMWrapFreeCtxt(xmlDOMWrapCtxtPtr ctxt) |
| pcercuei | 0:03b5121a232e | 8019 | { |
| pcercuei | 0:03b5121a232e | 8020 | if (ctxt == NULL) |
| pcercuei | 0:03b5121a232e | 8021 | return; |
| pcercuei | 0:03b5121a232e | 8022 | if (ctxt->namespaceMap != NULL) |
| pcercuei | 0:03b5121a232e | 8023 | xmlDOMWrapNsMapFree((xmlNsMapPtr) ctxt->namespaceMap); |
| pcercuei | 0:03b5121a232e | 8024 | /* |
| pcercuei | 0:03b5121a232e | 8025 | * TODO: Store the namespace map in the context. |
| pcercuei | 0:03b5121a232e | 8026 | */ |
| pcercuei | 0:03b5121a232e | 8027 | xmlFree(ctxt); |
| pcercuei | 0:03b5121a232e | 8028 | } |
| pcercuei | 0:03b5121a232e | 8029 | |
| pcercuei | 0:03b5121a232e | 8030 | /* |
| pcercuei | 0:03b5121a232e | 8031 | * xmlTreeLookupNsListByPrefix: |
| pcercuei | 0:03b5121a232e | 8032 | * @nsList: a list of ns-structs |
| pcercuei | 0:03b5121a232e | 8033 | * @prefix: the searched prefix |
| pcercuei | 0:03b5121a232e | 8034 | * |
| pcercuei | 0:03b5121a232e | 8035 | * Searches for a ns-decl with the given prefix in @nsList. |
| pcercuei | 0:03b5121a232e | 8036 | * |
| pcercuei | 0:03b5121a232e | 8037 | * Returns the ns-decl if found, NULL if not found and on |
| pcercuei | 0:03b5121a232e | 8038 | * API errors. |
| pcercuei | 0:03b5121a232e | 8039 | */ |
| pcercuei | 0:03b5121a232e | 8040 | static xmlNsPtr |
| pcercuei | 0:03b5121a232e | 8041 | xmlTreeNSListLookupByPrefix(xmlNsPtr nsList, const xmlChar *prefix) |
| pcercuei | 0:03b5121a232e | 8042 | { |
| pcercuei | 0:03b5121a232e | 8043 | if (nsList == NULL) |
| pcercuei | 0:03b5121a232e | 8044 | return (NULL); |
| pcercuei | 0:03b5121a232e | 8045 | { |
| pcercuei | 0:03b5121a232e | 8046 | xmlNsPtr ns; |
| pcercuei | 0:03b5121a232e | 8047 | ns = nsList; |
| pcercuei | 0:03b5121a232e | 8048 | do { |
| pcercuei | 0:03b5121a232e | 8049 | if ((prefix == ns->prefix) || |
| pcercuei | 0:03b5121a232e | 8050 | xmlStrEqual(prefix, ns->prefix)) { |
| pcercuei | 0:03b5121a232e | 8051 | return (ns); |
| pcercuei | 0:03b5121a232e | 8052 | } |
| pcercuei | 0:03b5121a232e | 8053 | ns = ns->next; |
| pcercuei | 0:03b5121a232e | 8054 | } while (ns != NULL); |
| pcercuei | 0:03b5121a232e | 8055 | } |
| pcercuei | 0:03b5121a232e | 8056 | return (NULL); |
| pcercuei | 0:03b5121a232e | 8057 | } |
| pcercuei | 0:03b5121a232e | 8058 | |
| pcercuei | 0:03b5121a232e | 8059 | /* |
| pcercuei | 0:03b5121a232e | 8060 | * |
| pcercuei | 0:03b5121a232e | 8061 | * xmlDOMWrapNSNormGatherInScopeNs: |
| pcercuei | 0:03b5121a232e | 8062 | * @map: the namespace map |
| pcercuei | 0:03b5121a232e | 8063 | * @node: the node to start with |
| pcercuei | 0:03b5121a232e | 8064 | * |
| pcercuei | 0:03b5121a232e | 8065 | * Puts in-scope namespaces into the ns-map. |
| pcercuei | 0:03b5121a232e | 8066 | * |
| pcercuei | 0:03b5121a232e | 8067 | * Returns 0 on success, -1 on API or internal errors. |
| pcercuei | 0:03b5121a232e | 8068 | */ |
| pcercuei | 0:03b5121a232e | 8069 | static int |
| pcercuei | 0:03b5121a232e | 8070 | xmlDOMWrapNSNormGatherInScopeNs(xmlNsMapPtr *map, |
| pcercuei | 0:03b5121a232e | 8071 | xmlNodePtr node) |
| pcercuei | 0:03b5121a232e | 8072 | { |
| pcercuei | 0:03b5121a232e | 8073 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 8074 | xmlNsPtr ns; |
| pcercuei | 0:03b5121a232e | 8075 | xmlNsMapItemPtr mi; |
| pcercuei | 0:03b5121a232e | 8076 | int shadowed; |
| pcercuei | 0:03b5121a232e | 8077 | |
| pcercuei | 0:03b5121a232e | 8078 | if ((map == NULL) || (*map != NULL)) |
| pcercuei | 0:03b5121a232e | 8079 | return (-1); |
| pcercuei | 0:03b5121a232e | 8080 | if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) |
| pcercuei | 0:03b5121a232e | 8081 | return (-1); |
| pcercuei | 0:03b5121a232e | 8082 | /* |
| pcercuei | 0:03b5121a232e | 8083 | * Get in-scope ns-decls of @parent. |
| pcercuei | 0:03b5121a232e | 8084 | */ |
| pcercuei | 0:03b5121a232e | 8085 | cur = node; |
| pcercuei | 0:03b5121a232e | 8086 | while ((cur != NULL) && (cur != (xmlNodePtr) cur->doc)) { |
| pcercuei | 0:03b5121a232e | 8087 | if (cur->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 8088 | if (cur->nsDef != NULL) { |
| pcercuei | 0:03b5121a232e | 8089 | ns = cur->nsDef; |
| pcercuei | 0:03b5121a232e | 8090 | do { |
| pcercuei | 0:03b5121a232e | 8091 | shadowed = 0; |
| pcercuei | 0:03b5121a232e | 8092 | if (XML_NSMAP_NOTEMPTY(*map)) { |
| pcercuei | 0:03b5121a232e | 8093 | /* |
| pcercuei | 0:03b5121a232e | 8094 | * Skip shadowed prefixes. |
| pcercuei | 0:03b5121a232e | 8095 | */ |
| pcercuei | 0:03b5121a232e | 8096 | XML_NSMAP_FOREACH(*map, mi) { |
| pcercuei | 0:03b5121a232e | 8097 | if ((ns->prefix == mi->newNs->prefix) || |
| pcercuei | 0:03b5121a232e | 8098 | xmlStrEqual(ns->prefix, mi->newNs->prefix)) { |
| pcercuei | 0:03b5121a232e | 8099 | shadowed = 1; |
| pcercuei | 0:03b5121a232e | 8100 | break; |
| pcercuei | 0:03b5121a232e | 8101 | } |
| pcercuei | 0:03b5121a232e | 8102 | } |
| pcercuei | 0:03b5121a232e | 8103 | } |
| pcercuei | 0:03b5121a232e | 8104 | /* |
| pcercuei | 0:03b5121a232e | 8105 | * Insert mapping. |
| pcercuei | 0:03b5121a232e | 8106 | */ |
| pcercuei | 0:03b5121a232e | 8107 | mi = xmlDOMWrapNsMapAddItem(map, 0, NULL, |
| pcercuei | 0:03b5121a232e | 8108 | ns, XML_TREE_NSMAP_PARENT); |
| pcercuei | 0:03b5121a232e | 8109 | if (mi == NULL) |
| pcercuei | 0:03b5121a232e | 8110 | return (-1); |
| pcercuei | 0:03b5121a232e | 8111 | if (shadowed) |
| pcercuei | 0:03b5121a232e | 8112 | mi->shadowDepth = 0; |
| pcercuei | 0:03b5121a232e | 8113 | ns = ns->next; |
| pcercuei | 0:03b5121a232e | 8114 | } while (ns != NULL); |
| pcercuei | 0:03b5121a232e | 8115 | } |
| pcercuei | 0:03b5121a232e | 8116 | } |
| pcercuei | 0:03b5121a232e | 8117 | cur = cur->parent; |
| pcercuei | 0:03b5121a232e | 8118 | } |
| pcercuei | 0:03b5121a232e | 8119 | return (0); |
| pcercuei | 0:03b5121a232e | 8120 | } |
| pcercuei | 0:03b5121a232e | 8121 | |
| pcercuei | 0:03b5121a232e | 8122 | /* |
| pcercuei | 0:03b5121a232e | 8123 | * XML_TREE_ADOPT_STR: If we have a dest-dict, put @str in the dict; |
| pcercuei | 0:03b5121a232e | 8124 | * otherwise copy it, when it was in the source-dict. |
| pcercuei | 0:03b5121a232e | 8125 | */ |
| pcercuei | 0:03b5121a232e | 8126 | #define XML_TREE_ADOPT_STR(str) \ |
| pcercuei | 0:03b5121a232e | 8127 | if (adoptStr && (str != NULL)) { \ |
| pcercuei | 0:03b5121a232e | 8128 | if (destDoc->dict) { \ |
| pcercuei | 0:03b5121a232e | 8129 | const xmlChar *old = str; \ |
| pcercuei | 0:03b5121a232e | 8130 | str = xmlDictLookup(destDoc->dict, str, -1); \ |
| pcercuei | 0:03b5121a232e | 8131 | if ((sourceDoc == NULL) || (sourceDoc->dict == NULL) || \ |
| pcercuei | 0:03b5121a232e | 8132 | (!xmlDictOwns(sourceDoc->dict, old))) \ |
| pcercuei | 0:03b5121a232e | 8133 | xmlFree((char *)old); \ |
| pcercuei | 0:03b5121a232e | 8134 | } else if ((sourceDoc) && (sourceDoc->dict) && \ |
| pcercuei | 0:03b5121a232e | 8135 | xmlDictOwns(sourceDoc->dict, str)) { \ |
| pcercuei | 0:03b5121a232e | 8136 | str = BAD_CAST xmlStrdup(str); \ |
| pcercuei | 0:03b5121a232e | 8137 | } \ |
| pcercuei | 0:03b5121a232e | 8138 | } |
| pcercuei | 0:03b5121a232e | 8139 | |
| pcercuei | 0:03b5121a232e | 8140 | /* |
| pcercuei | 0:03b5121a232e | 8141 | * XML_TREE_ADOPT_STR_2: If @str was in the source-dict, then |
| pcercuei | 0:03b5121a232e | 8142 | * put it in dest-dict or copy it. |
| pcercuei | 0:03b5121a232e | 8143 | */ |
| pcercuei | 0:03b5121a232e | 8144 | #define XML_TREE_ADOPT_STR_2(str) \ |
| pcercuei | 0:03b5121a232e | 8145 | if (adoptStr && (str != NULL) && (sourceDoc != NULL) && \ |
| pcercuei | 0:03b5121a232e | 8146 | (sourceDoc->dict != NULL) && \ |
| pcercuei | 0:03b5121a232e | 8147 | xmlDictOwns(sourceDoc->dict, cur->content)) { \ |
| pcercuei | 0:03b5121a232e | 8148 | if (destDoc->dict) \ |
| pcercuei | 0:03b5121a232e | 8149 | cur->content = (xmlChar *) \ |
| pcercuei | 0:03b5121a232e | 8150 | xmlDictLookup(destDoc->dict, cur->content, -1); \ |
| pcercuei | 0:03b5121a232e | 8151 | else \ |
| pcercuei | 0:03b5121a232e | 8152 | cur->content = xmlStrdup(BAD_CAST cur->content); \ |
| pcercuei | 0:03b5121a232e | 8153 | } |
| pcercuei | 0:03b5121a232e | 8154 | |
| pcercuei | 0:03b5121a232e | 8155 | /* |
| pcercuei | 0:03b5121a232e | 8156 | * xmlDOMWrapNSNormAddNsMapItem2: |
| pcercuei | 0:03b5121a232e | 8157 | * |
| pcercuei | 0:03b5121a232e | 8158 | * For internal use. Adds a ns-decl mapping. |
| pcercuei | 0:03b5121a232e | 8159 | * |
| pcercuei | 0:03b5121a232e | 8160 | * Returns 0 on success, -1 on internal errors. |
| pcercuei | 0:03b5121a232e | 8161 | */ |
| pcercuei | 0:03b5121a232e | 8162 | static int |
| pcercuei | 0:03b5121a232e | 8163 | xmlDOMWrapNSNormAddNsMapItem2(xmlNsPtr **list, int *size, int *number, |
| pcercuei | 0:03b5121a232e | 8164 | xmlNsPtr oldNs, xmlNsPtr newNs) |
| pcercuei | 0:03b5121a232e | 8165 | { |
| pcercuei | 0:03b5121a232e | 8166 | if (*list == NULL) { |
| pcercuei | 0:03b5121a232e | 8167 | *list = (xmlNsPtr *) xmlMalloc(6 * sizeof(xmlNsPtr)); |
| pcercuei | 0:03b5121a232e | 8168 | if (*list == NULL) { |
| pcercuei | 0:03b5121a232e | 8169 | xmlTreeErrMemory("alloc ns map item"); |
| pcercuei | 0:03b5121a232e | 8170 | return(-1); |
| pcercuei | 0:03b5121a232e | 8171 | } |
| pcercuei | 0:03b5121a232e | 8172 | *size = 3; |
| pcercuei | 0:03b5121a232e | 8173 | *number = 0; |
| pcercuei | 0:03b5121a232e | 8174 | } else if ((*number) >= (*size)) { |
| pcercuei | 0:03b5121a232e | 8175 | *size *= 2; |
| pcercuei | 0:03b5121a232e | 8176 | *list = (xmlNsPtr *) xmlRealloc(*list, |
| pcercuei | 0:03b5121a232e | 8177 | (*size) * 2 * sizeof(xmlNsPtr)); |
| pcercuei | 0:03b5121a232e | 8178 | if (*list == NULL) { |
| pcercuei | 0:03b5121a232e | 8179 | xmlTreeErrMemory("realloc ns map item"); |
| pcercuei | 0:03b5121a232e | 8180 | return(-1); |
| pcercuei | 0:03b5121a232e | 8181 | } |
| pcercuei | 0:03b5121a232e | 8182 | } |
| pcercuei | 0:03b5121a232e | 8183 | (*list)[2 * (*number)] = oldNs; |
| pcercuei | 0:03b5121a232e | 8184 | (*list)[2 * (*number) +1] = newNs; |
| pcercuei | 0:03b5121a232e | 8185 | (*number)++; |
| pcercuei | 0:03b5121a232e | 8186 | return (0); |
| pcercuei | 0:03b5121a232e | 8187 | } |
| pcercuei | 0:03b5121a232e | 8188 | |
| pcercuei | 0:03b5121a232e | 8189 | /* |
| pcercuei | 0:03b5121a232e | 8190 | * xmlDOMWrapRemoveNode: |
| pcercuei | 0:03b5121a232e | 8191 | * @ctxt: a DOM wrapper context |
| pcercuei | 0:03b5121a232e | 8192 | * @doc: the doc |
| pcercuei | 0:03b5121a232e | 8193 | * @node: the node to be removed. |
| pcercuei | 0:03b5121a232e | 8194 | * @options: set of options, unused at the moment |
| pcercuei | 0:03b5121a232e | 8195 | * |
| pcercuei | 0:03b5121a232e | 8196 | * Unlinks the given node from its owner. |
| pcercuei | 0:03b5121a232e | 8197 | * This will substitute ns-references to node->nsDef for |
| pcercuei | 0:03b5121a232e | 8198 | * ns-references to doc->oldNs, thus ensuring the removed |
| pcercuei | 0:03b5121a232e | 8199 | * branch to be autark wrt ns-references. |
| pcercuei | 0:03b5121a232e | 8200 | * |
| pcercuei | 0:03b5121a232e | 8201 | * NOTE: This function was not intensively tested. |
| pcercuei | 0:03b5121a232e | 8202 | * |
| pcercuei | 0:03b5121a232e | 8203 | * Returns 0 on success, 1 if the node is not supported, |
| pcercuei | 0:03b5121a232e | 8204 | * -1 on API and internal errors. |
| pcercuei | 0:03b5121a232e | 8205 | */ |
| pcercuei | 0:03b5121a232e | 8206 | int |
| pcercuei | 0:03b5121a232e | 8207 | xmlDOMWrapRemoveNode(xmlDOMWrapCtxtPtr ctxt, xmlDocPtr doc, |
| pcercuei | 0:03b5121a232e | 8208 | xmlNodePtr node, int options ATTRIBUTE_UNUSED) |
| pcercuei | 0:03b5121a232e | 8209 | { |
| pcercuei | 0:03b5121a232e | 8210 | xmlNsPtr *list = NULL; |
| pcercuei | 0:03b5121a232e | 8211 | int sizeList, nbList, i, j; |
| pcercuei | 0:03b5121a232e | 8212 | xmlNsPtr ns; |
| pcercuei | 0:03b5121a232e | 8213 | |
| pcercuei | 0:03b5121a232e | 8214 | if ((node == NULL) || (doc == NULL) || (node->doc != doc)) |
| pcercuei | 0:03b5121a232e | 8215 | return (-1); |
| pcercuei | 0:03b5121a232e | 8216 | |
| pcercuei | 0:03b5121a232e | 8217 | /* TODO: 0 or -1 ? */ |
| pcercuei | 0:03b5121a232e | 8218 | if (node->parent == NULL) |
| pcercuei | 0:03b5121a232e | 8219 | return (0); |
| pcercuei | 0:03b5121a232e | 8220 | |
| pcercuei | 0:03b5121a232e | 8221 | switch (node->type) { |
| pcercuei | 0:03b5121a232e | 8222 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 8223 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 8224 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 8225 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 8226 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 8227 | xmlUnlinkNode(node); |
| pcercuei | 0:03b5121a232e | 8228 | return (0); |
| pcercuei | 0:03b5121a232e | 8229 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 8230 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 8231 | break; |
| pcercuei | 0:03b5121a232e | 8232 | default: |
| pcercuei | 0:03b5121a232e | 8233 | return (1); |
| pcercuei | 0:03b5121a232e | 8234 | } |
| pcercuei | 0:03b5121a232e | 8235 | xmlUnlinkNode(node); |
| pcercuei | 0:03b5121a232e | 8236 | /* |
| pcercuei | 0:03b5121a232e | 8237 | * Save out-of-scope ns-references in doc->oldNs. |
| pcercuei | 0:03b5121a232e | 8238 | */ |
| pcercuei | 0:03b5121a232e | 8239 | do { |
| pcercuei | 0:03b5121a232e | 8240 | switch (node->type) { |
| pcercuei | 0:03b5121a232e | 8241 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 8242 | if ((ctxt == NULL) && (node->nsDef != NULL)) { |
| pcercuei | 0:03b5121a232e | 8243 | ns = node->nsDef; |
| pcercuei | 0:03b5121a232e | 8244 | do { |
| pcercuei | 0:03b5121a232e | 8245 | if (xmlDOMWrapNSNormAddNsMapItem2(&list, &sizeList, |
| pcercuei | 0:03b5121a232e | 8246 | &nbList, ns, ns) == -1) |
| pcercuei | 0:03b5121a232e | 8247 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 8248 | ns = ns->next; |
| pcercuei | 0:03b5121a232e | 8249 | } while (ns != NULL); |
| pcercuei | 0:03b5121a232e | 8250 | } |
| pcercuei | 0:03b5121a232e | 8251 | /* No break on purpose. */ |
| pcercuei | 0:03b5121a232e | 8252 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 8253 | if (node->ns != NULL) { |
| pcercuei | 0:03b5121a232e | 8254 | /* |
| pcercuei | 0:03b5121a232e | 8255 | * Find a mapping. |
| pcercuei | 0:03b5121a232e | 8256 | */ |
| pcercuei | 0:03b5121a232e | 8257 | if (list != NULL) { |
| pcercuei | 0:03b5121a232e | 8258 | for (i = 0, j = 0; i < nbList; i++, j += 2) { |
| pcercuei | 0:03b5121a232e | 8259 | if (node->ns == list[j]) { |
| pcercuei | 0:03b5121a232e | 8260 | node->ns = list[++j]; |
| pcercuei | 0:03b5121a232e | 8261 | goto next_node; |
| pcercuei | 0:03b5121a232e | 8262 | } |
| pcercuei | 0:03b5121a232e | 8263 | } |
| pcercuei | 0:03b5121a232e | 8264 | } |
| pcercuei | 0:03b5121a232e | 8265 | ns = NULL; |
| pcercuei | 0:03b5121a232e | 8266 | if (ctxt != NULL) { |
| pcercuei | 0:03b5121a232e | 8267 | /* |
| pcercuei | 0:03b5121a232e | 8268 | * User defined. |
| pcercuei | 0:03b5121a232e | 8269 | */ |
| pcercuei | 0:03b5121a232e | 8270 | } else { |
| pcercuei | 0:03b5121a232e | 8271 | /* |
| pcercuei | 0:03b5121a232e | 8272 | * Add to doc's oldNs. |
| pcercuei | 0:03b5121a232e | 8273 | */ |
| pcercuei | 0:03b5121a232e | 8274 | ns = xmlDOMWrapStoreNs(doc, node->ns->href, |
| pcercuei | 0:03b5121a232e | 8275 | node->ns->prefix); |
| pcercuei | 0:03b5121a232e | 8276 | if (ns == NULL) |
| pcercuei | 0:03b5121a232e | 8277 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 8278 | } |
| pcercuei | 0:03b5121a232e | 8279 | if (ns != NULL) { |
| pcercuei | 0:03b5121a232e | 8280 | /* |
| pcercuei | 0:03b5121a232e | 8281 | * Add mapping. |
| pcercuei | 0:03b5121a232e | 8282 | */ |
| pcercuei | 0:03b5121a232e | 8283 | if (xmlDOMWrapNSNormAddNsMapItem2(&list, &sizeList, |
| pcercuei | 0:03b5121a232e | 8284 | &nbList, node->ns, ns) == -1) |
| pcercuei | 0:03b5121a232e | 8285 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 8286 | } |
| pcercuei | 0:03b5121a232e | 8287 | node->ns = ns; |
| pcercuei | 0:03b5121a232e | 8288 | } |
| pcercuei | 0:03b5121a232e | 8289 | if ((node->type == XML_ELEMENT_NODE) && |
| pcercuei | 0:03b5121a232e | 8290 | (node->properties != NULL)) { |
| pcercuei | 0:03b5121a232e | 8291 | node = (xmlNodePtr) node->properties; |
| pcercuei | 0:03b5121a232e | 8292 | continue; |
| pcercuei | 0:03b5121a232e | 8293 | } |
| pcercuei | 0:03b5121a232e | 8294 | break; |
| pcercuei | 0:03b5121a232e | 8295 | default: |
| pcercuei | 0:03b5121a232e | 8296 | goto next_sibling; |
| pcercuei | 0:03b5121a232e | 8297 | } |
| pcercuei | 0:03b5121a232e | 8298 | next_node: |
| pcercuei | 0:03b5121a232e | 8299 | if ((node->type == XML_ELEMENT_NODE) && |
| pcercuei | 0:03b5121a232e | 8300 | (node->children != NULL)) { |
| pcercuei | 0:03b5121a232e | 8301 | node = node->children; |
| pcercuei | 0:03b5121a232e | 8302 | continue; |
| pcercuei | 0:03b5121a232e | 8303 | } |
| pcercuei | 0:03b5121a232e | 8304 | next_sibling: |
| pcercuei | 0:03b5121a232e | 8305 | if (node == NULL) |
| pcercuei | 0:03b5121a232e | 8306 | break; |
| pcercuei | 0:03b5121a232e | 8307 | if (node->next != NULL) |
| pcercuei | 0:03b5121a232e | 8308 | node = node->next; |
| pcercuei | 0:03b5121a232e | 8309 | else { |
| pcercuei | 0:03b5121a232e | 8310 | node = node->parent; |
| pcercuei | 0:03b5121a232e | 8311 | goto next_sibling; |
| pcercuei | 0:03b5121a232e | 8312 | } |
| pcercuei | 0:03b5121a232e | 8313 | } while (node != NULL); |
| pcercuei | 0:03b5121a232e | 8314 | |
| pcercuei | 0:03b5121a232e | 8315 | if (list != NULL) |
| pcercuei | 0:03b5121a232e | 8316 | xmlFree(list); |
| pcercuei | 0:03b5121a232e | 8317 | return (0); |
| pcercuei | 0:03b5121a232e | 8318 | |
| pcercuei | 0:03b5121a232e | 8319 | internal_error: |
| pcercuei | 0:03b5121a232e | 8320 | if (list != NULL) |
| pcercuei | 0:03b5121a232e | 8321 | xmlFree(list); |
| pcercuei | 0:03b5121a232e | 8322 | return (-1); |
| pcercuei | 0:03b5121a232e | 8323 | } |
| pcercuei | 0:03b5121a232e | 8324 | |
| pcercuei | 0:03b5121a232e | 8325 | /* |
| pcercuei | 0:03b5121a232e | 8326 | * xmlSearchNsByNamespaceStrict: |
| pcercuei | 0:03b5121a232e | 8327 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 8328 | * @node: the start node |
| pcercuei | 0:03b5121a232e | 8329 | * @nsName: the searched namespace name |
| pcercuei | 0:03b5121a232e | 8330 | * @retNs: the resulting ns-decl |
| pcercuei | 0:03b5121a232e | 8331 | * @prefixed: if the found ns-decl must have a prefix (for attributes) |
| pcercuei | 0:03b5121a232e | 8332 | * |
| pcercuei | 0:03b5121a232e | 8333 | * Dynamically searches for a ns-declaration which matches |
| pcercuei | 0:03b5121a232e | 8334 | * the given @nsName in the ancestor-or-self axis of @node. |
| pcercuei | 0:03b5121a232e | 8335 | * |
| pcercuei | 0:03b5121a232e | 8336 | * Returns 1 if a ns-decl was found, 0 if not and -1 on API |
| pcercuei | 0:03b5121a232e | 8337 | * and internal errors. |
| pcercuei | 0:03b5121a232e | 8338 | */ |
| pcercuei | 0:03b5121a232e | 8339 | static int |
| pcercuei | 0:03b5121a232e | 8340 | xmlSearchNsByNamespaceStrict(xmlDocPtr doc, xmlNodePtr node, |
| pcercuei | 0:03b5121a232e | 8341 | const xmlChar* nsName, |
| pcercuei | 0:03b5121a232e | 8342 | xmlNsPtr *retNs, int prefixed) |
| pcercuei | 0:03b5121a232e | 8343 | { |
| pcercuei | 0:03b5121a232e | 8344 | xmlNodePtr cur, prev = NULL, out = NULL; |
| pcercuei | 0:03b5121a232e | 8345 | xmlNsPtr ns, prevns; |
| pcercuei | 0:03b5121a232e | 8346 | |
| pcercuei | 0:03b5121a232e | 8347 | if ((doc == NULL) || (nsName == NULL) || (retNs == NULL)) |
| pcercuei | 0:03b5121a232e | 8348 | return (-1); |
| pcercuei | 0:03b5121a232e | 8349 | if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) |
| pcercuei | 0:03b5121a232e | 8350 | return(-1); |
| pcercuei | 0:03b5121a232e | 8351 | |
| pcercuei | 0:03b5121a232e | 8352 | *retNs = NULL; |
| pcercuei | 0:03b5121a232e | 8353 | if (xmlStrEqual(nsName, XML_XML_NAMESPACE)) { |
| pcercuei | 0:03b5121a232e | 8354 | *retNs = xmlTreeEnsureXMLDecl(doc); |
| pcercuei | 0:03b5121a232e | 8355 | if (*retNs == NULL) |
| pcercuei | 0:03b5121a232e | 8356 | return (-1); |
| pcercuei | 0:03b5121a232e | 8357 | return (1); |
| pcercuei | 0:03b5121a232e | 8358 | } |
| pcercuei | 0:03b5121a232e | 8359 | cur = node; |
| pcercuei | 0:03b5121a232e | 8360 | do { |
| pcercuei | 0:03b5121a232e | 8361 | if (cur->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 8362 | if (cur->nsDef != NULL) { |
| pcercuei | 0:03b5121a232e | 8363 | for (ns = cur->nsDef; ns != NULL; ns = ns->next) { |
| pcercuei | 0:03b5121a232e | 8364 | if (prefixed && (ns->prefix == NULL)) |
| pcercuei | 0:03b5121a232e | 8365 | continue; |
| pcercuei | 0:03b5121a232e | 8366 | if (prev != NULL) { |
| pcercuei | 0:03b5121a232e | 8367 | /* |
| pcercuei | 0:03b5121a232e | 8368 | * Check the last level of ns-decls for a |
| pcercuei | 0:03b5121a232e | 8369 | * shadowing prefix. |
| pcercuei | 0:03b5121a232e | 8370 | */ |
| pcercuei | 0:03b5121a232e | 8371 | prevns = prev->nsDef; |
| pcercuei | 0:03b5121a232e | 8372 | do { |
| pcercuei | 0:03b5121a232e | 8373 | if ((prevns->prefix == ns->prefix) || |
| pcercuei | 0:03b5121a232e | 8374 | ((prevns->prefix != NULL) && |
| pcercuei | 0:03b5121a232e | 8375 | (ns->prefix != NULL) && |
| pcercuei | 0:03b5121a232e | 8376 | xmlStrEqual(prevns->prefix, ns->prefix))) { |
| pcercuei | 0:03b5121a232e | 8377 | /* |
| pcercuei | 0:03b5121a232e | 8378 | * Shadowed. |
| pcercuei | 0:03b5121a232e | 8379 | */ |
| pcercuei | 0:03b5121a232e | 8380 | break; |
| pcercuei | 0:03b5121a232e | 8381 | } |
| pcercuei | 0:03b5121a232e | 8382 | prevns = prevns->next; |
| pcercuei | 0:03b5121a232e | 8383 | } while (prevns != NULL); |
| pcercuei | 0:03b5121a232e | 8384 | if (prevns != NULL) |
| pcercuei | 0:03b5121a232e | 8385 | continue; |
| pcercuei | 0:03b5121a232e | 8386 | } |
| pcercuei | 0:03b5121a232e | 8387 | /* |
| pcercuei | 0:03b5121a232e | 8388 | * Ns-name comparison. |
| pcercuei | 0:03b5121a232e | 8389 | */ |
| pcercuei | 0:03b5121a232e | 8390 | if ((nsName == ns->href) || |
| pcercuei | 0:03b5121a232e | 8391 | xmlStrEqual(nsName, ns->href)) { |
| pcercuei | 0:03b5121a232e | 8392 | /* |
| pcercuei | 0:03b5121a232e | 8393 | * At this point the prefix can only be shadowed, |
| pcercuei | 0:03b5121a232e | 8394 | * if we are the the (at least) 3rd level of |
| pcercuei | 0:03b5121a232e | 8395 | * ns-decls. |
| pcercuei | 0:03b5121a232e | 8396 | */ |
| pcercuei | 0:03b5121a232e | 8397 | if (out) { |
| pcercuei | 0:03b5121a232e | 8398 | int ret; |
| pcercuei | 0:03b5121a232e | 8399 | |
| pcercuei | 0:03b5121a232e | 8400 | ret = xmlNsInScope(doc, node, prev, ns->prefix); |
| pcercuei | 0:03b5121a232e | 8401 | if (ret < 0) |
| pcercuei | 0:03b5121a232e | 8402 | return (-1); |
| pcercuei | 0:03b5121a232e | 8403 | /* |
| pcercuei | 0:03b5121a232e | 8404 | * TODO: Should we try to find a matching ns-name |
| pcercuei | 0:03b5121a232e | 8405 | * only once? This here keeps on searching. |
| pcercuei | 0:03b5121a232e | 8406 | * I think we should try further since, there might |
| pcercuei | 0:03b5121a232e | 8407 | * be an other matching ns-decl with an unshadowed |
| pcercuei | 0:03b5121a232e | 8408 | * prefix. |
| pcercuei | 0:03b5121a232e | 8409 | */ |
| pcercuei | 0:03b5121a232e | 8410 | if (! ret) |
| pcercuei | 0:03b5121a232e | 8411 | continue; |
| pcercuei | 0:03b5121a232e | 8412 | } |
| pcercuei | 0:03b5121a232e | 8413 | *retNs = ns; |
| pcercuei | 0:03b5121a232e | 8414 | return (1); |
| pcercuei | 0:03b5121a232e | 8415 | } |
| pcercuei | 0:03b5121a232e | 8416 | } |
| pcercuei | 0:03b5121a232e | 8417 | out = prev; |
| pcercuei | 0:03b5121a232e | 8418 | prev = cur; |
| pcercuei | 0:03b5121a232e | 8419 | } |
| pcercuei | 0:03b5121a232e | 8420 | } else if ((cur->type == XML_ENTITY_NODE) || |
| pcercuei | 0:03b5121a232e | 8421 | (cur->type == XML_ENTITY_DECL)) |
| pcercuei | 0:03b5121a232e | 8422 | return (0); |
| pcercuei | 0:03b5121a232e | 8423 | cur = cur->parent; |
| pcercuei | 0:03b5121a232e | 8424 | } while ((cur != NULL) && (cur->doc != (xmlDocPtr) cur)); |
| pcercuei | 0:03b5121a232e | 8425 | return (0); |
| pcercuei | 0:03b5121a232e | 8426 | } |
| pcercuei | 0:03b5121a232e | 8427 | |
| pcercuei | 0:03b5121a232e | 8428 | /* |
| pcercuei | 0:03b5121a232e | 8429 | * xmlSearchNsByPrefixStrict: |
| pcercuei | 0:03b5121a232e | 8430 | * @doc: the document |
| pcercuei | 0:03b5121a232e | 8431 | * @node: the start node |
| pcercuei | 0:03b5121a232e | 8432 | * @prefix: the searched namespace prefix |
| pcercuei | 0:03b5121a232e | 8433 | * @retNs: the resulting ns-decl |
| pcercuei | 0:03b5121a232e | 8434 | * |
| pcercuei | 0:03b5121a232e | 8435 | * Dynamically searches for a ns-declaration which matches |
| pcercuei | 0:03b5121a232e | 8436 | * the given @nsName in the ancestor-or-self axis of @node. |
| pcercuei | 0:03b5121a232e | 8437 | * |
| pcercuei | 0:03b5121a232e | 8438 | * Returns 1 if a ns-decl was found, 0 if not and -1 on API |
| pcercuei | 0:03b5121a232e | 8439 | * and internal errors. |
| pcercuei | 0:03b5121a232e | 8440 | */ |
| pcercuei | 0:03b5121a232e | 8441 | static int |
| pcercuei | 0:03b5121a232e | 8442 | xmlSearchNsByPrefixStrict(xmlDocPtr doc, xmlNodePtr node, |
| pcercuei | 0:03b5121a232e | 8443 | const xmlChar* prefix, |
| pcercuei | 0:03b5121a232e | 8444 | xmlNsPtr *retNs) |
| pcercuei | 0:03b5121a232e | 8445 | { |
| pcercuei | 0:03b5121a232e | 8446 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 8447 | xmlNsPtr ns; |
| pcercuei | 0:03b5121a232e | 8448 | |
| pcercuei | 0:03b5121a232e | 8449 | if ((doc == NULL) || (node == NULL) || (node->type == XML_NAMESPACE_DECL)) |
| pcercuei | 0:03b5121a232e | 8450 | return(-1); |
| pcercuei | 0:03b5121a232e | 8451 | |
| pcercuei | 0:03b5121a232e | 8452 | if (retNs) |
| pcercuei | 0:03b5121a232e | 8453 | *retNs = NULL; |
| pcercuei | 0:03b5121a232e | 8454 | if (IS_STR_XML(prefix)) { |
| pcercuei | 0:03b5121a232e | 8455 | if (retNs) { |
| pcercuei | 0:03b5121a232e | 8456 | *retNs = xmlTreeEnsureXMLDecl(doc); |
| pcercuei | 0:03b5121a232e | 8457 | if (*retNs == NULL) |
| pcercuei | 0:03b5121a232e | 8458 | return (-1); |
| pcercuei | 0:03b5121a232e | 8459 | } |
| pcercuei | 0:03b5121a232e | 8460 | return (1); |
| pcercuei | 0:03b5121a232e | 8461 | } |
| pcercuei | 0:03b5121a232e | 8462 | cur = node; |
| pcercuei | 0:03b5121a232e | 8463 | do { |
| pcercuei | 0:03b5121a232e | 8464 | if (cur->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 8465 | if (cur->nsDef != NULL) { |
| pcercuei | 0:03b5121a232e | 8466 | ns = cur->nsDef; |
| pcercuei | 0:03b5121a232e | 8467 | do { |
| pcercuei | 0:03b5121a232e | 8468 | if ((prefix == ns->prefix) || |
| pcercuei | 0:03b5121a232e | 8469 | xmlStrEqual(prefix, ns->prefix)) |
| pcercuei | 0:03b5121a232e | 8470 | { |
| pcercuei | 0:03b5121a232e | 8471 | /* |
| pcercuei | 0:03b5121a232e | 8472 | * Disabled namespaces, e.g. xmlns:abc="". |
| pcercuei | 0:03b5121a232e | 8473 | */ |
| pcercuei | 0:03b5121a232e | 8474 | if (ns->href == NULL) |
| pcercuei | 0:03b5121a232e | 8475 | return(0); |
| pcercuei | 0:03b5121a232e | 8476 | if (retNs) |
| pcercuei | 0:03b5121a232e | 8477 | *retNs = ns; |
| pcercuei | 0:03b5121a232e | 8478 | return (1); |
| pcercuei | 0:03b5121a232e | 8479 | } |
| pcercuei | 0:03b5121a232e | 8480 | ns = ns->next; |
| pcercuei | 0:03b5121a232e | 8481 | } while (ns != NULL); |
| pcercuei | 0:03b5121a232e | 8482 | } |
| pcercuei | 0:03b5121a232e | 8483 | } else if ((cur->type == XML_ENTITY_NODE) || |
| pcercuei | 0:03b5121a232e | 8484 | (cur->type == XML_ENTITY_DECL)) |
| pcercuei | 0:03b5121a232e | 8485 | return (0); |
| pcercuei | 0:03b5121a232e | 8486 | cur = cur->parent; |
| pcercuei | 0:03b5121a232e | 8487 | } while ((cur != NULL) && (cur->doc != (xmlDocPtr) cur)); |
| pcercuei | 0:03b5121a232e | 8488 | return (0); |
| pcercuei | 0:03b5121a232e | 8489 | } |
| pcercuei | 0:03b5121a232e | 8490 | |
| pcercuei | 0:03b5121a232e | 8491 | /* |
| pcercuei | 0:03b5121a232e | 8492 | * xmlDOMWrapNSNormDeclareNsForced: |
| pcercuei | 0:03b5121a232e | 8493 | * @doc: the doc |
| pcercuei | 0:03b5121a232e | 8494 | * @elem: the element-node to declare on |
| pcercuei | 0:03b5121a232e | 8495 | * @nsName: the namespace-name of the ns-decl |
| pcercuei | 0:03b5121a232e | 8496 | * @prefix: the preferred prefix of the ns-decl |
| pcercuei | 0:03b5121a232e | 8497 | * @checkShadow: ensure that the new ns-decl doesn't shadow ancestor ns-decls |
| pcercuei | 0:03b5121a232e | 8498 | * |
| pcercuei | 0:03b5121a232e | 8499 | * Declares a new namespace on @elem. It tries to use the |
| pcercuei | 0:03b5121a232e | 8500 | * given @prefix; if a ns-decl with the given prefix is already existent |
| pcercuei | 0:03b5121a232e | 8501 | * on @elem, it will generate an other prefix. |
| pcercuei | 0:03b5121a232e | 8502 | * |
| pcercuei | 0:03b5121a232e | 8503 | * Returns 1 if a ns-decl was found, 0 if not and -1 on API |
| pcercuei | 0:03b5121a232e | 8504 | * and internal errors. |
| pcercuei | 0:03b5121a232e | 8505 | */ |
| pcercuei | 0:03b5121a232e | 8506 | static xmlNsPtr |
| pcercuei | 0:03b5121a232e | 8507 | xmlDOMWrapNSNormDeclareNsForced(xmlDocPtr doc, |
| pcercuei | 0:03b5121a232e | 8508 | xmlNodePtr elem, |
| pcercuei | 0:03b5121a232e | 8509 | const xmlChar *nsName, |
| pcercuei | 0:03b5121a232e | 8510 | const xmlChar *prefix, |
| pcercuei | 0:03b5121a232e | 8511 | int checkShadow) |
| pcercuei | 0:03b5121a232e | 8512 | { |
| pcercuei | 0:03b5121a232e | 8513 | |
| pcercuei | 0:03b5121a232e | 8514 | xmlNsPtr ret; |
| pcercuei | 0:03b5121a232e | 8515 | char buf[50]; |
| pcercuei | 0:03b5121a232e | 8516 | const xmlChar *pref; |
| pcercuei | 0:03b5121a232e | 8517 | int counter = 0; |
| pcercuei | 0:03b5121a232e | 8518 | |
| pcercuei | 0:03b5121a232e | 8519 | if ((doc == NULL) || (elem == NULL) || (elem->type != XML_ELEMENT_NODE)) |
| pcercuei | 0:03b5121a232e | 8520 | return(NULL); |
| pcercuei | 0:03b5121a232e | 8521 | /* |
| pcercuei | 0:03b5121a232e | 8522 | * Create a ns-decl on @anchor. |
| pcercuei | 0:03b5121a232e | 8523 | */ |
| pcercuei | 0:03b5121a232e | 8524 | pref = prefix; |
| pcercuei | 0:03b5121a232e | 8525 | while (1) { |
| pcercuei | 0:03b5121a232e | 8526 | /* |
| pcercuei | 0:03b5121a232e | 8527 | * Lookup whether the prefix is unused in elem's ns-decls. |
| pcercuei | 0:03b5121a232e | 8528 | */ |
| pcercuei | 0:03b5121a232e | 8529 | if ((elem->nsDef != NULL) && |
| pcercuei | 0:03b5121a232e | 8530 | (xmlTreeNSListLookupByPrefix(elem->nsDef, pref) != NULL)) |
| pcercuei | 0:03b5121a232e | 8531 | goto ns_next_prefix; |
| pcercuei | 0:03b5121a232e | 8532 | if (checkShadow && elem->parent && |
| pcercuei | 0:03b5121a232e | 8533 | ((xmlNodePtr) elem->parent->doc != elem->parent)) { |
| pcercuei | 0:03b5121a232e | 8534 | /* |
| pcercuei | 0:03b5121a232e | 8535 | * Does it shadow ancestor ns-decls? |
| pcercuei | 0:03b5121a232e | 8536 | */ |
| pcercuei | 0:03b5121a232e | 8537 | if (xmlSearchNsByPrefixStrict(doc, elem->parent, pref, NULL) == 1) |
| pcercuei | 0:03b5121a232e | 8538 | goto ns_next_prefix; |
| pcercuei | 0:03b5121a232e | 8539 | } |
| pcercuei | 0:03b5121a232e | 8540 | ret = xmlNewNs(NULL, nsName, pref); |
| pcercuei | 0:03b5121a232e | 8541 | if (ret == NULL) |
| pcercuei | 0:03b5121a232e | 8542 | return (NULL); |
| pcercuei | 0:03b5121a232e | 8543 | if (elem->nsDef == NULL) |
| pcercuei | 0:03b5121a232e | 8544 | elem->nsDef = ret; |
| pcercuei | 0:03b5121a232e | 8545 | else { |
| pcercuei | 0:03b5121a232e | 8546 | xmlNsPtr ns2 = elem->nsDef; |
| pcercuei | 0:03b5121a232e | 8547 | while (ns2->next != NULL) |
| pcercuei | 0:03b5121a232e | 8548 | ns2 = ns2->next; |
| pcercuei | 0:03b5121a232e | 8549 | ns2->next = ret; |
| pcercuei | 0:03b5121a232e | 8550 | } |
| pcercuei | 0:03b5121a232e | 8551 | return (ret); |
| pcercuei | 0:03b5121a232e | 8552 | ns_next_prefix: |
| pcercuei | 0:03b5121a232e | 8553 | counter++; |
| pcercuei | 0:03b5121a232e | 8554 | if (counter > 1000) |
| pcercuei | 0:03b5121a232e | 8555 | return (NULL); |
| pcercuei | 0:03b5121a232e | 8556 | if (prefix == NULL) { |
| pcercuei | 0:03b5121a232e | 8557 | snprintf((char *) buf, sizeof(buf), |
| pcercuei | 0:03b5121a232e | 8558 | "ns_%d", counter); |
| pcercuei | 0:03b5121a232e | 8559 | } else |
| pcercuei | 0:03b5121a232e | 8560 | snprintf((char *) buf, sizeof(buf), |
| pcercuei | 0:03b5121a232e | 8561 | "%.30s_%d", (char *)prefix, counter); |
| pcercuei | 0:03b5121a232e | 8562 | pref = BAD_CAST buf; |
| pcercuei | 0:03b5121a232e | 8563 | } |
| pcercuei | 0:03b5121a232e | 8564 | } |
| pcercuei | 0:03b5121a232e | 8565 | |
| pcercuei | 0:03b5121a232e | 8566 | /* |
| pcercuei | 0:03b5121a232e | 8567 | * xmlDOMWrapNSNormAquireNormalizedNs: |
| pcercuei | 0:03b5121a232e | 8568 | * @doc: the doc |
| pcercuei | 0:03b5121a232e | 8569 | * @elem: the element-node to declare namespaces on |
| pcercuei | 0:03b5121a232e | 8570 | * @ns: the ns-struct to use for the search |
| pcercuei | 0:03b5121a232e | 8571 | * @retNs: the found/created ns-struct |
| pcercuei | 0:03b5121a232e | 8572 | * @nsMap: the ns-map |
| pcercuei | 0:03b5121a232e | 8573 | * @depth: the current tree depth |
| pcercuei | 0:03b5121a232e | 8574 | * @ancestorsOnly: search in ancestor ns-decls only |
| pcercuei | 0:03b5121a232e | 8575 | * @prefixed: if the searched ns-decl must have a prefix (for attributes) |
| pcercuei | 0:03b5121a232e | 8576 | * |
| pcercuei | 0:03b5121a232e | 8577 | * Searches for a matching ns-name in the ns-decls of @nsMap, if not |
| pcercuei | 0:03b5121a232e | 8578 | * found it will either declare it on @elem, or store it in doc->oldNs. |
| pcercuei | 0:03b5121a232e | 8579 | * If a new ns-decl needs to be declared on @elem, it tries to use the |
| pcercuei | 0:03b5121a232e | 8580 | * @ns->prefix for it, if this prefix is already in use on @elem, it will |
| pcercuei | 0:03b5121a232e | 8581 | * change the prefix or the new ns-decl. |
| pcercuei | 0:03b5121a232e | 8582 | * |
| pcercuei | 0:03b5121a232e | 8583 | * Returns 0 if succeeded, -1 otherwise and on API/internal errors. |
| pcercuei | 0:03b5121a232e | 8584 | */ |
| pcercuei | 0:03b5121a232e | 8585 | static int |
| pcercuei | 0:03b5121a232e | 8586 | xmlDOMWrapNSNormAquireNormalizedNs(xmlDocPtr doc, |
| pcercuei | 0:03b5121a232e | 8587 | xmlNodePtr elem, |
| pcercuei | 0:03b5121a232e | 8588 | xmlNsPtr ns, |
| pcercuei | 0:03b5121a232e | 8589 | xmlNsPtr *retNs, |
| pcercuei | 0:03b5121a232e | 8590 | xmlNsMapPtr *nsMap, |
| pcercuei | 0:03b5121a232e | 8591 | |
| pcercuei | 0:03b5121a232e | 8592 | int depth, |
| pcercuei | 0:03b5121a232e | 8593 | int ancestorsOnly, |
| pcercuei | 0:03b5121a232e | 8594 | int prefixed) |
| pcercuei | 0:03b5121a232e | 8595 | { |
| pcercuei | 0:03b5121a232e | 8596 | xmlNsMapItemPtr mi; |
| pcercuei | 0:03b5121a232e | 8597 | |
| pcercuei | 0:03b5121a232e | 8598 | if ((doc == NULL) || (ns == NULL) || (retNs == NULL) || |
| pcercuei | 0:03b5121a232e | 8599 | (nsMap == NULL)) |
| pcercuei | 0:03b5121a232e | 8600 | return (-1); |
| pcercuei | 0:03b5121a232e | 8601 | |
| pcercuei | 0:03b5121a232e | 8602 | *retNs = NULL; |
| pcercuei | 0:03b5121a232e | 8603 | /* |
| pcercuei | 0:03b5121a232e | 8604 | * Handle XML namespace. |
| pcercuei | 0:03b5121a232e | 8605 | */ |
| pcercuei | 0:03b5121a232e | 8606 | if (IS_STR_XML(ns->prefix)) { |
| pcercuei | 0:03b5121a232e | 8607 | /* |
| pcercuei | 0:03b5121a232e | 8608 | * Insert XML namespace mapping. |
| pcercuei | 0:03b5121a232e | 8609 | */ |
| pcercuei | 0:03b5121a232e | 8610 | *retNs = xmlTreeEnsureXMLDecl(doc); |
| pcercuei | 0:03b5121a232e | 8611 | if (*retNs == NULL) |
| pcercuei | 0:03b5121a232e | 8612 | return (-1); |
| pcercuei | 0:03b5121a232e | 8613 | return (0); |
| pcercuei | 0:03b5121a232e | 8614 | } |
| pcercuei | 0:03b5121a232e | 8615 | /* |
| pcercuei | 0:03b5121a232e | 8616 | * If the search should be done in ancestors only and no |
| pcercuei | 0:03b5121a232e | 8617 | * @elem (the first ancestor) was specified, then skip the search. |
| pcercuei | 0:03b5121a232e | 8618 | */ |
| pcercuei | 0:03b5121a232e | 8619 | if ((XML_NSMAP_NOTEMPTY(*nsMap)) && |
| pcercuei | 0:03b5121a232e | 8620 | (! (ancestorsOnly && (elem == NULL)))) |
| pcercuei | 0:03b5121a232e | 8621 | { |
| pcercuei | 0:03b5121a232e | 8622 | /* |
| pcercuei | 0:03b5121a232e | 8623 | * Try to find an equal ns-name in in-scope ns-decls. |
| pcercuei | 0:03b5121a232e | 8624 | */ |
| pcercuei | 0:03b5121a232e | 8625 | XML_NSMAP_FOREACH(*nsMap, mi) { |
| pcercuei | 0:03b5121a232e | 8626 | if ((mi->depth >= XML_TREE_NSMAP_PARENT) && |
| pcercuei | 0:03b5121a232e | 8627 | /* |
| pcercuei | 0:03b5121a232e | 8628 | * ancestorsOnly: This should be turned on to gain speed, |
| pcercuei | 0:03b5121a232e | 8629 | * if one knows that the branch itself was already |
| pcercuei | 0:03b5121a232e | 8630 | * ns-wellformed and no stale references existed. |
| pcercuei | 0:03b5121a232e | 8631 | * I.e. it searches in the ancestor axis only. |
| pcercuei | 0:03b5121a232e | 8632 | */ |
| pcercuei | 0:03b5121a232e | 8633 | ((! ancestorsOnly) || (mi->depth == XML_TREE_NSMAP_PARENT)) && |
| pcercuei | 0:03b5121a232e | 8634 | /* Skip shadowed prefixes. */ |
| pcercuei | 0:03b5121a232e | 8635 | (mi->shadowDepth == -1) && |
| pcercuei | 0:03b5121a232e | 8636 | /* Skip xmlns="" or xmlns:foo="". */ |
| pcercuei | 0:03b5121a232e | 8637 | ((mi->newNs->href != NULL) && |
| pcercuei | 0:03b5121a232e | 8638 | (mi->newNs->href[0] != 0)) && |
| pcercuei | 0:03b5121a232e | 8639 | /* Ensure a prefix if wanted. */ |
| pcercuei | 0:03b5121a232e | 8640 | ((! prefixed) || (mi->newNs->prefix != NULL)) && |
| pcercuei | 0:03b5121a232e | 8641 | /* Equal ns name */ |
| pcercuei | 0:03b5121a232e | 8642 | ((mi->newNs->href == ns->href) || |
| pcercuei | 0:03b5121a232e | 8643 | xmlStrEqual(mi->newNs->href, ns->href))) { |
| pcercuei | 0:03b5121a232e | 8644 | /* Set the mapping. */ |
| pcercuei | 0:03b5121a232e | 8645 | mi->oldNs = ns; |
| pcercuei | 0:03b5121a232e | 8646 | *retNs = mi->newNs; |
| pcercuei | 0:03b5121a232e | 8647 | return (0); |
| pcercuei | 0:03b5121a232e | 8648 | } |
| pcercuei | 0:03b5121a232e | 8649 | } |
| pcercuei | 0:03b5121a232e | 8650 | } |
| pcercuei | 0:03b5121a232e | 8651 | /* |
| pcercuei | 0:03b5121a232e | 8652 | * No luck, the namespace is out of scope or shadowed. |
| pcercuei | 0:03b5121a232e | 8653 | */ |
| pcercuei | 0:03b5121a232e | 8654 | if (elem == NULL) { |
| pcercuei | 0:03b5121a232e | 8655 | xmlNsPtr tmpns; |
| pcercuei | 0:03b5121a232e | 8656 | |
| pcercuei | 0:03b5121a232e | 8657 | /* |
| pcercuei | 0:03b5121a232e | 8658 | * Store ns-decls in "oldNs" of the document-node. |
| pcercuei | 0:03b5121a232e | 8659 | */ |
| pcercuei | 0:03b5121a232e | 8660 | tmpns = xmlDOMWrapStoreNs(doc, ns->href, ns->prefix); |
| pcercuei | 0:03b5121a232e | 8661 | if (tmpns == NULL) |
| pcercuei | 0:03b5121a232e | 8662 | return (-1); |
| pcercuei | 0:03b5121a232e | 8663 | /* |
| pcercuei | 0:03b5121a232e | 8664 | * Insert mapping. |
| pcercuei | 0:03b5121a232e | 8665 | */ |
| pcercuei | 0:03b5121a232e | 8666 | if (xmlDOMWrapNsMapAddItem(nsMap, -1, ns, |
| pcercuei | 0:03b5121a232e | 8667 | tmpns, XML_TREE_NSMAP_DOC) == NULL) { |
| pcercuei | 0:03b5121a232e | 8668 | xmlFreeNs(tmpns); |
| pcercuei | 0:03b5121a232e | 8669 | return (-1); |
| pcercuei | 0:03b5121a232e | 8670 | } |
| pcercuei | 0:03b5121a232e | 8671 | *retNs = tmpns; |
| pcercuei | 0:03b5121a232e | 8672 | } else { |
| pcercuei | 0:03b5121a232e | 8673 | xmlNsPtr tmpns; |
| pcercuei | 0:03b5121a232e | 8674 | |
| pcercuei | 0:03b5121a232e | 8675 | tmpns = xmlDOMWrapNSNormDeclareNsForced(doc, elem, ns->href, |
| pcercuei | 0:03b5121a232e | 8676 | ns->prefix, 0); |
| pcercuei | 0:03b5121a232e | 8677 | if (tmpns == NULL) |
| pcercuei | 0:03b5121a232e | 8678 | return (-1); |
| pcercuei | 0:03b5121a232e | 8679 | |
| pcercuei | 0:03b5121a232e | 8680 | if (*nsMap != NULL) { |
| pcercuei | 0:03b5121a232e | 8681 | /* |
| pcercuei | 0:03b5121a232e | 8682 | * Does it shadow ancestor ns-decls? |
| pcercuei | 0:03b5121a232e | 8683 | */ |
| pcercuei | 0:03b5121a232e | 8684 | XML_NSMAP_FOREACH(*nsMap, mi) { |
| pcercuei | 0:03b5121a232e | 8685 | if ((mi->depth < depth) && |
| pcercuei | 0:03b5121a232e | 8686 | (mi->shadowDepth == -1) && |
| pcercuei | 0:03b5121a232e | 8687 | ((ns->prefix == mi->newNs->prefix) || |
| pcercuei | 0:03b5121a232e | 8688 | xmlStrEqual(ns->prefix, mi->newNs->prefix))) { |
| pcercuei | 0:03b5121a232e | 8689 | /* |
| pcercuei | 0:03b5121a232e | 8690 | * Shadows. |
| pcercuei | 0:03b5121a232e | 8691 | */ |
| pcercuei | 0:03b5121a232e | 8692 | mi->shadowDepth = depth; |
| pcercuei | 0:03b5121a232e | 8693 | break; |
| pcercuei | 0:03b5121a232e | 8694 | } |
| pcercuei | 0:03b5121a232e | 8695 | } |
| pcercuei | 0:03b5121a232e | 8696 | } |
| pcercuei | 0:03b5121a232e | 8697 | if (xmlDOMWrapNsMapAddItem(nsMap, -1, ns, tmpns, depth) == NULL) { |
| pcercuei | 0:03b5121a232e | 8698 | xmlFreeNs(tmpns); |
| pcercuei | 0:03b5121a232e | 8699 | return (-1); |
| pcercuei | 0:03b5121a232e | 8700 | } |
| pcercuei | 0:03b5121a232e | 8701 | *retNs = tmpns; |
| pcercuei | 0:03b5121a232e | 8702 | } |
| pcercuei | 0:03b5121a232e | 8703 | return (0); |
| pcercuei | 0:03b5121a232e | 8704 | } |
| pcercuei | 0:03b5121a232e | 8705 | |
| pcercuei | 0:03b5121a232e | 8706 | typedef enum { |
| pcercuei | 0:03b5121a232e | 8707 | XML_DOM_RECONNS_REMOVEREDUND = 1<<0 |
| pcercuei | 0:03b5121a232e | 8708 | } xmlDOMReconcileNSOptions; |
| pcercuei | 0:03b5121a232e | 8709 | |
| pcercuei | 0:03b5121a232e | 8710 | /* |
| pcercuei | 0:03b5121a232e | 8711 | * xmlDOMWrapReconcileNamespaces: |
| pcercuei | 0:03b5121a232e | 8712 | * @ctxt: DOM wrapper context, unused at the moment |
| pcercuei | 0:03b5121a232e | 8713 | * @elem: the element-node |
| pcercuei | 0:03b5121a232e | 8714 | * @options: option flags |
| pcercuei | 0:03b5121a232e | 8715 | * |
| pcercuei | 0:03b5121a232e | 8716 | * Ensures that ns-references point to ns-decls hold on element-nodes. |
| pcercuei | 0:03b5121a232e | 8717 | * Ensures that the tree is namespace wellformed by creating additional |
| pcercuei | 0:03b5121a232e | 8718 | * ns-decls where needed. Note that, since prefixes of already existent |
| pcercuei | 0:03b5121a232e | 8719 | * ns-decls can be shadowed by this process, it could break QNames in |
| pcercuei | 0:03b5121a232e | 8720 | * attribute values or element content. |
| pcercuei | 0:03b5121a232e | 8721 | * |
| pcercuei | 0:03b5121a232e | 8722 | * NOTE: This function was not intensively tested. |
| pcercuei | 0:03b5121a232e | 8723 | * |
| pcercuei | 0:03b5121a232e | 8724 | * Returns 0 if succeeded, -1 otherwise and on API/internal errors. |
| pcercuei | 0:03b5121a232e | 8725 | */ |
| pcercuei | 0:03b5121a232e | 8726 | |
| pcercuei | 0:03b5121a232e | 8727 | int |
| pcercuei | 0:03b5121a232e | 8728 | xmlDOMWrapReconcileNamespaces(xmlDOMWrapCtxtPtr ctxt ATTRIBUTE_UNUSED, |
| pcercuei | 0:03b5121a232e | 8729 | xmlNodePtr elem, |
| pcercuei | 0:03b5121a232e | 8730 | int options) |
| pcercuei | 0:03b5121a232e | 8731 | { |
| pcercuei | 0:03b5121a232e | 8732 | int depth = -1, adoptns = 0, parnsdone = 0; |
| pcercuei | 0:03b5121a232e | 8733 | xmlNsPtr ns, prevns; |
| pcercuei | 0:03b5121a232e | 8734 | xmlDocPtr doc; |
| pcercuei | 0:03b5121a232e | 8735 | xmlNodePtr cur, curElem = NULL; |
| pcercuei | 0:03b5121a232e | 8736 | xmlNsMapPtr nsMap = NULL; |
| pcercuei | 0:03b5121a232e | 8737 | xmlNsMapItemPtr /* topmi = NULL, */ mi; |
| pcercuei | 0:03b5121a232e | 8738 | /* @ancestorsOnly should be set by an option flag. */ |
| pcercuei | 0:03b5121a232e | 8739 | int ancestorsOnly = 0; |
| pcercuei | 0:03b5121a232e | 8740 | int optRemoveRedundantNS = |
| pcercuei | 0:03b5121a232e | 8741 | ((xmlDOMReconcileNSOptions) options & XML_DOM_RECONNS_REMOVEREDUND) ? 1 : 0; |
| pcercuei | 0:03b5121a232e | 8742 | xmlNsPtr *listRedund = NULL; |
| pcercuei | 0:03b5121a232e | 8743 | int sizeRedund = 0, nbRedund = 0, ret, i, j; |
| pcercuei | 0:03b5121a232e | 8744 | |
| pcercuei | 0:03b5121a232e | 8745 | if ((elem == NULL) || (elem->doc == NULL) || |
| pcercuei | 0:03b5121a232e | 8746 | (elem->type != XML_ELEMENT_NODE)) |
| pcercuei | 0:03b5121a232e | 8747 | return (-1); |
| pcercuei | 0:03b5121a232e | 8748 | |
| pcercuei | 0:03b5121a232e | 8749 | doc = elem->doc; |
| pcercuei | 0:03b5121a232e | 8750 | cur = elem; |
| pcercuei | 0:03b5121a232e | 8751 | do { |
| pcercuei | 0:03b5121a232e | 8752 | switch (cur->type) { |
| pcercuei | 0:03b5121a232e | 8753 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 8754 | adoptns = 1; |
| pcercuei | 0:03b5121a232e | 8755 | curElem = cur; |
| pcercuei | 0:03b5121a232e | 8756 | depth++; |
| pcercuei | 0:03b5121a232e | 8757 | /* |
| pcercuei | 0:03b5121a232e | 8758 | * Namespace declarations. |
| pcercuei | 0:03b5121a232e | 8759 | */ |
| pcercuei | 0:03b5121a232e | 8760 | if (cur->nsDef != NULL) { |
| pcercuei | 0:03b5121a232e | 8761 | prevns = NULL; |
| pcercuei | 0:03b5121a232e | 8762 | ns = cur->nsDef; |
| pcercuei | 0:03b5121a232e | 8763 | while (ns != NULL) { |
| pcercuei | 0:03b5121a232e | 8764 | if (! parnsdone) { |
| pcercuei | 0:03b5121a232e | 8765 | if ((elem->parent) && |
| pcercuei | 0:03b5121a232e | 8766 | ((xmlNodePtr) elem->parent->doc != elem->parent)) { |
| pcercuei | 0:03b5121a232e | 8767 | /* |
| pcercuei | 0:03b5121a232e | 8768 | * Gather ancestor in-scope ns-decls. |
| pcercuei | 0:03b5121a232e | 8769 | */ |
| pcercuei | 0:03b5121a232e | 8770 | if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, |
| pcercuei | 0:03b5121a232e | 8771 | elem->parent) == -1) |
| pcercuei | 0:03b5121a232e | 8772 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 8773 | } |
| pcercuei | 0:03b5121a232e | 8774 | parnsdone = 1; |
| pcercuei | 0:03b5121a232e | 8775 | } |
| pcercuei | 0:03b5121a232e | 8776 | |
| pcercuei | 0:03b5121a232e | 8777 | /* |
| pcercuei | 0:03b5121a232e | 8778 | * Lookup the ns ancestor-axis for equal ns-decls in scope. |
| pcercuei | 0:03b5121a232e | 8779 | */ |
| pcercuei | 0:03b5121a232e | 8780 | if (optRemoveRedundantNS && XML_NSMAP_NOTEMPTY(nsMap)) { |
| pcercuei | 0:03b5121a232e | 8781 | XML_NSMAP_FOREACH(nsMap, mi) { |
| pcercuei | 0:03b5121a232e | 8782 | if ((mi->depth >= XML_TREE_NSMAP_PARENT) && |
| pcercuei | 0:03b5121a232e | 8783 | (mi->shadowDepth == -1) && |
| pcercuei | 0:03b5121a232e | 8784 | ((ns->prefix == mi->newNs->prefix) || |
| pcercuei | 0:03b5121a232e | 8785 | xmlStrEqual(ns->prefix, mi->newNs->prefix)) && |
| pcercuei | 0:03b5121a232e | 8786 | ((ns->href == mi->newNs->href) || |
| pcercuei | 0:03b5121a232e | 8787 | xmlStrEqual(ns->href, mi->newNs->href))) |
| pcercuei | 0:03b5121a232e | 8788 | { |
| pcercuei | 0:03b5121a232e | 8789 | /* |
| pcercuei | 0:03b5121a232e | 8790 | * A redundant ns-decl was found. |
| pcercuei | 0:03b5121a232e | 8791 | * Add it to the list of redundant ns-decls. |
| pcercuei | 0:03b5121a232e | 8792 | */ |
| pcercuei | 0:03b5121a232e | 8793 | if (xmlDOMWrapNSNormAddNsMapItem2(&listRedund, |
| pcercuei | 0:03b5121a232e | 8794 | &sizeRedund, &nbRedund, ns, mi->newNs) == -1) |
| pcercuei | 0:03b5121a232e | 8795 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 8796 | /* |
| pcercuei | 0:03b5121a232e | 8797 | * Remove the ns-decl from the element-node. |
| pcercuei | 0:03b5121a232e | 8798 | */ |
| pcercuei | 0:03b5121a232e | 8799 | if (prevns) |
| pcercuei | 0:03b5121a232e | 8800 | prevns->next = ns->next; |
| pcercuei | 0:03b5121a232e | 8801 | else |
| pcercuei | 0:03b5121a232e | 8802 | cur->nsDef = ns->next; |
| pcercuei | 0:03b5121a232e | 8803 | goto next_ns_decl; |
| pcercuei | 0:03b5121a232e | 8804 | } |
| pcercuei | 0:03b5121a232e | 8805 | } |
| pcercuei | 0:03b5121a232e | 8806 | } |
| pcercuei | 0:03b5121a232e | 8807 | |
| pcercuei | 0:03b5121a232e | 8808 | /* |
| pcercuei | 0:03b5121a232e | 8809 | * Skip ns-references handling if the referenced |
| pcercuei | 0:03b5121a232e | 8810 | * ns-decl is declared on the same element. |
| pcercuei | 0:03b5121a232e | 8811 | */ |
| pcercuei | 0:03b5121a232e | 8812 | if ((cur->ns != NULL) && adoptns && (cur->ns == ns)) |
| pcercuei | 0:03b5121a232e | 8813 | adoptns = 0; |
| pcercuei | 0:03b5121a232e | 8814 | /* |
| pcercuei | 0:03b5121a232e | 8815 | * Does it shadow any ns-decl? |
| pcercuei | 0:03b5121a232e | 8816 | */ |
| pcercuei | 0:03b5121a232e | 8817 | if (XML_NSMAP_NOTEMPTY(nsMap)) { |
| pcercuei | 0:03b5121a232e | 8818 | XML_NSMAP_FOREACH(nsMap, mi) { |
| pcercuei | 0:03b5121a232e | 8819 | if ((mi->depth >= XML_TREE_NSMAP_PARENT) && |
| pcercuei | 0:03b5121a232e | 8820 | (mi->shadowDepth == -1) && |
| pcercuei | 0:03b5121a232e | 8821 | ((ns->prefix == mi->newNs->prefix) || |
| pcercuei | 0:03b5121a232e | 8822 | xmlStrEqual(ns->prefix, mi->newNs->prefix))) { |
| pcercuei | 0:03b5121a232e | 8823 | |
| pcercuei | 0:03b5121a232e | 8824 | mi->shadowDepth = depth; |
| pcercuei | 0:03b5121a232e | 8825 | } |
| pcercuei | 0:03b5121a232e | 8826 | } |
| pcercuei | 0:03b5121a232e | 8827 | } |
| pcercuei | 0:03b5121a232e | 8828 | /* |
| pcercuei | 0:03b5121a232e | 8829 | * Push mapping. |
| pcercuei | 0:03b5121a232e | 8830 | */ |
| pcercuei | 0:03b5121a232e | 8831 | if (xmlDOMWrapNsMapAddItem(&nsMap, -1, ns, ns, |
| pcercuei | 0:03b5121a232e | 8832 | depth) == NULL) |
| pcercuei | 0:03b5121a232e | 8833 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 8834 | |
| pcercuei | 0:03b5121a232e | 8835 | prevns = ns; |
| pcercuei | 0:03b5121a232e | 8836 | next_ns_decl: |
| pcercuei | 0:03b5121a232e | 8837 | ns = ns->next; |
| pcercuei | 0:03b5121a232e | 8838 | } |
| pcercuei | 0:03b5121a232e | 8839 | } |
| pcercuei | 0:03b5121a232e | 8840 | if (! adoptns) |
| pcercuei | 0:03b5121a232e | 8841 | goto ns_end; |
| pcercuei | 0:03b5121a232e | 8842 | /* No break on purpose. */ |
| pcercuei | 0:03b5121a232e | 8843 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 8844 | /* No ns, no fun. */ |
| pcercuei | 0:03b5121a232e | 8845 | if (cur->ns == NULL) |
| pcercuei | 0:03b5121a232e | 8846 | goto ns_end; |
| pcercuei | 0:03b5121a232e | 8847 | |
| pcercuei | 0:03b5121a232e | 8848 | if (! parnsdone) { |
| pcercuei | 0:03b5121a232e | 8849 | if ((elem->parent) && |
| pcercuei | 0:03b5121a232e | 8850 | ((xmlNodePtr) elem->parent->doc != elem->parent)) { |
| pcercuei | 0:03b5121a232e | 8851 | if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, |
| pcercuei | 0:03b5121a232e | 8852 | elem->parent) == -1) |
| pcercuei | 0:03b5121a232e | 8853 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 8854 | } |
| pcercuei | 0:03b5121a232e | 8855 | parnsdone = 1; |
| pcercuei | 0:03b5121a232e | 8856 | } |
| pcercuei | 0:03b5121a232e | 8857 | /* |
| pcercuei | 0:03b5121a232e | 8858 | * Adjust the reference if this was a redundant ns-decl. |
| pcercuei | 0:03b5121a232e | 8859 | */ |
| pcercuei | 0:03b5121a232e | 8860 | if (listRedund) { |
| pcercuei | 0:03b5121a232e | 8861 | for (i = 0, j = 0; i < nbRedund; i++, j += 2) { |
| pcercuei | 0:03b5121a232e | 8862 | if (cur->ns == listRedund[j]) { |
| pcercuei | 0:03b5121a232e | 8863 | cur->ns = listRedund[++j]; |
| pcercuei | 0:03b5121a232e | 8864 | break; |
| pcercuei | 0:03b5121a232e | 8865 | } |
| pcercuei | 0:03b5121a232e | 8866 | } |
| pcercuei | 0:03b5121a232e | 8867 | } |
| pcercuei | 0:03b5121a232e | 8868 | /* |
| pcercuei | 0:03b5121a232e | 8869 | * Adopt ns-references. |
| pcercuei | 0:03b5121a232e | 8870 | */ |
| pcercuei | 0:03b5121a232e | 8871 | if (XML_NSMAP_NOTEMPTY(nsMap)) { |
| pcercuei | 0:03b5121a232e | 8872 | /* |
| pcercuei | 0:03b5121a232e | 8873 | * Search for a mapping. |
| pcercuei | 0:03b5121a232e | 8874 | */ |
| pcercuei | 0:03b5121a232e | 8875 | XML_NSMAP_FOREACH(nsMap, mi) { |
| pcercuei | 0:03b5121a232e | 8876 | if ((mi->shadowDepth == -1) && |
| pcercuei | 0:03b5121a232e | 8877 | (cur->ns == mi->oldNs)) { |
| pcercuei | 0:03b5121a232e | 8878 | |
| pcercuei | 0:03b5121a232e | 8879 | cur->ns = mi->newNs; |
| pcercuei | 0:03b5121a232e | 8880 | goto ns_end; |
| pcercuei | 0:03b5121a232e | 8881 | } |
| pcercuei | 0:03b5121a232e | 8882 | } |
| pcercuei | 0:03b5121a232e | 8883 | } |
| pcercuei | 0:03b5121a232e | 8884 | /* |
| pcercuei | 0:03b5121a232e | 8885 | * Aquire a normalized ns-decl and add it to the map. |
| pcercuei | 0:03b5121a232e | 8886 | */ |
| pcercuei | 0:03b5121a232e | 8887 | if (xmlDOMWrapNSNormAquireNormalizedNs(doc, curElem, |
| pcercuei | 0:03b5121a232e | 8888 | cur->ns, &ns, |
| pcercuei | 0:03b5121a232e | 8889 | &nsMap, depth, |
| pcercuei | 0:03b5121a232e | 8890 | ancestorsOnly, |
| pcercuei | 0:03b5121a232e | 8891 | (cur->type == XML_ATTRIBUTE_NODE) ? 1 : 0) == -1) |
| pcercuei | 0:03b5121a232e | 8892 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 8893 | cur->ns = ns; |
| pcercuei | 0:03b5121a232e | 8894 | |
| pcercuei | 0:03b5121a232e | 8895 | ns_end: |
| pcercuei | 0:03b5121a232e | 8896 | if ((cur->type == XML_ELEMENT_NODE) && |
| pcercuei | 0:03b5121a232e | 8897 | (cur->properties != NULL)) { |
| pcercuei | 0:03b5121a232e | 8898 | /* |
| pcercuei | 0:03b5121a232e | 8899 | * Process attributes. |
| pcercuei | 0:03b5121a232e | 8900 | */ |
| pcercuei | 0:03b5121a232e | 8901 | cur = (xmlNodePtr) cur->properties; |
| pcercuei | 0:03b5121a232e | 8902 | continue; |
| pcercuei | 0:03b5121a232e | 8903 | } |
| pcercuei | 0:03b5121a232e | 8904 | break; |
| pcercuei | 0:03b5121a232e | 8905 | default: |
| pcercuei | 0:03b5121a232e | 8906 | goto next_sibling; |
| pcercuei | 0:03b5121a232e | 8907 | } |
| pcercuei | 0:03b5121a232e | 8908 | into_content: |
| pcercuei | 0:03b5121a232e | 8909 | if ((cur->type == XML_ELEMENT_NODE) && |
| pcercuei | 0:03b5121a232e | 8910 | (cur->children != NULL)) { |
| pcercuei | 0:03b5121a232e | 8911 | /* |
| pcercuei | 0:03b5121a232e | 8912 | * Process content of element-nodes only. |
| pcercuei | 0:03b5121a232e | 8913 | */ |
| pcercuei | 0:03b5121a232e | 8914 | cur = cur->children; |
| pcercuei | 0:03b5121a232e | 8915 | continue; |
| pcercuei | 0:03b5121a232e | 8916 | } |
| pcercuei | 0:03b5121a232e | 8917 | next_sibling: |
| pcercuei | 0:03b5121a232e | 8918 | if (cur == elem) |
| pcercuei | 0:03b5121a232e | 8919 | break; |
| pcercuei | 0:03b5121a232e | 8920 | if (cur->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 8921 | if (XML_NSMAP_NOTEMPTY(nsMap)) { |
| pcercuei | 0:03b5121a232e | 8922 | /* |
| pcercuei | 0:03b5121a232e | 8923 | * Pop mappings. |
| pcercuei | 0:03b5121a232e | 8924 | */ |
| pcercuei | 0:03b5121a232e | 8925 | while ((nsMap->last != NULL) && |
| pcercuei | 0:03b5121a232e | 8926 | (nsMap->last->depth >= depth)) |
| pcercuei | 0:03b5121a232e | 8927 | { |
| pcercuei | 0:03b5121a232e | 8928 | XML_NSMAP_POP(nsMap, mi) |
| pcercuei | 0:03b5121a232e | 8929 | } |
| pcercuei | 0:03b5121a232e | 8930 | /* |
| pcercuei | 0:03b5121a232e | 8931 | * Unshadow. |
| pcercuei | 0:03b5121a232e | 8932 | */ |
| pcercuei | 0:03b5121a232e | 8933 | XML_NSMAP_FOREACH(nsMap, mi) { |
| pcercuei | 0:03b5121a232e | 8934 | if (mi->shadowDepth >= depth) |
| pcercuei | 0:03b5121a232e | 8935 | mi->shadowDepth = -1; |
| pcercuei | 0:03b5121a232e | 8936 | } |
| pcercuei | 0:03b5121a232e | 8937 | } |
| pcercuei | 0:03b5121a232e | 8938 | depth--; |
| pcercuei | 0:03b5121a232e | 8939 | } |
| pcercuei | 0:03b5121a232e | 8940 | if (cur->next != NULL) |
| pcercuei | 0:03b5121a232e | 8941 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 8942 | else { |
| pcercuei | 0:03b5121a232e | 8943 | if (cur->type == XML_ATTRIBUTE_NODE) { |
| pcercuei | 0:03b5121a232e | 8944 | cur = cur->parent; |
| pcercuei | 0:03b5121a232e | 8945 | goto into_content; |
| pcercuei | 0:03b5121a232e | 8946 | } |
| pcercuei | 0:03b5121a232e | 8947 | cur = cur->parent; |
| pcercuei | 0:03b5121a232e | 8948 | goto next_sibling; |
| pcercuei | 0:03b5121a232e | 8949 | } |
| pcercuei | 0:03b5121a232e | 8950 | } while (cur != NULL); |
| pcercuei | 0:03b5121a232e | 8951 | |
| pcercuei | 0:03b5121a232e | 8952 | ret = 0; |
| pcercuei | 0:03b5121a232e | 8953 | goto exit; |
| pcercuei | 0:03b5121a232e | 8954 | internal_error: |
| pcercuei | 0:03b5121a232e | 8955 | ret = -1; |
| pcercuei | 0:03b5121a232e | 8956 | exit: |
| pcercuei | 0:03b5121a232e | 8957 | if (listRedund) { |
| pcercuei | 0:03b5121a232e | 8958 | for (i = 0, j = 0; i < nbRedund; i++, j += 2) { |
| pcercuei | 0:03b5121a232e | 8959 | xmlFreeNs(listRedund[j]); |
| pcercuei | 0:03b5121a232e | 8960 | } |
| pcercuei | 0:03b5121a232e | 8961 | xmlFree(listRedund); |
| pcercuei | 0:03b5121a232e | 8962 | } |
| pcercuei | 0:03b5121a232e | 8963 | if (nsMap != NULL) |
| pcercuei | 0:03b5121a232e | 8964 | xmlDOMWrapNsMapFree(nsMap); |
| pcercuei | 0:03b5121a232e | 8965 | return (ret); |
| pcercuei | 0:03b5121a232e | 8966 | } |
| pcercuei | 0:03b5121a232e | 8967 | |
| pcercuei | 0:03b5121a232e | 8968 | /* |
| pcercuei | 0:03b5121a232e | 8969 | * xmlDOMWrapAdoptBranch: |
| pcercuei | 0:03b5121a232e | 8970 | * @ctxt: the optional context for custom processing |
| pcercuei | 0:03b5121a232e | 8971 | * @sourceDoc: the optional sourceDoc |
| pcercuei | 0:03b5121a232e | 8972 | * @node: the element-node to start with |
| pcercuei | 0:03b5121a232e | 8973 | * @destDoc: the destination doc for adoption |
| pcercuei | 0:03b5121a232e | 8974 | * @destParent: the optional new parent of @node in @destDoc |
| pcercuei | 0:03b5121a232e | 8975 | * @options: option flags |
| pcercuei | 0:03b5121a232e | 8976 | * |
| pcercuei | 0:03b5121a232e | 8977 | * Ensures that ns-references point to @destDoc: either to |
| pcercuei | 0:03b5121a232e | 8978 | * elements->nsDef entries if @destParent is given, or to |
| pcercuei | 0:03b5121a232e | 8979 | * @destDoc->oldNs otherwise. |
| pcercuei | 0:03b5121a232e | 8980 | * If @destParent is given, it ensures that the tree is namespace |
| pcercuei | 0:03b5121a232e | 8981 | * wellformed by creating additional ns-decls where needed. |
| pcercuei | 0:03b5121a232e | 8982 | * Note that, since prefixes of already existent ns-decls can be |
| pcercuei | 0:03b5121a232e | 8983 | * shadowed by this process, it could break QNames in attribute |
| pcercuei | 0:03b5121a232e | 8984 | * values or element content. |
| pcercuei | 0:03b5121a232e | 8985 | * |
| pcercuei | 0:03b5121a232e | 8986 | * NOTE: This function was not intensively tested. |
| pcercuei | 0:03b5121a232e | 8987 | * |
| pcercuei | 0:03b5121a232e | 8988 | * Returns 0 if succeeded, -1 otherwise and on API/internal errors. |
| pcercuei | 0:03b5121a232e | 8989 | */ |
| pcercuei | 0:03b5121a232e | 8990 | static int |
| pcercuei | 0:03b5121a232e | 8991 | xmlDOMWrapAdoptBranch(xmlDOMWrapCtxtPtr ctxt, |
| pcercuei | 0:03b5121a232e | 8992 | xmlDocPtr sourceDoc, |
| pcercuei | 0:03b5121a232e | 8993 | xmlNodePtr node, |
| pcercuei | 0:03b5121a232e | 8994 | xmlDocPtr destDoc, |
| pcercuei | 0:03b5121a232e | 8995 | xmlNodePtr destParent, |
| pcercuei | 0:03b5121a232e | 8996 | int options ATTRIBUTE_UNUSED) |
| pcercuei | 0:03b5121a232e | 8997 | { |
| pcercuei | 0:03b5121a232e | 8998 | int ret = 0; |
| pcercuei | 0:03b5121a232e | 8999 | xmlNodePtr cur, curElem = NULL; |
| pcercuei | 0:03b5121a232e | 9000 | xmlNsMapPtr nsMap = NULL; |
| pcercuei | 0:03b5121a232e | 9001 | xmlNsMapItemPtr mi; |
| pcercuei | 0:03b5121a232e | 9002 | xmlNsPtr ns = NULL; |
| pcercuei | 0:03b5121a232e | 9003 | int depth = -1, adoptStr = 1; |
| pcercuei | 0:03b5121a232e | 9004 | /* gather @parent's ns-decls. */ |
| pcercuei | 0:03b5121a232e | 9005 | int parnsdone; |
| pcercuei | 0:03b5121a232e | 9006 | /* @ancestorsOnly should be set per option. */ |
| pcercuei | 0:03b5121a232e | 9007 | int ancestorsOnly = 0; |
| pcercuei | 0:03b5121a232e | 9008 | |
| pcercuei | 0:03b5121a232e | 9009 | /* |
| pcercuei | 0:03b5121a232e | 9010 | * Optimize string adoption for equal or none dicts. |
| pcercuei | 0:03b5121a232e | 9011 | */ |
| pcercuei | 0:03b5121a232e | 9012 | if ((sourceDoc != NULL) && |
| pcercuei | 0:03b5121a232e | 9013 | (sourceDoc->dict == destDoc->dict)) |
| pcercuei | 0:03b5121a232e | 9014 | adoptStr = 0; |
| pcercuei | 0:03b5121a232e | 9015 | else |
| pcercuei | 0:03b5121a232e | 9016 | adoptStr = 1; |
| pcercuei | 0:03b5121a232e | 9017 | |
| pcercuei | 0:03b5121a232e | 9018 | /* |
| pcercuei | 0:03b5121a232e | 9019 | * Get the ns-map from the context if available. |
| pcercuei | 0:03b5121a232e | 9020 | */ |
| pcercuei | 0:03b5121a232e | 9021 | if (ctxt) |
| pcercuei | 0:03b5121a232e | 9022 | nsMap = (xmlNsMapPtr) ctxt->namespaceMap; |
| pcercuei | 0:03b5121a232e | 9023 | /* |
| pcercuei | 0:03b5121a232e | 9024 | * Disable search for ns-decls in the parent-axis of the |
| pcercuei | 0:03b5121a232e | 9025 | * desination element, if: |
| pcercuei | 0:03b5121a232e | 9026 | * 1) there's no destination parent |
| pcercuei | 0:03b5121a232e | 9027 | * 2) custom ns-reference handling is used |
| pcercuei | 0:03b5121a232e | 9028 | */ |
| pcercuei | 0:03b5121a232e | 9029 | if ((destParent == NULL) || |
| pcercuei | 0:03b5121a232e | 9030 | (ctxt && ctxt->getNsForNodeFunc)) |
| pcercuei | 0:03b5121a232e | 9031 | { |
| pcercuei | 0:03b5121a232e | 9032 | parnsdone = 1; |
| pcercuei | 0:03b5121a232e | 9033 | } else |
| pcercuei | 0:03b5121a232e | 9034 | parnsdone = 0; |
| pcercuei | 0:03b5121a232e | 9035 | |
| pcercuei | 0:03b5121a232e | 9036 | cur = node; |
| pcercuei | 0:03b5121a232e | 9037 | if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) |
| pcercuei | 0:03b5121a232e | 9038 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9039 | |
| pcercuei | 0:03b5121a232e | 9040 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 9041 | /* |
| pcercuei | 0:03b5121a232e | 9042 | * Paranoid source-doc sanity check. |
| pcercuei | 0:03b5121a232e | 9043 | */ |
| pcercuei | 0:03b5121a232e | 9044 | if (cur->doc != sourceDoc) { |
| pcercuei | 0:03b5121a232e | 9045 | /* |
| pcercuei | 0:03b5121a232e | 9046 | * We'll assume XIncluded nodes if the doc differs. |
| pcercuei | 0:03b5121a232e | 9047 | * TODO: Do we need to reconciliate XIncluded nodes? |
| pcercuei | 0:03b5121a232e | 9048 | * This here skips XIncluded nodes and tries to handle |
| pcercuei | 0:03b5121a232e | 9049 | * broken sequences. |
| pcercuei | 0:03b5121a232e | 9050 | */ |
| pcercuei | 0:03b5121a232e | 9051 | if (cur->next == NULL) |
| pcercuei | 0:03b5121a232e | 9052 | goto leave_node; |
| pcercuei | 0:03b5121a232e | 9053 | do { |
| pcercuei | 0:03b5121a232e | 9054 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 9055 | if ((cur->type == XML_XINCLUDE_END) || |
| pcercuei | 0:03b5121a232e | 9056 | (cur->doc == node->doc)) |
| pcercuei | 0:03b5121a232e | 9057 | break; |
| pcercuei | 0:03b5121a232e | 9058 | } while (cur->next != NULL); |
| pcercuei | 0:03b5121a232e | 9059 | |
| pcercuei | 0:03b5121a232e | 9060 | if (cur->doc != node->doc) |
| pcercuei | 0:03b5121a232e | 9061 | goto leave_node; |
| pcercuei | 0:03b5121a232e | 9062 | } |
| pcercuei | 0:03b5121a232e | 9063 | cur->doc = destDoc; |
| pcercuei | 0:03b5121a232e | 9064 | switch (cur->type) { |
| pcercuei | 0:03b5121a232e | 9065 | case XML_XINCLUDE_START: |
| pcercuei | 0:03b5121a232e | 9066 | case XML_XINCLUDE_END: |
| pcercuei | 0:03b5121a232e | 9067 | /* |
| pcercuei | 0:03b5121a232e | 9068 | * TODO |
| pcercuei | 0:03b5121a232e | 9069 | */ |
| pcercuei | 0:03b5121a232e | 9070 | return (-1); |
| pcercuei | 0:03b5121a232e | 9071 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 9072 | curElem = cur; |
| pcercuei | 0:03b5121a232e | 9073 | depth++; |
| pcercuei | 0:03b5121a232e | 9074 | /* |
| pcercuei | 0:03b5121a232e | 9075 | * Namespace declarations. |
| pcercuei | 0:03b5121a232e | 9076 | * - ns->href and ns->prefix are never in the dict, so |
| pcercuei | 0:03b5121a232e | 9077 | * we need not move the values over to the destination dict. |
| pcercuei | 0:03b5121a232e | 9078 | * - Note that for custom handling of ns-references, |
| pcercuei | 0:03b5121a232e | 9079 | * the ns-decls need not be stored in the ns-map, |
| pcercuei | 0:03b5121a232e | 9080 | * since they won't be referenced by node->ns. |
| pcercuei | 0:03b5121a232e | 9081 | */ |
| pcercuei | 0:03b5121a232e | 9082 | if ((cur->nsDef) && |
| pcercuei | 0:03b5121a232e | 9083 | ((ctxt == NULL) || (ctxt->getNsForNodeFunc == NULL))) |
| pcercuei | 0:03b5121a232e | 9084 | { |
| pcercuei | 0:03b5121a232e | 9085 | if (! parnsdone) { |
| pcercuei | 0:03b5121a232e | 9086 | /* |
| pcercuei | 0:03b5121a232e | 9087 | * Gather @parent's in-scope ns-decls. |
| pcercuei | 0:03b5121a232e | 9088 | */ |
| pcercuei | 0:03b5121a232e | 9089 | if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, |
| pcercuei | 0:03b5121a232e | 9090 | destParent) == -1) |
| pcercuei | 0:03b5121a232e | 9091 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9092 | parnsdone = 1; |
| pcercuei | 0:03b5121a232e | 9093 | } |
| pcercuei | 0:03b5121a232e | 9094 | for (ns = cur->nsDef; ns != NULL; ns = ns->next) { |
| pcercuei | 0:03b5121a232e | 9095 | /* |
| pcercuei | 0:03b5121a232e | 9096 | * NOTE: ns->prefix and ns->href are never in the dict. |
| pcercuei | 0:03b5121a232e | 9097 | * XML_TREE_ADOPT_STR(ns->prefix) |
| pcercuei | 0:03b5121a232e | 9098 | * XML_TREE_ADOPT_STR(ns->href) |
| pcercuei | 0:03b5121a232e | 9099 | */ |
| pcercuei | 0:03b5121a232e | 9100 | /* |
| pcercuei | 0:03b5121a232e | 9101 | * Does it shadow any ns-decl? |
| pcercuei | 0:03b5121a232e | 9102 | */ |
| pcercuei | 0:03b5121a232e | 9103 | if (XML_NSMAP_NOTEMPTY(nsMap)) { |
| pcercuei | 0:03b5121a232e | 9104 | XML_NSMAP_FOREACH(nsMap, mi) { |
| pcercuei | 0:03b5121a232e | 9105 | if ((mi->depth >= XML_TREE_NSMAP_PARENT) && |
| pcercuei | 0:03b5121a232e | 9106 | (mi->shadowDepth == -1) && |
| pcercuei | 0:03b5121a232e | 9107 | ((ns->prefix == mi->newNs->prefix) || |
| pcercuei | 0:03b5121a232e | 9108 | xmlStrEqual(ns->prefix, |
| pcercuei | 0:03b5121a232e | 9109 | mi->newNs->prefix))) { |
| pcercuei | 0:03b5121a232e | 9110 | |
| pcercuei | 0:03b5121a232e | 9111 | mi->shadowDepth = depth; |
| pcercuei | 0:03b5121a232e | 9112 | } |
| pcercuei | 0:03b5121a232e | 9113 | } |
| pcercuei | 0:03b5121a232e | 9114 | } |
| pcercuei | 0:03b5121a232e | 9115 | /* |
| pcercuei | 0:03b5121a232e | 9116 | * Push mapping. |
| pcercuei | 0:03b5121a232e | 9117 | */ |
| pcercuei | 0:03b5121a232e | 9118 | if (xmlDOMWrapNsMapAddItem(&nsMap, -1, |
| pcercuei | 0:03b5121a232e | 9119 | ns, ns, depth) == NULL) |
| pcercuei | 0:03b5121a232e | 9120 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9121 | } |
| pcercuei | 0:03b5121a232e | 9122 | } |
| pcercuei | 0:03b5121a232e | 9123 | /* No break on purpose. */ |
| pcercuei | 0:03b5121a232e | 9124 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 9125 | /* No namespace, no fun. */ |
| pcercuei | 0:03b5121a232e | 9126 | if (cur->ns == NULL) |
| pcercuei | 0:03b5121a232e | 9127 | goto ns_end; |
| pcercuei | 0:03b5121a232e | 9128 | |
| pcercuei | 0:03b5121a232e | 9129 | if (! parnsdone) { |
| pcercuei | 0:03b5121a232e | 9130 | if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, |
| pcercuei | 0:03b5121a232e | 9131 | destParent) == -1) |
| pcercuei | 0:03b5121a232e | 9132 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9133 | parnsdone = 1; |
| pcercuei | 0:03b5121a232e | 9134 | } |
| pcercuei | 0:03b5121a232e | 9135 | /* |
| pcercuei | 0:03b5121a232e | 9136 | * Adopt ns-references. |
| pcercuei | 0:03b5121a232e | 9137 | */ |
| pcercuei | 0:03b5121a232e | 9138 | if (XML_NSMAP_NOTEMPTY(nsMap)) { |
| pcercuei | 0:03b5121a232e | 9139 | /* |
| pcercuei | 0:03b5121a232e | 9140 | * Search for a mapping. |
| pcercuei | 0:03b5121a232e | 9141 | */ |
| pcercuei | 0:03b5121a232e | 9142 | XML_NSMAP_FOREACH(nsMap, mi) { |
| pcercuei | 0:03b5121a232e | 9143 | if ((mi->shadowDepth == -1) && |
| pcercuei | 0:03b5121a232e | 9144 | (cur->ns == mi->oldNs)) { |
| pcercuei | 0:03b5121a232e | 9145 | |
| pcercuei | 0:03b5121a232e | 9146 | cur->ns = mi->newNs; |
| pcercuei | 0:03b5121a232e | 9147 | goto ns_end; |
| pcercuei | 0:03b5121a232e | 9148 | } |
| pcercuei | 0:03b5121a232e | 9149 | } |
| pcercuei | 0:03b5121a232e | 9150 | } |
| pcercuei | 0:03b5121a232e | 9151 | /* |
| pcercuei | 0:03b5121a232e | 9152 | * No matching namespace in scope. We need a new one. |
| pcercuei | 0:03b5121a232e | 9153 | */ |
| pcercuei | 0:03b5121a232e | 9154 | if ((ctxt) && (ctxt->getNsForNodeFunc)) { |
| pcercuei | 0:03b5121a232e | 9155 | /* |
| pcercuei | 0:03b5121a232e | 9156 | * User-defined behaviour. |
| pcercuei | 0:03b5121a232e | 9157 | */ |
| pcercuei | 0:03b5121a232e | 9158 | ns = ctxt->getNsForNodeFunc(ctxt, cur, |
| pcercuei | 0:03b5121a232e | 9159 | cur->ns->href, cur->ns->prefix); |
| pcercuei | 0:03b5121a232e | 9160 | /* |
| pcercuei | 0:03b5121a232e | 9161 | * Insert mapping if ns is available; it's the users fault |
| pcercuei | 0:03b5121a232e | 9162 | * if not. |
| pcercuei | 0:03b5121a232e | 9163 | */ |
| pcercuei | 0:03b5121a232e | 9164 | if (xmlDOMWrapNsMapAddItem(&nsMap, -1, |
| pcercuei | 0:03b5121a232e | 9165 | cur->ns, ns, XML_TREE_NSMAP_CUSTOM) == NULL) |
| pcercuei | 0:03b5121a232e | 9166 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9167 | cur->ns = ns; |
| pcercuei | 0:03b5121a232e | 9168 | } else { |
| pcercuei | 0:03b5121a232e | 9169 | /* |
| pcercuei | 0:03b5121a232e | 9170 | * Aquire a normalized ns-decl and add it to the map. |
| pcercuei | 0:03b5121a232e | 9171 | */ |
| pcercuei | 0:03b5121a232e | 9172 | if (xmlDOMWrapNSNormAquireNormalizedNs(destDoc, |
| pcercuei | 0:03b5121a232e | 9173 | /* ns-decls on curElem or on destDoc->oldNs */ |
| pcercuei | 0:03b5121a232e | 9174 | destParent ? curElem : NULL, |
| pcercuei | 0:03b5121a232e | 9175 | cur->ns, &ns, |
| pcercuei | 0:03b5121a232e | 9176 | &nsMap, depth, |
| pcercuei | 0:03b5121a232e | 9177 | ancestorsOnly, |
| pcercuei | 0:03b5121a232e | 9178 | /* ns-decls must be prefixed for attributes. */ |
| pcercuei | 0:03b5121a232e | 9179 | (cur->type == XML_ATTRIBUTE_NODE) ? 1 : 0) == -1) |
| pcercuei | 0:03b5121a232e | 9180 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9181 | cur->ns = ns; |
| pcercuei | 0:03b5121a232e | 9182 | } |
| pcercuei | 0:03b5121a232e | 9183 | ns_end: |
| pcercuei | 0:03b5121a232e | 9184 | /* |
| pcercuei | 0:03b5121a232e | 9185 | * Further node properties. |
| pcercuei | 0:03b5121a232e | 9186 | * TODO: Is this all? |
| pcercuei | 0:03b5121a232e | 9187 | */ |
| pcercuei | 0:03b5121a232e | 9188 | XML_TREE_ADOPT_STR(cur->name) |
| pcercuei | 0:03b5121a232e | 9189 | if (cur->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 9190 | cur->psvi = NULL; |
| pcercuei | 0:03b5121a232e | 9191 | cur->line = 0; |
| pcercuei | 0:03b5121a232e | 9192 | cur->extra = 0; |
| pcercuei | 0:03b5121a232e | 9193 | /* |
| pcercuei | 0:03b5121a232e | 9194 | * Walk attributes. |
| pcercuei | 0:03b5121a232e | 9195 | */ |
| pcercuei | 0:03b5121a232e | 9196 | if (cur->properties != NULL) { |
| pcercuei | 0:03b5121a232e | 9197 | /* |
| pcercuei | 0:03b5121a232e | 9198 | * Process first attribute node. |
| pcercuei | 0:03b5121a232e | 9199 | */ |
| pcercuei | 0:03b5121a232e | 9200 | cur = (xmlNodePtr) cur->properties; |
| pcercuei | 0:03b5121a232e | 9201 | continue; |
| pcercuei | 0:03b5121a232e | 9202 | } |
| pcercuei | 0:03b5121a232e | 9203 | } else { |
| pcercuei | 0:03b5121a232e | 9204 | /* |
| pcercuei | 0:03b5121a232e | 9205 | * Attributes. |
| pcercuei | 0:03b5121a232e | 9206 | */ |
| pcercuei | 0:03b5121a232e | 9207 | if ((sourceDoc != NULL) && |
| pcercuei | 0:03b5121a232e | 9208 | (((xmlAttrPtr) cur)->atype == XML_ATTRIBUTE_ID)) |
| pcercuei | 0:03b5121a232e | 9209 | { |
| pcercuei | 0:03b5121a232e | 9210 | xmlRemoveID(sourceDoc, (xmlAttrPtr) cur); |
| pcercuei | 0:03b5121a232e | 9211 | } |
| pcercuei | 0:03b5121a232e | 9212 | ((xmlAttrPtr) cur)->atype = 0; |
| pcercuei | 0:03b5121a232e | 9213 | ((xmlAttrPtr) cur)->psvi = NULL; |
| pcercuei | 0:03b5121a232e | 9214 | } |
| pcercuei | 0:03b5121a232e | 9215 | break; |
| pcercuei | 0:03b5121a232e | 9216 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 9217 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 9218 | /* |
| pcercuei | 0:03b5121a232e | 9219 | * This puts the content in the dest dict, only if |
| pcercuei | 0:03b5121a232e | 9220 | * it was previously in the source dict. |
| pcercuei | 0:03b5121a232e | 9221 | */ |
| pcercuei | 0:03b5121a232e | 9222 | XML_TREE_ADOPT_STR_2(cur->content) |
| pcercuei | 0:03b5121a232e | 9223 | goto leave_node; |
| pcercuei | 0:03b5121a232e | 9224 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 9225 | /* |
| pcercuei | 0:03b5121a232e | 9226 | * Remove reference to the entitity-node. |
| pcercuei | 0:03b5121a232e | 9227 | */ |
| pcercuei | 0:03b5121a232e | 9228 | cur->content = NULL; |
| pcercuei | 0:03b5121a232e | 9229 | cur->children = NULL; |
| pcercuei | 0:03b5121a232e | 9230 | cur->last = NULL; |
| pcercuei | 0:03b5121a232e | 9231 | if ((destDoc->intSubset) || (destDoc->extSubset)) { |
| pcercuei | 0:03b5121a232e | 9232 | xmlEntityPtr ent; |
| pcercuei | 0:03b5121a232e | 9233 | /* |
| pcercuei | 0:03b5121a232e | 9234 | * Assign new entity-node if available. |
| pcercuei | 0:03b5121a232e | 9235 | */ |
| pcercuei | 0:03b5121a232e | 9236 | ent = xmlGetDocEntity(destDoc, cur->name); |
| pcercuei | 0:03b5121a232e | 9237 | if (ent != NULL) { |
| pcercuei | 0:03b5121a232e | 9238 | cur->content = ent->content; |
| pcercuei | 0:03b5121a232e | 9239 | cur->children = (xmlNodePtr) ent; |
| pcercuei | 0:03b5121a232e | 9240 | cur->last = (xmlNodePtr) ent; |
| pcercuei | 0:03b5121a232e | 9241 | } |
| pcercuei | 0:03b5121a232e | 9242 | } |
| pcercuei | 0:03b5121a232e | 9243 | goto leave_node; |
| pcercuei | 0:03b5121a232e | 9244 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 9245 | XML_TREE_ADOPT_STR(cur->name) |
| pcercuei | 0:03b5121a232e | 9246 | XML_TREE_ADOPT_STR_2(cur->content) |
| pcercuei | 0:03b5121a232e | 9247 | break; |
| pcercuei | 0:03b5121a232e | 9248 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 9249 | break; |
| pcercuei | 0:03b5121a232e | 9250 | default: |
| pcercuei | 0:03b5121a232e | 9251 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9252 | } |
| pcercuei | 0:03b5121a232e | 9253 | /* |
| pcercuei | 0:03b5121a232e | 9254 | * Walk the tree. |
| pcercuei | 0:03b5121a232e | 9255 | */ |
| pcercuei | 0:03b5121a232e | 9256 | if (cur->children != NULL) { |
| pcercuei | 0:03b5121a232e | 9257 | cur = cur->children; |
| pcercuei | 0:03b5121a232e | 9258 | continue; |
| pcercuei | 0:03b5121a232e | 9259 | } |
| pcercuei | 0:03b5121a232e | 9260 | |
| pcercuei | 0:03b5121a232e | 9261 | leave_node: |
| pcercuei | 0:03b5121a232e | 9262 | if (cur == node) |
| pcercuei | 0:03b5121a232e | 9263 | break; |
| pcercuei | 0:03b5121a232e | 9264 | if ((cur->type == XML_ELEMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 9265 | (cur->type == XML_XINCLUDE_START) || |
| pcercuei | 0:03b5121a232e | 9266 | (cur->type == XML_XINCLUDE_END)) |
| pcercuei | 0:03b5121a232e | 9267 | { |
| pcercuei | 0:03b5121a232e | 9268 | /* |
| pcercuei | 0:03b5121a232e | 9269 | * TODO: Do we expect nsDefs on XML_XINCLUDE_START? |
| pcercuei | 0:03b5121a232e | 9270 | */ |
| pcercuei | 0:03b5121a232e | 9271 | if (XML_NSMAP_NOTEMPTY(nsMap)) { |
| pcercuei | 0:03b5121a232e | 9272 | /* |
| pcercuei | 0:03b5121a232e | 9273 | * Pop mappings. |
| pcercuei | 0:03b5121a232e | 9274 | */ |
| pcercuei | 0:03b5121a232e | 9275 | while ((nsMap->last != NULL) && |
| pcercuei | 0:03b5121a232e | 9276 | (nsMap->last->depth >= depth)) |
| pcercuei | 0:03b5121a232e | 9277 | { |
| pcercuei | 0:03b5121a232e | 9278 | XML_NSMAP_POP(nsMap, mi) |
| pcercuei | 0:03b5121a232e | 9279 | } |
| pcercuei | 0:03b5121a232e | 9280 | /* |
| pcercuei | 0:03b5121a232e | 9281 | * Unshadow. |
| pcercuei | 0:03b5121a232e | 9282 | */ |
| pcercuei | 0:03b5121a232e | 9283 | XML_NSMAP_FOREACH(nsMap, mi) { |
| pcercuei | 0:03b5121a232e | 9284 | if (mi->shadowDepth >= depth) |
| pcercuei | 0:03b5121a232e | 9285 | mi->shadowDepth = -1; |
| pcercuei | 0:03b5121a232e | 9286 | } |
| pcercuei | 0:03b5121a232e | 9287 | } |
| pcercuei | 0:03b5121a232e | 9288 | depth--; |
| pcercuei | 0:03b5121a232e | 9289 | } |
| pcercuei | 0:03b5121a232e | 9290 | if (cur->next != NULL) |
| pcercuei | 0:03b5121a232e | 9291 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 9292 | else if ((cur->type == XML_ATTRIBUTE_NODE) && |
| pcercuei | 0:03b5121a232e | 9293 | (cur->parent->children != NULL)) |
| pcercuei | 0:03b5121a232e | 9294 | { |
| pcercuei | 0:03b5121a232e | 9295 | cur = cur->parent->children; |
| pcercuei | 0:03b5121a232e | 9296 | } else { |
| pcercuei | 0:03b5121a232e | 9297 | cur = cur->parent; |
| pcercuei | 0:03b5121a232e | 9298 | goto leave_node; |
| pcercuei | 0:03b5121a232e | 9299 | } |
| pcercuei | 0:03b5121a232e | 9300 | } |
| pcercuei | 0:03b5121a232e | 9301 | |
| pcercuei | 0:03b5121a232e | 9302 | goto exit; |
| pcercuei | 0:03b5121a232e | 9303 | |
| pcercuei | 0:03b5121a232e | 9304 | internal_error: |
| pcercuei | 0:03b5121a232e | 9305 | ret = -1; |
| pcercuei | 0:03b5121a232e | 9306 | |
| pcercuei | 0:03b5121a232e | 9307 | exit: |
| pcercuei | 0:03b5121a232e | 9308 | /* |
| pcercuei | 0:03b5121a232e | 9309 | * Cleanup. |
| pcercuei | 0:03b5121a232e | 9310 | */ |
| pcercuei | 0:03b5121a232e | 9311 | if (nsMap != NULL) { |
| pcercuei | 0:03b5121a232e | 9312 | if ((ctxt) && (ctxt->namespaceMap == nsMap)) { |
| pcercuei | 0:03b5121a232e | 9313 | /* |
| pcercuei | 0:03b5121a232e | 9314 | * Just cleanup the map but don't free. |
| pcercuei | 0:03b5121a232e | 9315 | */ |
| pcercuei | 0:03b5121a232e | 9316 | if (nsMap->first) { |
| pcercuei | 0:03b5121a232e | 9317 | if (nsMap->pool) |
| pcercuei | 0:03b5121a232e | 9318 | nsMap->last->next = nsMap->pool; |
| pcercuei | 0:03b5121a232e | 9319 | nsMap->pool = nsMap->first; |
| pcercuei | 0:03b5121a232e | 9320 | nsMap->first = NULL; |
| pcercuei | 0:03b5121a232e | 9321 | } |
| pcercuei | 0:03b5121a232e | 9322 | } else |
| pcercuei | 0:03b5121a232e | 9323 | xmlDOMWrapNsMapFree(nsMap); |
| pcercuei | 0:03b5121a232e | 9324 | } |
| pcercuei | 0:03b5121a232e | 9325 | return(ret); |
| pcercuei | 0:03b5121a232e | 9326 | } |
| pcercuei | 0:03b5121a232e | 9327 | |
| pcercuei | 0:03b5121a232e | 9328 | /* |
| pcercuei | 0:03b5121a232e | 9329 | * xmlDOMWrapCloneNode: |
| pcercuei | 0:03b5121a232e | 9330 | * @ctxt: the optional context for custom processing |
| pcercuei | 0:03b5121a232e | 9331 | * @sourceDoc: the optional sourceDoc |
| pcercuei | 0:03b5121a232e | 9332 | * @node: the node to start with |
| pcercuei | 0:03b5121a232e | 9333 | * @resNode: the clone of the given @node |
| pcercuei | 0:03b5121a232e | 9334 | * @destDoc: the destination doc |
| pcercuei | 0:03b5121a232e | 9335 | * @destParent: the optional new parent of @node in @destDoc |
| pcercuei | 0:03b5121a232e | 9336 | * @deep: descend into child if set |
| pcercuei | 0:03b5121a232e | 9337 | * @options: option flags |
| pcercuei | 0:03b5121a232e | 9338 | * |
| pcercuei | 0:03b5121a232e | 9339 | * References of out-of scope ns-decls are remapped to point to @destDoc: |
| pcercuei | 0:03b5121a232e | 9340 | * 1) If @destParent is given, then nsDef entries on element-nodes are used |
| pcercuei | 0:03b5121a232e | 9341 | * 2) If *no* @destParent is given, then @destDoc->oldNs entries are used. |
| pcercuei | 0:03b5121a232e | 9342 | * This is the case when you don't know already where the cloned branch |
| pcercuei | 0:03b5121a232e | 9343 | * will be added to. |
| pcercuei | 0:03b5121a232e | 9344 | * |
| pcercuei | 0:03b5121a232e | 9345 | * If @destParent is given, it ensures that the tree is namespace |
| pcercuei | 0:03b5121a232e | 9346 | * wellformed by creating additional ns-decls where needed. |
| pcercuei | 0:03b5121a232e | 9347 | * Note that, since prefixes of already existent ns-decls can be |
| pcercuei | 0:03b5121a232e | 9348 | * shadowed by this process, it could break QNames in attribute |
| pcercuei | 0:03b5121a232e | 9349 | * values or element content. |
| pcercuei | 0:03b5121a232e | 9350 | * TODO: |
| pcercuei | 0:03b5121a232e | 9351 | * 1) What to do with XInclude? Currently this returns an error for XInclude. |
| pcercuei | 0:03b5121a232e | 9352 | * |
| pcercuei | 0:03b5121a232e | 9353 | * Returns 0 if the operation succeeded, |
| pcercuei | 0:03b5121a232e | 9354 | * 1 if a node of unsupported (or not yet supported) type was given, |
| pcercuei | 0:03b5121a232e | 9355 | * -1 on API/internal errors. |
| pcercuei | 0:03b5121a232e | 9356 | */ |
| pcercuei | 0:03b5121a232e | 9357 | |
| pcercuei | 0:03b5121a232e | 9358 | int |
| pcercuei | 0:03b5121a232e | 9359 | xmlDOMWrapCloneNode(xmlDOMWrapCtxtPtr ctxt, |
| pcercuei | 0:03b5121a232e | 9360 | xmlDocPtr sourceDoc, |
| pcercuei | 0:03b5121a232e | 9361 | xmlNodePtr node, |
| pcercuei | 0:03b5121a232e | 9362 | xmlNodePtr *resNode, |
| pcercuei | 0:03b5121a232e | 9363 | xmlDocPtr destDoc, |
| pcercuei | 0:03b5121a232e | 9364 | xmlNodePtr destParent, |
| pcercuei | 0:03b5121a232e | 9365 | int deep, |
| pcercuei | 0:03b5121a232e | 9366 | int options ATTRIBUTE_UNUSED) |
| pcercuei | 0:03b5121a232e | 9367 | { |
| pcercuei | 0:03b5121a232e | 9368 | int ret = 0; |
| pcercuei | 0:03b5121a232e | 9369 | xmlNodePtr cur, curElem = NULL; |
| pcercuei | 0:03b5121a232e | 9370 | xmlNsMapPtr nsMap = NULL; |
| pcercuei | 0:03b5121a232e | 9371 | xmlNsMapItemPtr mi; |
| pcercuei | 0:03b5121a232e | 9372 | xmlNsPtr ns; |
| pcercuei | 0:03b5121a232e | 9373 | int depth = -1; |
| pcercuei | 0:03b5121a232e | 9374 | /* int adoptStr = 1; */ |
| pcercuei | 0:03b5121a232e | 9375 | /* gather @parent's ns-decls. */ |
| pcercuei | 0:03b5121a232e | 9376 | int parnsdone = 0; |
| pcercuei | 0:03b5121a232e | 9377 | /* |
| pcercuei | 0:03b5121a232e | 9378 | * @ancestorsOnly: |
| pcercuei | 0:03b5121a232e | 9379 | * TODO: @ancestorsOnly should be set per option. |
| pcercuei | 0:03b5121a232e | 9380 | * |
| pcercuei | 0:03b5121a232e | 9381 | */ |
| pcercuei | 0:03b5121a232e | 9382 | int ancestorsOnly = 0; |
| pcercuei | 0:03b5121a232e | 9383 | xmlNodePtr resultClone = NULL, clone = NULL, parentClone = NULL, prevClone = NULL; |
| pcercuei | 0:03b5121a232e | 9384 | xmlNsPtr cloneNs = NULL, *cloneNsDefSlot = NULL; |
| pcercuei | 0:03b5121a232e | 9385 | xmlDictPtr dict; /* The destination dict */ |
| pcercuei | 0:03b5121a232e | 9386 | |
| pcercuei | 0:03b5121a232e | 9387 | if ((node == NULL) || (resNode == NULL) || (destDoc == NULL)) |
| pcercuei | 0:03b5121a232e | 9388 | return(-1); |
| pcercuei | 0:03b5121a232e | 9389 | /* |
| pcercuei | 0:03b5121a232e | 9390 | * TODO: Initially we support only element-nodes. |
| pcercuei | 0:03b5121a232e | 9391 | */ |
| pcercuei | 0:03b5121a232e | 9392 | if (node->type != XML_ELEMENT_NODE) |
| pcercuei | 0:03b5121a232e | 9393 | return(1); |
| pcercuei | 0:03b5121a232e | 9394 | /* |
| pcercuei | 0:03b5121a232e | 9395 | * Check node->doc sanity. |
| pcercuei | 0:03b5121a232e | 9396 | */ |
| pcercuei | 0:03b5121a232e | 9397 | if ((node->doc != NULL) && (sourceDoc != NULL) && |
| pcercuei | 0:03b5121a232e | 9398 | (node->doc != sourceDoc)) { |
| pcercuei | 0:03b5121a232e | 9399 | /* |
| pcercuei | 0:03b5121a232e | 9400 | * Might be an XIncluded node. |
| pcercuei | 0:03b5121a232e | 9401 | */ |
| pcercuei | 0:03b5121a232e | 9402 | return (-1); |
| pcercuei | 0:03b5121a232e | 9403 | } |
| pcercuei | 0:03b5121a232e | 9404 | if (sourceDoc == NULL) |
| pcercuei | 0:03b5121a232e | 9405 | sourceDoc = node->doc; |
| pcercuei | 0:03b5121a232e | 9406 | if (sourceDoc == NULL) |
| pcercuei | 0:03b5121a232e | 9407 | return (-1); |
| pcercuei | 0:03b5121a232e | 9408 | |
| pcercuei | 0:03b5121a232e | 9409 | dict = destDoc->dict; |
| pcercuei | 0:03b5121a232e | 9410 | /* |
| pcercuei | 0:03b5121a232e | 9411 | * Reuse the namespace map of the context. |
| pcercuei | 0:03b5121a232e | 9412 | */ |
| pcercuei | 0:03b5121a232e | 9413 | if (ctxt) |
| pcercuei | 0:03b5121a232e | 9414 | nsMap = (xmlNsMapPtr) ctxt->namespaceMap; |
| pcercuei | 0:03b5121a232e | 9415 | |
| pcercuei | 0:03b5121a232e | 9416 | *resNode = NULL; |
| pcercuei | 0:03b5121a232e | 9417 | |
| pcercuei | 0:03b5121a232e | 9418 | cur = node; |
| pcercuei | 0:03b5121a232e | 9419 | if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) |
| pcercuei | 0:03b5121a232e | 9420 | return(-1); |
| pcercuei | 0:03b5121a232e | 9421 | |
| pcercuei | 0:03b5121a232e | 9422 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 9423 | if (cur->doc != sourceDoc) { |
| pcercuei | 0:03b5121a232e | 9424 | /* |
| pcercuei | 0:03b5121a232e | 9425 | * We'll assume XIncluded nodes if the doc differs. |
| pcercuei | 0:03b5121a232e | 9426 | * TODO: Do we need to reconciliate XIncluded nodes? |
| pcercuei | 0:03b5121a232e | 9427 | * TODO: This here returns -1 in this case. |
| pcercuei | 0:03b5121a232e | 9428 | */ |
| pcercuei | 0:03b5121a232e | 9429 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9430 | } |
| pcercuei | 0:03b5121a232e | 9431 | /* |
| pcercuei | 0:03b5121a232e | 9432 | * Create a new node. |
| pcercuei | 0:03b5121a232e | 9433 | */ |
| pcercuei | 0:03b5121a232e | 9434 | switch (cur->type) { |
| pcercuei | 0:03b5121a232e | 9435 | case XML_XINCLUDE_START: |
| pcercuei | 0:03b5121a232e | 9436 | case XML_XINCLUDE_END: |
| pcercuei | 0:03b5121a232e | 9437 | /* |
| pcercuei | 0:03b5121a232e | 9438 | * TODO: What to do with XInclude? |
| pcercuei | 0:03b5121a232e | 9439 | */ |
| pcercuei | 0:03b5121a232e | 9440 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9441 | break; |
| pcercuei | 0:03b5121a232e | 9442 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 9443 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 9444 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 9445 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 9446 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 9447 | case XML_DOCUMENT_FRAG_NODE: |
| pcercuei | 0:03b5121a232e | 9448 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 9449 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 9450 | /* |
| pcercuei | 0:03b5121a232e | 9451 | * Nodes of xmlNode structure. |
| pcercuei | 0:03b5121a232e | 9452 | */ |
| pcercuei | 0:03b5121a232e | 9453 | clone = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 9454 | if (clone == NULL) { |
| pcercuei | 0:03b5121a232e | 9455 | xmlTreeErrMemory("xmlDOMWrapCloneNode(): allocating a node"); |
| pcercuei | 0:03b5121a232e | 9456 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9457 | } |
| pcercuei | 0:03b5121a232e | 9458 | memset(clone, 0, sizeof(xmlNode)); |
| pcercuei | 0:03b5121a232e | 9459 | /* |
| pcercuei | 0:03b5121a232e | 9460 | * Set hierachical links. |
| pcercuei | 0:03b5121a232e | 9461 | */ |
| pcercuei | 0:03b5121a232e | 9462 | if (resultClone != NULL) { |
| pcercuei | 0:03b5121a232e | 9463 | clone->parent = parentClone; |
| pcercuei | 0:03b5121a232e | 9464 | if (prevClone) { |
| pcercuei | 0:03b5121a232e | 9465 | prevClone->next = clone; |
| pcercuei | 0:03b5121a232e | 9466 | clone->prev = prevClone; |
| pcercuei | 0:03b5121a232e | 9467 | } else |
| pcercuei | 0:03b5121a232e | 9468 | parentClone->children = clone; |
| pcercuei | 0:03b5121a232e | 9469 | } else |
| pcercuei | 0:03b5121a232e | 9470 | resultClone = clone; |
| pcercuei | 0:03b5121a232e | 9471 | |
| pcercuei | 0:03b5121a232e | 9472 | break; |
| pcercuei | 0:03b5121a232e | 9473 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 9474 | /* |
| pcercuei | 0:03b5121a232e | 9475 | * Attributes (xmlAttr). |
| pcercuei | 0:03b5121a232e | 9476 | */ |
| pcercuei | 0:03b5121a232e | 9477 | clone = (xmlNodePtr) xmlMalloc(sizeof(xmlAttr)); |
| pcercuei | 0:03b5121a232e | 9478 | if (clone == NULL) { |
| pcercuei | 0:03b5121a232e | 9479 | xmlTreeErrMemory("xmlDOMWrapCloneNode(): allocating an attr-node"); |
| pcercuei | 0:03b5121a232e | 9480 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9481 | } |
| pcercuei | 0:03b5121a232e | 9482 | memset(clone, 0, sizeof(xmlAttr)); |
| pcercuei | 0:03b5121a232e | 9483 | /* |
| pcercuei | 0:03b5121a232e | 9484 | * Set hierachical links. |
| pcercuei | 0:03b5121a232e | 9485 | * TODO: Change this to add to the end of attributes. |
| pcercuei | 0:03b5121a232e | 9486 | */ |
| pcercuei | 0:03b5121a232e | 9487 | if (resultClone != NULL) { |
| pcercuei | 0:03b5121a232e | 9488 | clone->parent = parentClone; |
| pcercuei | 0:03b5121a232e | 9489 | if (prevClone) { |
| pcercuei | 0:03b5121a232e | 9490 | prevClone->next = clone; |
| pcercuei | 0:03b5121a232e | 9491 | clone->prev = prevClone; |
| pcercuei | 0:03b5121a232e | 9492 | } else |
| pcercuei | 0:03b5121a232e | 9493 | parentClone->properties = (xmlAttrPtr) clone; |
| pcercuei | 0:03b5121a232e | 9494 | } else |
| pcercuei | 0:03b5121a232e | 9495 | resultClone = clone; |
| pcercuei | 0:03b5121a232e | 9496 | break; |
| pcercuei | 0:03b5121a232e | 9497 | default: |
| pcercuei | 0:03b5121a232e | 9498 | /* |
| pcercuei | 0:03b5121a232e | 9499 | * TODO QUESTION: Any other nodes expected? |
| pcercuei | 0:03b5121a232e | 9500 | */ |
| pcercuei | 0:03b5121a232e | 9501 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9502 | } |
| pcercuei | 0:03b5121a232e | 9503 | |
| pcercuei | 0:03b5121a232e | 9504 | clone->type = cur->type; |
| pcercuei | 0:03b5121a232e | 9505 | clone->doc = destDoc; |
| pcercuei | 0:03b5121a232e | 9506 | |
| pcercuei | 0:03b5121a232e | 9507 | /* |
| pcercuei | 0:03b5121a232e | 9508 | * Clone the name of the node if any. |
| pcercuei | 0:03b5121a232e | 9509 | */ |
| pcercuei | 0:03b5121a232e | 9510 | if (cur->name == xmlStringText) |
| pcercuei | 0:03b5121a232e | 9511 | clone->name = xmlStringText; |
| pcercuei | 0:03b5121a232e | 9512 | else if (cur->name == xmlStringTextNoenc) |
| pcercuei | 0:03b5121a232e | 9513 | /* |
| pcercuei | 0:03b5121a232e | 9514 | * NOTE: Although xmlStringTextNoenc is never assigned to a node |
| pcercuei | 0:03b5121a232e | 9515 | * in tree.c, it might be set in Libxslt via |
| pcercuei | 0:03b5121a232e | 9516 | * "xsl:disable-output-escaping". |
| pcercuei | 0:03b5121a232e | 9517 | */ |
| pcercuei | 0:03b5121a232e | 9518 | clone->name = xmlStringTextNoenc; |
| pcercuei | 0:03b5121a232e | 9519 | else if (cur->name == xmlStringComment) |
| pcercuei | 0:03b5121a232e | 9520 | clone->name = xmlStringComment; |
| pcercuei | 0:03b5121a232e | 9521 | else if (cur->name != NULL) { |
| pcercuei | 0:03b5121a232e | 9522 | DICT_CONST_COPY(cur->name, clone->name); |
| pcercuei | 0:03b5121a232e | 9523 | } |
| pcercuei | 0:03b5121a232e | 9524 | |
| pcercuei | 0:03b5121a232e | 9525 | switch (cur->type) { |
| pcercuei | 0:03b5121a232e | 9526 | case XML_XINCLUDE_START: |
| pcercuei | 0:03b5121a232e | 9527 | case XML_XINCLUDE_END: |
| pcercuei | 0:03b5121a232e | 9528 | /* |
| pcercuei | 0:03b5121a232e | 9529 | * TODO |
| pcercuei | 0:03b5121a232e | 9530 | */ |
| pcercuei | 0:03b5121a232e | 9531 | return (-1); |
| pcercuei | 0:03b5121a232e | 9532 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 9533 | curElem = cur; |
| pcercuei | 0:03b5121a232e | 9534 | depth++; |
| pcercuei | 0:03b5121a232e | 9535 | /* |
| pcercuei | 0:03b5121a232e | 9536 | * Namespace declarations. |
| pcercuei | 0:03b5121a232e | 9537 | */ |
| pcercuei | 0:03b5121a232e | 9538 | if (cur->nsDef != NULL) { |
| pcercuei | 0:03b5121a232e | 9539 | if (! parnsdone) { |
| pcercuei | 0:03b5121a232e | 9540 | if (destParent && (ctxt == NULL)) { |
| pcercuei | 0:03b5121a232e | 9541 | /* |
| pcercuei | 0:03b5121a232e | 9542 | * Gather @parent's in-scope ns-decls. |
| pcercuei | 0:03b5121a232e | 9543 | */ |
| pcercuei | 0:03b5121a232e | 9544 | if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, |
| pcercuei | 0:03b5121a232e | 9545 | destParent) == -1) |
| pcercuei | 0:03b5121a232e | 9546 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9547 | } |
| pcercuei | 0:03b5121a232e | 9548 | parnsdone = 1; |
| pcercuei | 0:03b5121a232e | 9549 | } |
| pcercuei | 0:03b5121a232e | 9550 | /* |
| pcercuei | 0:03b5121a232e | 9551 | * Clone namespace declarations. |
| pcercuei | 0:03b5121a232e | 9552 | */ |
| pcercuei | 0:03b5121a232e | 9553 | cloneNsDefSlot = &(clone->nsDef); |
| pcercuei | 0:03b5121a232e | 9554 | for (ns = cur->nsDef; ns != NULL; ns = ns->next) { |
| pcercuei | 0:03b5121a232e | 9555 | /* |
| pcercuei | 0:03b5121a232e | 9556 | * Create a new xmlNs. |
| pcercuei | 0:03b5121a232e | 9557 | */ |
| pcercuei | 0:03b5121a232e | 9558 | cloneNs = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); |
| pcercuei | 0:03b5121a232e | 9559 | if (cloneNs == NULL) { |
| pcercuei | 0:03b5121a232e | 9560 | xmlTreeErrMemory("xmlDOMWrapCloneNode(): " |
| pcercuei | 0:03b5121a232e | 9561 | "allocating namespace"); |
| pcercuei | 0:03b5121a232e | 9562 | return(-1); |
| pcercuei | 0:03b5121a232e | 9563 | } |
| pcercuei | 0:03b5121a232e | 9564 | memset(cloneNs, 0, sizeof(xmlNs)); |
| pcercuei | 0:03b5121a232e | 9565 | cloneNs->type = XML_LOCAL_NAMESPACE; |
| pcercuei | 0:03b5121a232e | 9566 | |
| pcercuei | 0:03b5121a232e | 9567 | if (ns->href != NULL) |
| pcercuei | 0:03b5121a232e | 9568 | cloneNs->href = xmlStrdup(ns->href); |
| pcercuei | 0:03b5121a232e | 9569 | if (ns->prefix != NULL) |
| pcercuei | 0:03b5121a232e | 9570 | cloneNs->prefix = xmlStrdup(ns->prefix); |
| pcercuei | 0:03b5121a232e | 9571 | |
| pcercuei | 0:03b5121a232e | 9572 | *cloneNsDefSlot = cloneNs; |
| pcercuei | 0:03b5121a232e | 9573 | cloneNsDefSlot = &(cloneNs->next); |
| pcercuei | 0:03b5121a232e | 9574 | |
| pcercuei | 0:03b5121a232e | 9575 | /* |
| pcercuei | 0:03b5121a232e | 9576 | * Note that for custom handling of ns-references, |
| pcercuei | 0:03b5121a232e | 9577 | * the ns-decls need not be stored in the ns-map, |
| pcercuei | 0:03b5121a232e | 9578 | * since they won't be referenced by node->ns. |
| pcercuei | 0:03b5121a232e | 9579 | */ |
| pcercuei | 0:03b5121a232e | 9580 | if ((ctxt == NULL) || |
| pcercuei | 0:03b5121a232e | 9581 | (ctxt->getNsForNodeFunc == NULL)) |
| pcercuei | 0:03b5121a232e | 9582 | { |
| pcercuei | 0:03b5121a232e | 9583 | /* |
| pcercuei | 0:03b5121a232e | 9584 | * Does it shadow any ns-decl? |
| pcercuei | 0:03b5121a232e | 9585 | */ |
| pcercuei | 0:03b5121a232e | 9586 | if (XML_NSMAP_NOTEMPTY(nsMap)) { |
| pcercuei | 0:03b5121a232e | 9587 | XML_NSMAP_FOREACH(nsMap, mi) { |
| pcercuei | 0:03b5121a232e | 9588 | if ((mi->depth >= XML_TREE_NSMAP_PARENT) && |
| pcercuei | 0:03b5121a232e | 9589 | (mi->shadowDepth == -1) && |
| pcercuei | 0:03b5121a232e | 9590 | ((ns->prefix == mi->newNs->prefix) || |
| pcercuei | 0:03b5121a232e | 9591 | xmlStrEqual(ns->prefix, |
| pcercuei | 0:03b5121a232e | 9592 | mi->newNs->prefix))) { |
| pcercuei | 0:03b5121a232e | 9593 | /* |
| pcercuei | 0:03b5121a232e | 9594 | * Mark as shadowed at the current |
| pcercuei | 0:03b5121a232e | 9595 | * depth. |
| pcercuei | 0:03b5121a232e | 9596 | */ |
| pcercuei | 0:03b5121a232e | 9597 | mi->shadowDepth = depth; |
| pcercuei | 0:03b5121a232e | 9598 | } |
| pcercuei | 0:03b5121a232e | 9599 | } |
| pcercuei | 0:03b5121a232e | 9600 | } |
| pcercuei | 0:03b5121a232e | 9601 | /* |
| pcercuei | 0:03b5121a232e | 9602 | * Push mapping. |
| pcercuei | 0:03b5121a232e | 9603 | */ |
| pcercuei | 0:03b5121a232e | 9604 | if (xmlDOMWrapNsMapAddItem(&nsMap, -1, |
| pcercuei | 0:03b5121a232e | 9605 | ns, cloneNs, depth) == NULL) |
| pcercuei | 0:03b5121a232e | 9606 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9607 | } |
| pcercuei | 0:03b5121a232e | 9608 | } |
| pcercuei | 0:03b5121a232e | 9609 | } |
| pcercuei | 0:03b5121a232e | 9610 | /* cur->ns will be processed further down. */ |
| pcercuei | 0:03b5121a232e | 9611 | break; |
| pcercuei | 0:03b5121a232e | 9612 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 9613 | /* IDs will be processed further down. */ |
| pcercuei | 0:03b5121a232e | 9614 | /* cur->ns will be processed further down. */ |
| pcercuei | 0:03b5121a232e | 9615 | break; |
| pcercuei | 0:03b5121a232e | 9616 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 9617 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 9618 | /* |
| pcercuei | 0:03b5121a232e | 9619 | * Note that this will also cover the values of attributes. |
| pcercuei | 0:03b5121a232e | 9620 | */ |
| pcercuei | 0:03b5121a232e | 9621 | DICT_COPY(cur->content, clone->content); |
| pcercuei | 0:03b5121a232e | 9622 | goto leave_node; |
| pcercuei | 0:03b5121a232e | 9623 | case XML_ENTITY_NODE: |
| pcercuei | 0:03b5121a232e | 9624 | /* TODO: What to do here? */ |
| pcercuei | 0:03b5121a232e | 9625 | goto leave_node; |
| pcercuei | 0:03b5121a232e | 9626 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 9627 | if (sourceDoc != destDoc) { |
| pcercuei | 0:03b5121a232e | 9628 | if ((destDoc->intSubset) || (destDoc->extSubset)) { |
| pcercuei | 0:03b5121a232e | 9629 | xmlEntityPtr ent; |
| pcercuei | 0:03b5121a232e | 9630 | /* |
| pcercuei | 0:03b5121a232e | 9631 | * Different doc: Assign new entity-node if available. |
| pcercuei | 0:03b5121a232e | 9632 | */ |
| pcercuei | 0:03b5121a232e | 9633 | ent = xmlGetDocEntity(destDoc, cur->name); |
| pcercuei | 0:03b5121a232e | 9634 | if (ent != NULL) { |
| pcercuei | 0:03b5121a232e | 9635 | clone->content = ent->content; |
| pcercuei | 0:03b5121a232e | 9636 | clone->children = (xmlNodePtr) ent; |
| pcercuei | 0:03b5121a232e | 9637 | clone->last = (xmlNodePtr) ent; |
| pcercuei | 0:03b5121a232e | 9638 | } |
| pcercuei | 0:03b5121a232e | 9639 | } |
| pcercuei | 0:03b5121a232e | 9640 | } else { |
| pcercuei | 0:03b5121a232e | 9641 | /* |
| pcercuei | 0:03b5121a232e | 9642 | * Same doc: Use the current node's entity declaration |
| pcercuei | 0:03b5121a232e | 9643 | * and value. |
| pcercuei | 0:03b5121a232e | 9644 | */ |
| pcercuei | 0:03b5121a232e | 9645 | clone->content = cur->content; |
| pcercuei | 0:03b5121a232e | 9646 | clone->children = cur->children; |
| pcercuei | 0:03b5121a232e | 9647 | clone->last = cur->last; |
| pcercuei | 0:03b5121a232e | 9648 | } |
| pcercuei | 0:03b5121a232e | 9649 | goto leave_node; |
| pcercuei | 0:03b5121a232e | 9650 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 9651 | DICT_COPY(cur->content, clone->content); |
| pcercuei | 0:03b5121a232e | 9652 | goto leave_node; |
| pcercuei | 0:03b5121a232e | 9653 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 9654 | DICT_COPY(cur->content, clone->content); |
| pcercuei | 0:03b5121a232e | 9655 | goto leave_node; |
| pcercuei | 0:03b5121a232e | 9656 | default: |
| pcercuei | 0:03b5121a232e | 9657 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9658 | } |
| pcercuei | 0:03b5121a232e | 9659 | |
| pcercuei | 0:03b5121a232e | 9660 | if (cur->ns == NULL) |
| pcercuei | 0:03b5121a232e | 9661 | goto end_ns_reference; |
| pcercuei | 0:03b5121a232e | 9662 | |
| pcercuei | 0:03b5121a232e | 9663 | /* handle_ns_reference: */ |
| pcercuei | 0:03b5121a232e | 9664 | /* |
| pcercuei | 0:03b5121a232e | 9665 | ** The following will take care of references to ns-decls ******** |
| pcercuei | 0:03b5121a232e | 9666 | ** and is intended only for element- and attribute-nodes. |
| pcercuei | 0:03b5121a232e | 9667 | ** |
| pcercuei | 0:03b5121a232e | 9668 | */ |
| pcercuei | 0:03b5121a232e | 9669 | if (! parnsdone) { |
| pcercuei | 0:03b5121a232e | 9670 | if (destParent && (ctxt == NULL)) { |
| pcercuei | 0:03b5121a232e | 9671 | if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, destParent) == -1) |
| pcercuei | 0:03b5121a232e | 9672 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9673 | } |
| pcercuei | 0:03b5121a232e | 9674 | parnsdone = 1; |
| pcercuei | 0:03b5121a232e | 9675 | } |
| pcercuei | 0:03b5121a232e | 9676 | /* |
| pcercuei | 0:03b5121a232e | 9677 | * Adopt ns-references. |
| pcercuei | 0:03b5121a232e | 9678 | */ |
| pcercuei | 0:03b5121a232e | 9679 | if (XML_NSMAP_NOTEMPTY(nsMap)) { |
| pcercuei | 0:03b5121a232e | 9680 | /* |
| pcercuei | 0:03b5121a232e | 9681 | * Search for a mapping. |
| pcercuei | 0:03b5121a232e | 9682 | */ |
| pcercuei | 0:03b5121a232e | 9683 | XML_NSMAP_FOREACH(nsMap, mi) { |
| pcercuei | 0:03b5121a232e | 9684 | if ((mi->shadowDepth == -1) && |
| pcercuei | 0:03b5121a232e | 9685 | (cur->ns == mi->oldNs)) { |
| pcercuei | 0:03b5121a232e | 9686 | /* |
| pcercuei | 0:03b5121a232e | 9687 | * This is the nice case: a mapping was found. |
| pcercuei | 0:03b5121a232e | 9688 | */ |
| pcercuei | 0:03b5121a232e | 9689 | clone->ns = mi->newNs; |
| pcercuei | 0:03b5121a232e | 9690 | goto end_ns_reference; |
| pcercuei | 0:03b5121a232e | 9691 | } |
| pcercuei | 0:03b5121a232e | 9692 | } |
| pcercuei | 0:03b5121a232e | 9693 | } |
| pcercuei | 0:03b5121a232e | 9694 | /* |
| pcercuei | 0:03b5121a232e | 9695 | * No matching namespace in scope. We need a new one. |
| pcercuei | 0:03b5121a232e | 9696 | */ |
| pcercuei | 0:03b5121a232e | 9697 | if ((ctxt != NULL) && (ctxt->getNsForNodeFunc != NULL)) { |
| pcercuei | 0:03b5121a232e | 9698 | /* |
| pcercuei | 0:03b5121a232e | 9699 | * User-defined behaviour. |
| pcercuei | 0:03b5121a232e | 9700 | */ |
| pcercuei | 0:03b5121a232e | 9701 | ns = ctxt->getNsForNodeFunc(ctxt, cur, |
| pcercuei | 0:03b5121a232e | 9702 | cur->ns->href, cur->ns->prefix); |
| pcercuei | 0:03b5121a232e | 9703 | /* |
| pcercuei | 0:03b5121a232e | 9704 | * Add user's mapping. |
| pcercuei | 0:03b5121a232e | 9705 | */ |
| pcercuei | 0:03b5121a232e | 9706 | if (xmlDOMWrapNsMapAddItem(&nsMap, -1, |
| pcercuei | 0:03b5121a232e | 9707 | cur->ns, ns, XML_TREE_NSMAP_CUSTOM) == NULL) |
| pcercuei | 0:03b5121a232e | 9708 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9709 | clone->ns = ns; |
| pcercuei | 0:03b5121a232e | 9710 | } else { |
| pcercuei | 0:03b5121a232e | 9711 | /* |
| pcercuei | 0:03b5121a232e | 9712 | * Aquire a normalized ns-decl and add it to the map. |
| pcercuei | 0:03b5121a232e | 9713 | */ |
| pcercuei | 0:03b5121a232e | 9714 | if (xmlDOMWrapNSNormAquireNormalizedNs(destDoc, |
| pcercuei | 0:03b5121a232e | 9715 | /* ns-decls on curElem or on destDoc->oldNs */ |
| pcercuei | 0:03b5121a232e | 9716 | destParent ? curElem : NULL, |
| pcercuei | 0:03b5121a232e | 9717 | cur->ns, &ns, |
| pcercuei | 0:03b5121a232e | 9718 | &nsMap, depth, |
| pcercuei | 0:03b5121a232e | 9719 | /* if we need to search only in the ancestor-axis */ |
| pcercuei | 0:03b5121a232e | 9720 | ancestorsOnly, |
| pcercuei | 0:03b5121a232e | 9721 | /* ns-decls must be prefixed for attributes. */ |
| pcercuei | 0:03b5121a232e | 9722 | (cur->type == XML_ATTRIBUTE_NODE) ? 1 : 0) == -1) |
| pcercuei | 0:03b5121a232e | 9723 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9724 | clone->ns = ns; |
| pcercuei | 0:03b5121a232e | 9725 | } |
| pcercuei | 0:03b5121a232e | 9726 | |
| pcercuei | 0:03b5121a232e | 9727 | end_ns_reference: |
| pcercuei | 0:03b5121a232e | 9728 | |
| pcercuei | 0:03b5121a232e | 9729 | /* |
| pcercuei | 0:03b5121a232e | 9730 | * Some post-processing. |
| pcercuei | 0:03b5121a232e | 9731 | * |
| pcercuei | 0:03b5121a232e | 9732 | * Handle ID attributes. |
| pcercuei | 0:03b5121a232e | 9733 | */ |
| pcercuei | 0:03b5121a232e | 9734 | if ((clone->type == XML_ATTRIBUTE_NODE) && |
| pcercuei | 0:03b5121a232e | 9735 | (clone->parent != NULL)) |
| pcercuei | 0:03b5121a232e | 9736 | { |
| pcercuei | 0:03b5121a232e | 9737 | if (xmlIsID(destDoc, clone->parent, (xmlAttrPtr) clone)) { |
| pcercuei | 0:03b5121a232e | 9738 | |
| pcercuei | 0:03b5121a232e | 9739 | xmlChar *idVal; |
| pcercuei | 0:03b5121a232e | 9740 | |
| pcercuei | 0:03b5121a232e | 9741 | idVal = xmlNodeListGetString(cur->doc, cur->children, 1); |
| pcercuei | 0:03b5121a232e | 9742 | if (idVal != NULL) { |
| pcercuei | 0:03b5121a232e | 9743 | if (xmlAddID(NULL, destDoc, idVal, (xmlAttrPtr) cur) == NULL) { |
| pcercuei | 0:03b5121a232e | 9744 | /* TODO: error message. */ |
| pcercuei | 0:03b5121a232e | 9745 | xmlFree(idVal); |
| pcercuei | 0:03b5121a232e | 9746 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9747 | } |
| pcercuei | 0:03b5121a232e | 9748 | xmlFree(idVal); |
| pcercuei | 0:03b5121a232e | 9749 | } |
| pcercuei | 0:03b5121a232e | 9750 | } |
| pcercuei | 0:03b5121a232e | 9751 | } |
| pcercuei | 0:03b5121a232e | 9752 | /* |
| pcercuei | 0:03b5121a232e | 9753 | ** |
| pcercuei | 0:03b5121a232e | 9754 | ** The following will traverse the tree ************************** |
| pcercuei | 0:03b5121a232e | 9755 | ** |
| pcercuei | 0:03b5121a232e | 9756 | * |
| pcercuei | 0:03b5121a232e | 9757 | * Walk the element's attributes before descending into child-nodes. |
| pcercuei | 0:03b5121a232e | 9758 | */ |
| pcercuei | 0:03b5121a232e | 9759 | if ((cur->type == XML_ELEMENT_NODE) && (cur->properties != NULL)) { |
| pcercuei | 0:03b5121a232e | 9760 | prevClone = NULL; |
| pcercuei | 0:03b5121a232e | 9761 | parentClone = clone; |
| pcercuei | 0:03b5121a232e | 9762 | cur = (xmlNodePtr) cur->properties; |
| pcercuei | 0:03b5121a232e | 9763 | continue; |
| pcercuei | 0:03b5121a232e | 9764 | } |
| pcercuei | 0:03b5121a232e | 9765 | into_content: |
| pcercuei | 0:03b5121a232e | 9766 | /* |
| pcercuei | 0:03b5121a232e | 9767 | * Descend into child-nodes. |
| pcercuei | 0:03b5121a232e | 9768 | */ |
| pcercuei | 0:03b5121a232e | 9769 | if (cur->children != NULL) { |
| pcercuei | 0:03b5121a232e | 9770 | if (deep || (cur->type == XML_ATTRIBUTE_NODE)) { |
| pcercuei | 0:03b5121a232e | 9771 | prevClone = NULL; |
| pcercuei | 0:03b5121a232e | 9772 | parentClone = clone; |
| pcercuei | 0:03b5121a232e | 9773 | cur = cur->children; |
| pcercuei | 0:03b5121a232e | 9774 | continue; |
| pcercuei | 0:03b5121a232e | 9775 | } |
| pcercuei | 0:03b5121a232e | 9776 | } |
| pcercuei | 0:03b5121a232e | 9777 | |
| pcercuei | 0:03b5121a232e | 9778 | leave_node: |
| pcercuei | 0:03b5121a232e | 9779 | /* |
| pcercuei | 0:03b5121a232e | 9780 | * At this point we are done with the node, its content |
| pcercuei | 0:03b5121a232e | 9781 | * and an element-nodes's attribute-nodes. |
| pcercuei | 0:03b5121a232e | 9782 | */ |
| pcercuei | 0:03b5121a232e | 9783 | if (cur == node) |
| pcercuei | 0:03b5121a232e | 9784 | break; |
| pcercuei | 0:03b5121a232e | 9785 | if ((cur->type == XML_ELEMENT_NODE) || |
| pcercuei | 0:03b5121a232e | 9786 | (cur->type == XML_XINCLUDE_START) || |
| pcercuei | 0:03b5121a232e | 9787 | (cur->type == XML_XINCLUDE_END)) { |
| pcercuei | 0:03b5121a232e | 9788 | /* |
| pcercuei | 0:03b5121a232e | 9789 | * TODO: Do we expect nsDefs on XML_XINCLUDE_START? |
| pcercuei | 0:03b5121a232e | 9790 | */ |
| pcercuei | 0:03b5121a232e | 9791 | if (XML_NSMAP_NOTEMPTY(nsMap)) { |
| pcercuei | 0:03b5121a232e | 9792 | /* |
| pcercuei | 0:03b5121a232e | 9793 | * Pop mappings. |
| pcercuei | 0:03b5121a232e | 9794 | */ |
| pcercuei | 0:03b5121a232e | 9795 | while ((nsMap->last != NULL) && |
| pcercuei | 0:03b5121a232e | 9796 | (nsMap->last->depth >= depth)) |
| pcercuei | 0:03b5121a232e | 9797 | { |
| pcercuei | 0:03b5121a232e | 9798 | XML_NSMAP_POP(nsMap, mi) |
| pcercuei | 0:03b5121a232e | 9799 | } |
| pcercuei | 0:03b5121a232e | 9800 | /* |
| pcercuei | 0:03b5121a232e | 9801 | * Unshadow. |
| pcercuei | 0:03b5121a232e | 9802 | */ |
| pcercuei | 0:03b5121a232e | 9803 | XML_NSMAP_FOREACH(nsMap, mi) { |
| pcercuei | 0:03b5121a232e | 9804 | if (mi->shadowDepth >= depth) |
| pcercuei | 0:03b5121a232e | 9805 | mi->shadowDepth = -1; |
| pcercuei | 0:03b5121a232e | 9806 | } |
| pcercuei | 0:03b5121a232e | 9807 | } |
| pcercuei | 0:03b5121a232e | 9808 | depth--; |
| pcercuei | 0:03b5121a232e | 9809 | } |
| pcercuei | 0:03b5121a232e | 9810 | if (cur->next != NULL) { |
| pcercuei | 0:03b5121a232e | 9811 | prevClone = clone; |
| pcercuei | 0:03b5121a232e | 9812 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 9813 | } else if (cur->type != XML_ATTRIBUTE_NODE) { |
| pcercuei | 0:03b5121a232e | 9814 | /* |
| pcercuei | 0:03b5121a232e | 9815 | * Set clone->last. |
| pcercuei | 0:03b5121a232e | 9816 | */ |
| pcercuei | 0:03b5121a232e | 9817 | if (clone->parent != NULL) |
| pcercuei | 0:03b5121a232e | 9818 | clone->parent->last = clone; |
| pcercuei | 0:03b5121a232e | 9819 | clone = clone->parent; |
| pcercuei | 0:03b5121a232e | 9820 | if (clone != NULL) |
| pcercuei | 0:03b5121a232e | 9821 | parentClone = clone->parent; |
| pcercuei | 0:03b5121a232e | 9822 | /* |
| pcercuei | 0:03b5121a232e | 9823 | * Process parent --> next; |
| pcercuei | 0:03b5121a232e | 9824 | */ |
| pcercuei | 0:03b5121a232e | 9825 | cur = cur->parent; |
| pcercuei | 0:03b5121a232e | 9826 | goto leave_node; |
| pcercuei | 0:03b5121a232e | 9827 | } else { |
| pcercuei | 0:03b5121a232e | 9828 | /* This is for attributes only. */ |
| pcercuei | 0:03b5121a232e | 9829 | clone = clone->parent; |
| pcercuei | 0:03b5121a232e | 9830 | parentClone = clone->parent; |
| pcercuei | 0:03b5121a232e | 9831 | /* |
| pcercuei | 0:03b5121a232e | 9832 | * Process parent-element --> children. |
| pcercuei | 0:03b5121a232e | 9833 | */ |
| pcercuei | 0:03b5121a232e | 9834 | cur = cur->parent; |
| pcercuei | 0:03b5121a232e | 9835 | goto into_content; |
| pcercuei | 0:03b5121a232e | 9836 | } |
| pcercuei | 0:03b5121a232e | 9837 | } |
| pcercuei | 0:03b5121a232e | 9838 | goto exit; |
| pcercuei | 0:03b5121a232e | 9839 | |
| pcercuei | 0:03b5121a232e | 9840 | internal_error: |
| pcercuei | 0:03b5121a232e | 9841 | ret = -1; |
| pcercuei | 0:03b5121a232e | 9842 | |
| pcercuei | 0:03b5121a232e | 9843 | exit: |
| pcercuei | 0:03b5121a232e | 9844 | /* |
| pcercuei | 0:03b5121a232e | 9845 | * Cleanup. |
| pcercuei | 0:03b5121a232e | 9846 | */ |
| pcercuei | 0:03b5121a232e | 9847 | if (nsMap != NULL) { |
| pcercuei | 0:03b5121a232e | 9848 | if ((ctxt) && (ctxt->namespaceMap == nsMap)) { |
| pcercuei | 0:03b5121a232e | 9849 | /* |
| pcercuei | 0:03b5121a232e | 9850 | * Just cleanup the map but don't free. |
| pcercuei | 0:03b5121a232e | 9851 | */ |
| pcercuei | 0:03b5121a232e | 9852 | if (nsMap->first) { |
| pcercuei | 0:03b5121a232e | 9853 | if (nsMap->pool) |
| pcercuei | 0:03b5121a232e | 9854 | nsMap->last->next = nsMap->pool; |
| pcercuei | 0:03b5121a232e | 9855 | nsMap->pool = nsMap->first; |
| pcercuei | 0:03b5121a232e | 9856 | nsMap->first = NULL; |
| pcercuei | 0:03b5121a232e | 9857 | } |
| pcercuei | 0:03b5121a232e | 9858 | } else |
| pcercuei | 0:03b5121a232e | 9859 | xmlDOMWrapNsMapFree(nsMap); |
| pcercuei | 0:03b5121a232e | 9860 | } |
| pcercuei | 0:03b5121a232e | 9861 | /* |
| pcercuei | 0:03b5121a232e | 9862 | * TODO: Should we try a cleanup of the cloned node in case of a |
| pcercuei | 0:03b5121a232e | 9863 | * fatal error? |
| pcercuei | 0:03b5121a232e | 9864 | */ |
| pcercuei | 0:03b5121a232e | 9865 | *resNode = resultClone; |
| pcercuei | 0:03b5121a232e | 9866 | return (ret); |
| pcercuei | 0:03b5121a232e | 9867 | } |
| pcercuei | 0:03b5121a232e | 9868 | |
| pcercuei | 0:03b5121a232e | 9869 | /* |
| pcercuei | 0:03b5121a232e | 9870 | * xmlDOMWrapAdoptAttr: |
| pcercuei | 0:03b5121a232e | 9871 | * @ctxt: the optional context for custom processing |
| pcercuei | 0:03b5121a232e | 9872 | * @sourceDoc: the optional source document of attr |
| pcercuei | 0:03b5121a232e | 9873 | * @attr: the attribute-node to be adopted |
| pcercuei | 0:03b5121a232e | 9874 | * @destDoc: the destination doc for adoption |
| pcercuei | 0:03b5121a232e | 9875 | * @destParent: the optional new parent of @attr in @destDoc |
| pcercuei | 0:03b5121a232e | 9876 | * @options: option flags |
| pcercuei | 0:03b5121a232e | 9877 | * |
| pcercuei | 0:03b5121a232e | 9878 | * @attr is adopted by @destDoc. |
| pcercuei | 0:03b5121a232e | 9879 | * Ensures that ns-references point to @destDoc: either to |
| pcercuei | 0:03b5121a232e | 9880 | * elements->nsDef entries if @destParent is given, or to |
| pcercuei | 0:03b5121a232e | 9881 | * @destDoc->oldNs otherwise. |
| pcercuei | 0:03b5121a232e | 9882 | * |
| pcercuei | 0:03b5121a232e | 9883 | * Returns 0 if succeeded, -1 otherwise and on API/internal errors. |
| pcercuei | 0:03b5121a232e | 9884 | */ |
| pcercuei | 0:03b5121a232e | 9885 | static int |
| pcercuei | 0:03b5121a232e | 9886 | xmlDOMWrapAdoptAttr(xmlDOMWrapCtxtPtr ctxt, |
| pcercuei | 0:03b5121a232e | 9887 | xmlDocPtr sourceDoc, |
| pcercuei | 0:03b5121a232e | 9888 | xmlAttrPtr attr, |
| pcercuei | 0:03b5121a232e | 9889 | xmlDocPtr destDoc, |
| pcercuei | 0:03b5121a232e | 9890 | xmlNodePtr destParent, |
| pcercuei | 0:03b5121a232e | 9891 | int options ATTRIBUTE_UNUSED) |
| pcercuei | 0:03b5121a232e | 9892 | { |
| pcercuei | 0:03b5121a232e | 9893 | xmlNodePtr cur; |
| pcercuei | 0:03b5121a232e | 9894 | int adoptStr = 1; |
| pcercuei | 0:03b5121a232e | 9895 | |
| pcercuei | 0:03b5121a232e | 9896 | if ((attr == NULL) || (destDoc == NULL)) |
| pcercuei | 0:03b5121a232e | 9897 | return (-1); |
| pcercuei | 0:03b5121a232e | 9898 | |
| pcercuei | 0:03b5121a232e | 9899 | attr->doc = destDoc; |
| pcercuei | 0:03b5121a232e | 9900 | if (attr->ns != NULL) { |
| pcercuei | 0:03b5121a232e | 9901 | xmlNsPtr ns = NULL; |
| pcercuei | 0:03b5121a232e | 9902 | |
| pcercuei | 0:03b5121a232e | 9903 | if (ctxt != NULL) { |
| pcercuei | 0:03b5121a232e | 9904 | /* TODO: User defined. */ |
| pcercuei | 0:03b5121a232e | 9905 | } |
| pcercuei | 0:03b5121a232e | 9906 | /* XML Namespace. */ |
| pcercuei | 0:03b5121a232e | 9907 | if (IS_STR_XML(attr->ns->prefix)) { |
| pcercuei | 0:03b5121a232e | 9908 | ns = xmlTreeEnsureXMLDecl(destDoc); |
| pcercuei | 0:03b5121a232e | 9909 | } else if (destParent == NULL) { |
| pcercuei | 0:03b5121a232e | 9910 | /* |
| pcercuei | 0:03b5121a232e | 9911 | * Store in @destDoc->oldNs. |
| pcercuei | 0:03b5121a232e | 9912 | */ |
| pcercuei | 0:03b5121a232e | 9913 | ns = xmlDOMWrapStoreNs(destDoc, attr->ns->href, attr->ns->prefix); |
| pcercuei | 0:03b5121a232e | 9914 | } else { |
| pcercuei | 0:03b5121a232e | 9915 | /* |
| pcercuei | 0:03b5121a232e | 9916 | * Declare on @destParent. |
| pcercuei | 0:03b5121a232e | 9917 | */ |
| pcercuei | 0:03b5121a232e | 9918 | if (xmlSearchNsByNamespaceStrict(destDoc, destParent, attr->ns->href, |
| pcercuei | 0:03b5121a232e | 9919 | &ns, 1) == -1) |
| pcercuei | 0:03b5121a232e | 9920 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9921 | if (ns == NULL) { |
| pcercuei | 0:03b5121a232e | 9922 | ns = xmlDOMWrapNSNormDeclareNsForced(destDoc, destParent, |
| pcercuei | 0:03b5121a232e | 9923 | attr->ns->href, attr->ns->prefix, 1); |
| pcercuei | 0:03b5121a232e | 9924 | } |
| pcercuei | 0:03b5121a232e | 9925 | } |
| pcercuei | 0:03b5121a232e | 9926 | if (ns == NULL) |
| pcercuei | 0:03b5121a232e | 9927 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9928 | attr->ns = ns; |
| pcercuei | 0:03b5121a232e | 9929 | } |
| pcercuei | 0:03b5121a232e | 9930 | |
| pcercuei | 0:03b5121a232e | 9931 | XML_TREE_ADOPT_STR(attr->name); |
| pcercuei | 0:03b5121a232e | 9932 | attr->atype = 0; |
| pcercuei | 0:03b5121a232e | 9933 | attr->psvi = NULL; |
| pcercuei | 0:03b5121a232e | 9934 | /* |
| pcercuei | 0:03b5121a232e | 9935 | * Walk content. |
| pcercuei | 0:03b5121a232e | 9936 | */ |
| pcercuei | 0:03b5121a232e | 9937 | if (attr->children == NULL) |
| pcercuei | 0:03b5121a232e | 9938 | return (0); |
| pcercuei | 0:03b5121a232e | 9939 | cur = attr->children; |
| pcercuei | 0:03b5121a232e | 9940 | if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) |
| pcercuei | 0:03b5121a232e | 9941 | goto internal_error; |
| pcercuei | 0:03b5121a232e | 9942 | while (cur != NULL) { |
| pcercuei | 0:03b5121a232e | 9943 | cur->doc = destDoc; |
| pcercuei | 0:03b5121a232e | 9944 | switch (cur->type) { |
| pcercuei | 0:03b5121a232e | 9945 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 9946 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 9947 | XML_TREE_ADOPT_STR_2(cur->content) |
| pcercuei | 0:03b5121a232e | 9948 | break; |
| pcercuei | 0:03b5121a232e | 9949 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 9950 | /* |
| pcercuei | 0:03b5121a232e | 9951 | * Remove reference to the entitity-node. |
| pcercuei | 0:03b5121a232e | 9952 | */ |
| pcercuei | 0:03b5121a232e | 9953 | cur->content = NULL; |
| pcercuei | 0:03b5121a232e | 9954 | cur->children = NULL; |
| pcercuei | 0:03b5121a232e | 9955 | cur->last = NULL; |
| pcercuei | 0:03b5121a232e | 9956 | if ((destDoc->intSubset) || (destDoc->extSubset)) { |
| pcercuei | 0:03b5121a232e | 9957 | xmlEntityPtr ent; |
| pcercuei | 0:03b5121a232e | 9958 | /* |
| pcercuei | 0:03b5121a232e | 9959 | * Assign new entity-node if available. |
| pcercuei | 0:03b5121a232e | 9960 | */ |
| pcercuei | 0:03b5121a232e | 9961 | ent = xmlGetDocEntity(destDoc, cur->name); |
| pcercuei | 0:03b5121a232e | 9962 | if (ent != NULL) { |
| pcercuei | 0:03b5121a232e | 9963 | cur->content = ent->content; |
| pcercuei | 0:03b5121a232e | 9964 | cur->children = (xmlNodePtr) ent; |
| pcercuei | 0:03b5121a232e | 9965 | cur->last = (xmlNodePtr) ent; |
| pcercuei | 0:03b5121a232e | 9966 | } |
| pcercuei | 0:03b5121a232e | 9967 | } |
| pcercuei | 0:03b5121a232e | 9968 | break; |
| pcercuei | 0:03b5121a232e | 9969 | default: |
| pcercuei | 0:03b5121a232e | 9970 | break; |
| pcercuei | 0:03b5121a232e | 9971 | } |
| pcercuei | 0:03b5121a232e | 9972 | if (cur->children != NULL) { |
| pcercuei | 0:03b5121a232e | 9973 | cur = cur->children; |
| pcercuei | 0:03b5121a232e | 9974 | continue; |
| pcercuei | 0:03b5121a232e | 9975 | } |
| pcercuei | 0:03b5121a232e | 9976 | next_sibling: |
| pcercuei | 0:03b5121a232e | 9977 | if (cur == (xmlNodePtr) attr) |
| pcercuei | 0:03b5121a232e | 9978 | break; |
| pcercuei | 0:03b5121a232e | 9979 | if (cur->next != NULL) |
| pcercuei | 0:03b5121a232e | 9980 | cur = cur->next; |
| pcercuei | 0:03b5121a232e | 9981 | else { |
| pcercuei | 0:03b5121a232e | 9982 | cur = cur->parent; |
| pcercuei | 0:03b5121a232e | 9983 | goto next_sibling; |
| pcercuei | 0:03b5121a232e | 9984 | } |
| pcercuei | 0:03b5121a232e | 9985 | } |
| pcercuei | 0:03b5121a232e | 9986 | return (0); |
| pcercuei | 0:03b5121a232e | 9987 | internal_error: |
| pcercuei | 0:03b5121a232e | 9988 | return (-1); |
| pcercuei | 0:03b5121a232e | 9989 | } |
| pcercuei | 0:03b5121a232e | 9990 | |
| pcercuei | 0:03b5121a232e | 9991 | /* |
| pcercuei | 0:03b5121a232e | 9992 | * xmlDOMWrapAdoptNode: |
| pcercuei | 0:03b5121a232e | 9993 | * @ctxt: the optional context for custom processing |
| pcercuei | 0:03b5121a232e | 9994 | * @sourceDoc: the optional sourceDoc |
| pcercuei | 0:03b5121a232e | 9995 | * @node: the node to start with |
| pcercuei | 0:03b5121a232e | 9996 | * @destDoc: the destination doc |
| pcercuei | 0:03b5121a232e | 9997 | * @destParent: the optional new parent of @node in @destDoc |
| pcercuei | 0:03b5121a232e | 9998 | * @options: option flags |
| pcercuei | 0:03b5121a232e | 9999 | * |
| pcercuei | 0:03b5121a232e | 10000 | * References of out-of scope ns-decls are remapped to point to @destDoc: |
| pcercuei | 0:03b5121a232e | 10001 | * 1) If @destParent is given, then nsDef entries on element-nodes are used |
| pcercuei | 0:03b5121a232e | 10002 | * 2) If *no* @destParent is given, then @destDoc->oldNs entries are used |
| pcercuei | 0:03b5121a232e | 10003 | * This is the case when you have an unlinked node and just want to move it |
| pcercuei | 0:03b5121a232e | 10004 | * to the context of |
| pcercuei | 0:03b5121a232e | 10005 | * |
| pcercuei | 0:03b5121a232e | 10006 | * If @destParent is given, it ensures that the tree is namespace |
| pcercuei | 0:03b5121a232e | 10007 | * wellformed by creating additional ns-decls where needed. |
| pcercuei | 0:03b5121a232e | 10008 | * Note that, since prefixes of already existent ns-decls can be |
| pcercuei | 0:03b5121a232e | 10009 | * shadowed by this process, it could break QNames in attribute |
| pcercuei | 0:03b5121a232e | 10010 | * values or element content. |
| pcercuei | 0:03b5121a232e | 10011 | * NOTE: This function was not intensively tested. |
| pcercuei | 0:03b5121a232e | 10012 | * |
| pcercuei | 0:03b5121a232e | 10013 | * Returns 0 if the operation succeeded, |
| pcercuei | 0:03b5121a232e | 10014 | * 1 if a node of unsupported type was given, |
| pcercuei | 0:03b5121a232e | 10015 | * 2 if a node of not yet supported type was given and |
| pcercuei | 0:03b5121a232e | 10016 | * -1 on API/internal errors. |
| pcercuei | 0:03b5121a232e | 10017 | */ |
| pcercuei | 0:03b5121a232e | 10018 | int |
| pcercuei | 0:03b5121a232e | 10019 | xmlDOMWrapAdoptNode(xmlDOMWrapCtxtPtr ctxt, |
| pcercuei | 0:03b5121a232e | 10020 | xmlDocPtr sourceDoc, |
| pcercuei | 0:03b5121a232e | 10021 | xmlNodePtr node, |
| pcercuei | 0:03b5121a232e | 10022 | xmlDocPtr destDoc, |
| pcercuei | 0:03b5121a232e | 10023 | xmlNodePtr destParent, |
| pcercuei | 0:03b5121a232e | 10024 | int options) |
| pcercuei | 0:03b5121a232e | 10025 | { |
| pcercuei | 0:03b5121a232e | 10026 | if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) || |
| pcercuei | 0:03b5121a232e | 10027 | (destDoc == NULL) || |
| pcercuei | 0:03b5121a232e | 10028 | ((destParent != NULL) && (destParent->doc != destDoc))) |
| pcercuei | 0:03b5121a232e | 10029 | return(-1); |
| pcercuei | 0:03b5121a232e | 10030 | /* |
| pcercuei | 0:03b5121a232e | 10031 | * Check node->doc sanity. |
| pcercuei | 0:03b5121a232e | 10032 | */ |
| pcercuei | 0:03b5121a232e | 10033 | if ((node->doc != NULL) && (sourceDoc != NULL) && |
| pcercuei | 0:03b5121a232e | 10034 | (node->doc != sourceDoc)) { |
| pcercuei | 0:03b5121a232e | 10035 | /* |
| pcercuei | 0:03b5121a232e | 10036 | * Might be an XIncluded node. |
| pcercuei | 0:03b5121a232e | 10037 | */ |
| pcercuei | 0:03b5121a232e | 10038 | return (-1); |
| pcercuei | 0:03b5121a232e | 10039 | } |
| pcercuei | 0:03b5121a232e | 10040 | if (sourceDoc == NULL) |
| pcercuei | 0:03b5121a232e | 10041 | sourceDoc = node->doc; |
| pcercuei | 0:03b5121a232e | 10042 | if (sourceDoc == destDoc) |
| pcercuei | 0:03b5121a232e | 10043 | return (-1); |
| pcercuei | 0:03b5121a232e | 10044 | switch (node->type) { |
| pcercuei | 0:03b5121a232e | 10045 | case XML_ELEMENT_NODE: |
| pcercuei | 0:03b5121a232e | 10046 | case XML_ATTRIBUTE_NODE: |
| pcercuei | 0:03b5121a232e | 10047 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 10048 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 10049 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 10050 | case XML_PI_NODE: |
| pcercuei | 0:03b5121a232e | 10051 | case XML_COMMENT_NODE: |
| pcercuei | 0:03b5121a232e | 10052 | break; |
| pcercuei | 0:03b5121a232e | 10053 | case XML_DOCUMENT_FRAG_NODE: |
| pcercuei | 0:03b5121a232e | 10054 | /* TODO: Support document-fragment-nodes. */ |
| pcercuei | 0:03b5121a232e | 10055 | return (2); |
| pcercuei | 0:03b5121a232e | 10056 | default: |
| pcercuei | 0:03b5121a232e | 10057 | return (1); |
| pcercuei | 0:03b5121a232e | 10058 | } |
| pcercuei | 0:03b5121a232e | 10059 | /* |
| pcercuei | 0:03b5121a232e | 10060 | * Unlink only if @node was not already added to @destParent. |
| pcercuei | 0:03b5121a232e | 10061 | */ |
| pcercuei | 0:03b5121a232e | 10062 | if ((node->parent != NULL) && (destParent != node->parent)) |
| pcercuei | 0:03b5121a232e | 10063 | xmlUnlinkNode(node); |
| pcercuei | 0:03b5121a232e | 10064 | |
| pcercuei | 0:03b5121a232e | 10065 | if (node->type == XML_ELEMENT_NODE) { |
| pcercuei | 0:03b5121a232e | 10066 | return (xmlDOMWrapAdoptBranch(ctxt, sourceDoc, node, |
| pcercuei | 0:03b5121a232e | 10067 | destDoc, destParent, options)); |
| pcercuei | 0:03b5121a232e | 10068 | } else if (node->type == XML_ATTRIBUTE_NODE) { |
| pcercuei | 0:03b5121a232e | 10069 | return (xmlDOMWrapAdoptAttr(ctxt, sourceDoc, |
| pcercuei | 0:03b5121a232e | 10070 | (xmlAttrPtr) node, destDoc, destParent, options)); |
| pcercuei | 0:03b5121a232e | 10071 | } else { |
| pcercuei | 0:03b5121a232e | 10072 | xmlNodePtr cur = node; |
| pcercuei | 0:03b5121a232e | 10073 | int adoptStr = 1; |
| pcercuei | 0:03b5121a232e | 10074 | |
| pcercuei | 0:03b5121a232e | 10075 | cur->doc = destDoc; |
| pcercuei | 0:03b5121a232e | 10076 | /* |
| pcercuei | 0:03b5121a232e | 10077 | * Optimize string adoption. |
| pcercuei | 0:03b5121a232e | 10078 | */ |
| pcercuei | 0:03b5121a232e | 10079 | if ((sourceDoc != NULL) && |
| pcercuei | 0:03b5121a232e | 10080 | (sourceDoc->dict == destDoc->dict)) |
| pcercuei | 0:03b5121a232e | 10081 | adoptStr = 0; |
| pcercuei | 0:03b5121a232e | 10082 | switch (node->type) { |
| pcercuei | 0:03b5121a232e | 10083 | case XML_TEXT_NODE: |
| pcercuei | 0:03b5121a232e | 10084 | case XML_CDATA_SECTION_NODE: |
| pcercuei | 0:03b5121a232e | 10085 | XML_TREE_ADOPT_STR_2(node->content) |
| pcercuei | 0:03b5121a232e | 10086 | break; |
| pcercuei | 0:03b5121a232e | 10087 | case XML_ENTITY_REF_NODE: |
| pcercuei | 0:03b5121a232e | 10088 | /* |
| pcercuei | 0:03b5121a232e | 10089 | * Remove reference to the entitity-node. |
| pcercuei | 0:03b5121a232e | 10090 | */ |
| pcercuei | 0:03b5121a232e | 10091 | node->content = NULL; |
| pcercuei | 0:03b5121a232e | 10092 | node->children = NULL; |
| pcercuei | 0:03b5121a232e | 10093 | node->last = NULL; |
| pcercuei | 0:03b5121a232e | 10094 | if ((destDoc->intSubset) || (destDoc->extSubset)) { |
| pcercuei | 0:03b5121a232e | 10095 | xmlEntityPtr ent; |
| pcercuei | 0:03b5121a232e | 10096 | /* |
| pcercuei | 0:03b5121a232e | 10097 | * Assign new entity-node if available. |
| pcercuei | 0:03b5121a232e | 10098 | */ |
| pcercuei | 0:03b5121a232e | 10099 | ent = xmlGetDocEntity(destDoc, node->name); |
| pcercuei | 0:03b5121a232e | 10100 | if (ent != NULL) { |
| pcercuei | 0:03b5121a232e | 10101 | node->content = ent->content; |
| pcercuei | 0:03b5121a232e | 10102 | node->children = (xmlNodePtr) ent; |
| pcercuei | 0:03b5121a232e | 10103 | node->last = (xmlNodePtr) ent; |
| pcercuei | 0:03b5121a232e | 10104 | } |
| pcercuei | 0:03b5121a232e | 10105 | } |
| pcercuei | 0:03b5121a232e | 10106 | XML_TREE_ADOPT_STR(node->name) |
| pcercuei | 0:03b5121a232e | 10107 | break; |
| pcercuei | 0:03b5121a232e | 10108 | case XML_PI_NODE: { |
| pcercuei | 0:03b5121a232e | 10109 | XML_TREE_ADOPT_STR(node->name) |
| pcercuei | 0:03b5121a232e | 10110 | XML_TREE_ADOPT_STR_2(node->content) |
| pcercuei | 0:03b5121a232e | 10111 | break; |
| pcercuei | 0:03b5121a232e | 10112 | } |
| pcercuei | 0:03b5121a232e | 10113 | default: |
| pcercuei | 0:03b5121a232e | 10114 | break; |
| pcercuei | 0:03b5121a232e | 10115 | } |
| pcercuei | 0:03b5121a232e | 10116 | } |
| pcercuei | 0:03b5121a232e | 10117 | return (0); |
| pcercuei | 0:03b5121a232e | 10118 | } |
| pcercuei | 0:03b5121a232e | 10119 | |
| pcercuei | 0:03b5121a232e | 10120 | #define bottom_tree |
| pcercuei | 0:03b5121a232e | 10121 | #include "elfgcchack.h" |
| pcercuei | 0:03b5121a232e | 10122 |