OLD | NEW |
1 /* | 1 /* |
2 * tree.c : implementation of access function for an XML tree. | 2 * tree.c : implementation of access function for an XML tree. |
3 * | 3 * |
4 * References: | 4 * References: |
5 * XHTML 1.0 W3C REC: http://www.w3.org/TR/2002/REC-xhtml1-20020801/ | 5 * XHTML 1.0 W3C REC: http://www.w3.org/TR/2002/REC-xhtml1-20020801/ |
6 * | 6 * |
7 * See Copyright for the status of this software. | 7 * See Copyright for the status of this software. |
8 * | 8 * |
9 * daniel@veillard.com | 9 * daniel@veillard.com |
10 * | 10 * |
11 */ | 11 */ |
12 | 12 |
13 #define IN_LIBXML | 13 #define IN_LIBXML |
14 #include "libxml.h" | 14 #include "libxml.h" |
15 | 15 |
16 #include <string.h> /* for memset() only ! */ | 16 #include <string.h> /* for memset() only ! */ |
17 | 17 #include <limits.h> |
18 #ifdef HAVE_CTYPE_H | 18 #ifdef HAVE_CTYPE_H |
19 #include <ctype.h> | 19 #include <ctype.h> |
20 #endif | 20 #endif |
21 #ifdef HAVE_STDLIB_H | 21 #ifdef HAVE_STDLIB_H |
22 #include <stdlib.h> | 22 #include <stdlib.h> |
23 #endif | 23 #endif |
24 #ifdef HAVE_ZLIB_H | 24 #ifdef HAVE_ZLIB_H |
25 #include <zlib.h> | 25 #include <zlib.h> |
26 #endif | 26 #endif |
27 | 27 |
(...skipping 10 matching lines...) Expand all Loading... |
38 #include <libxml/HTMLtree.h> | 38 #include <libxml/HTMLtree.h> |
39 #endif | 39 #endif |
40 #ifdef LIBXML_DEBUG_ENABLED | 40 #ifdef LIBXML_DEBUG_ENABLED |
41 #include <libxml/debugXML.h> | 41 #include <libxml/debugXML.h> |
42 #endif | 42 #endif |
43 | 43 |
44 int __xmlRegisterCallbacks = 0; | 44 int __xmlRegisterCallbacks = 0; |
45 | 45 |
46 /************************************************************************ | 46 /************************************************************************ |
47 * * | 47 * * |
48 * » » Forward declarations» » » » » * | 48 *» » Forward declarations» » » » » * |
49 * * | 49 * * |
50 ************************************************************************/ | 50 ************************************************************************/ |
51 | 51 |
52 xmlNsPtr xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns); | 52 static xmlNsPtr |
| 53 xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns); |
53 | 54 |
54 static xmlChar* xmlGetPropNodeValueInternal(xmlAttrPtr prop); | 55 static xmlChar* xmlGetPropNodeValueInternal(xmlAttrPtr prop); |
55 | 56 |
56 /************************************************************************ | 57 /************************************************************************ |
57 * * | 58 * * |
58 * » » Tree memory error handler» » » » * | 59 *» » Tree memory error handler» » » » * |
59 * * | 60 * * |
60 ************************************************************************/ | 61 ************************************************************************/ |
61 /** | 62 /** |
62 * xmlTreeErrMemory: | 63 * xmlTreeErrMemory: |
63 * @extra: extra informations | 64 * @extra: extra informations |
64 * | 65 * |
65 * Handle an out of memory condition | 66 * Handle an out of memory condition |
66 */ | 67 */ |
67 static void | 68 static void |
68 xmlTreeErrMemory(const char *extra) | 69 xmlTreeErrMemory(const char *extra) |
(...skipping 27 matching lines...) Expand all Loading... |
96 msg = "string is not in UTF-8\n"; | 97 msg = "string is not in UTF-8\n"; |
97 break; | 98 break; |
98 default: | 99 default: |
99 msg = "unexpected error number\n"; | 100 msg = "unexpected error number\n"; |
100 } | 101 } |
101 __xmlSimpleError(XML_FROM_TREE, code, node, msg, extra); | 102 __xmlSimpleError(XML_FROM_TREE, code, node, msg, extra); |
102 } | 103 } |
103 | 104 |
104 /************************************************************************ | 105 /************************************************************************ |
105 * * | 106 * * |
106 * » » A few static variables and macros» » » * | 107 *» » A few static variables and macros» » » * |
107 * * | 108 * * |
108 ************************************************************************/ | 109 ************************************************************************/ |
109 /* #undef xmlStringText */ | 110 /* #undef xmlStringText */ |
110 const xmlChar xmlStringText[] = { 't', 'e', 'x', 't', 0 }; | 111 const xmlChar xmlStringText[] = { 't', 'e', 'x', 't', 0 }; |
111 /* #undef xmlStringTextNoenc */ | 112 /* #undef xmlStringTextNoenc */ |
112 const xmlChar xmlStringTextNoenc[] = | 113 const xmlChar xmlStringTextNoenc[] = |
113 { 't', 'e', 'x', 't', 'n', 'o', 'e', 'n', 'c', 0 }; | 114 { 't', 'e', 'x', 't', 'n', 'o', 'e', 'n', 'c', 0 }; |
114 /* #undef xmlStringComment */ | 115 /* #undef xmlStringComment */ |
115 const xmlChar xmlStringComment[] = { 'c', 'o', 'm', 'm', 'e', 'n', 't', 0 }; | 116 const xmlChar xmlStringComment[] = { 'c', 'o', 'm', 'm', 'e', 'n', 't', 0 }; |
116 | 117 |
117 static int xmlCompressMode = 0; | 118 static int xmlCompressMode = 0; |
118 static int xmlCheckDTD = 1; | 119 static int xmlCheckDTD = 1; |
119 | 120 |
120 #define UPDATE_LAST_CHILD_AND_PARENT(n) if ((n) != NULL) { \ | 121 #define UPDATE_LAST_CHILD_AND_PARENT(n) if ((n) != NULL) { \ |
121 xmlNodePtr ulccur = (n)->children; \ | 122 xmlNodePtr ulccur = (n)->children; \ |
122 if (ulccur == NULL) { \ | 123 if (ulccur == NULL) { \ |
123 (n)->last = NULL; \ | 124 (n)->last = NULL; \ |
124 } else { \ | 125 } else { \ |
125 while (ulccur->next != NULL) { \ | 126 while (ulccur->next != NULL) { \ |
126 » »ulccur->parent = (n);» » » » » \ | 127 » » ulccur->parent = (n);» » » » » \ |
127 ulccur = ulccur->next; \ | 128 ulccur = ulccur->next; \ |
128 } \ | 129 } \ |
129 ulccur->parent = (n); \ | 130 ulccur->parent = (n); \ |
130 (n)->last = ulccur; \ | 131 (n)->last = ulccur; \ |
131 }} | 132 }} |
132 | 133 |
133 #define IS_STR_XML(str) ((str != NULL) && (str[0] == 'x') && \ | 134 #define IS_STR_XML(str) ((str != NULL) && (str[0] == 'x') && \ |
134 (str[1] == 'm') && (str[2] == 'l') && (str[3] == 0)) | 135 (str[1] == 'm') && (str[2] == 'l') && (str[3] == 0)) |
135 | 136 |
136 /* #define DEBUG_BUFFER */ | 137 /* #define DEBUG_BUFFER */ |
137 /* #define DEBUG_TREE */ | 138 /* #define DEBUG_TREE */ |
138 | 139 |
139 /************************************************************************ | 140 /************************************************************************ |
140 * * | 141 * * |
141 *» » Functions to move to entities.c once the » » * | 142 *» » Functions to move to entities.c once the» » * |
142 * API freeze is smoothen and they can be made public. * | 143 * API freeze is smoothen and they can be made public. * |
143 * * | 144 * * |
144 ************************************************************************/ | 145 ************************************************************************/ |
145 #include <libxml/hash.h> | 146 #include <libxml/hash.h> |
146 | 147 |
147 #ifdef LIBXML_TREE_ENABLED | 148 #ifdef LIBXML_TREE_ENABLED |
148 /** | 149 /** |
149 * xmlGetEntityFromDtd: | 150 * xmlGetEntityFromDtd: |
150 * @dtd: A pointer to the DTD to search | 151 * @dtd: A pointer to the DTD to search |
151 * @name: The entity name | 152 * @name: The entity name |
152 * | 153 * |
153 * Do an entity lookup in the DTD entity hash table and | 154 * Do an entity lookup in the DTD entity hash table and |
154 * return the corresponding entity, if found. | 155 * return the corresponding entity, if found. |
155 * | 156 * |
156 * Returns A pointer to the entity structure or NULL if not found. | 157 * Returns A pointer to the entity structure or NULL if not found. |
157 */ | 158 */ |
158 static xmlEntityPtr | 159 static xmlEntityPtr |
159 xmlGetEntityFromDtd(xmlDtdPtr dtd, const xmlChar *name) { | 160 xmlGetEntityFromDtd(xmlDtdPtr dtd, const xmlChar *name) { |
160 xmlEntitiesTablePtr table; | 161 xmlEntitiesTablePtr table; |
161 | 162 |
162 if((dtd != NULL) && (dtd->entities != NULL)) { | 163 if((dtd != NULL) && (dtd->entities != NULL)) { |
163 table = (xmlEntitiesTablePtr) dtd->entities; | 164 table = (xmlEntitiesTablePtr) dtd->entities; |
164 return((xmlEntityPtr) xmlHashLookup(table, name)); | 165 return((xmlEntityPtr) xmlHashLookup(table, name)); |
165 » /* return(xmlGetEntityFromTable(table, name)); */ | 166 » /* return(xmlGetEntityFromTable(table, name)); */ |
166 } | 167 } |
167 return(NULL); | 168 return(NULL); |
168 } | 169 } |
169 /** | 170 /** |
170 * xmlGetParameterEntityFromDtd: | 171 * xmlGetParameterEntityFromDtd: |
171 * @dtd: A pointer to the DTD to search | 172 * @dtd: A pointer to the DTD to search |
172 * @name: The entity name | 173 * @name: The entity name |
173 * | 174 * |
174 * Do an entity lookup in the DTD pararmeter entity hash table and | 175 * Do an entity lookup in the DTD pararmeter entity hash table and |
175 * return the corresponding entity, if found. | 176 * return the corresponding entity, if found. |
176 * | 177 * |
177 * Returns A pointer to the entity structure or NULL if not found. | 178 * Returns A pointer to the entity structure or NULL if not found. |
178 */ | 179 */ |
179 static xmlEntityPtr | 180 static xmlEntityPtr |
180 xmlGetParameterEntityFromDtd(xmlDtdPtr dtd, const xmlChar *name) { | 181 xmlGetParameterEntityFromDtd(xmlDtdPtr dtd, const xmlChar *name) { |
181 xmlEntitiesTablePtr table; | 182 xmlEntitiesTablePtr table; |
182 | 183 |
183 if ((dtd != NULL) && (dtd->pentities != NULL)) { | 184 if ((dtd != NULL) && (dtd->pentities != NULL)) { |
184 table = (xmlEntitiesTablePtr) dtd->pentities; | 185 table = (xmlEntitiesTablePtr) dtd->pentities; |
185 return((xmlEntityPtr) xmlHashLookup(table, name)); | 186 return((xmlEntityPtr) xmlHashLookup(table, name)); |
186 /* return(xmlGetEntityFromTable(table, name)); */ | 187 /* return(xmlGetEntityFromTable(table, name)); */ |
187 } | 188 } |
188 return(NULL); | 189 return(NULL); |
189 } | 190 } |
190 #endif /* LIBXML_TREE_ENABLED */ | 191 #endif /* LIBXML_TREE_ENABLED */ |
191 | 192 |
192 /************************************************************************ | 193 /************************************************************************ |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 memcpy(&ret[0], prefix, lenp); | 234 memcpy(&ret[0], prefix, lenp); |
234 ret[lenp] = ':'; | 235 ret[lenp] = ':'; |
235 memcpy(&ret[lenp + 1], ncname, lenn); | 236 memcpy(&ret[lenp + 1], ncname, lenn); |
236 ret[lenn + lenp + 1] = 0; | 237 ret[lenn + lenp + 1] = 0; |
237 return(ret); | 238 return(ret); |
238 } | 239 } |
239 | 240 |
240 /** | 241 /** |
241 * xmlSplitQName2: | 242 * xmlSplitQName2: |
242 * @name: the full QName | 243 * @name: the full QName |
243 * @prefix: a xmlChar ** | 244 * @prefix: a xmlChar ** |
244 * | 245 * |
245 * parse an XML qualified name string | 246 * parse an XML qualified name string |
246 * | 247 * |
247 * [NS 5] QName ::= (Prefix ':')? LocalPart | 248 * [NS 5] QName ::= (Prefix ':')? LocalPart |
248 * | 249 * |
249 * [NS 6] Prefix ::= NCName | 250 * [NS 6] Prefix ::= NCName |
250 * | 251 * |
251 * [NS 7] LocalPart ::= NCName | 252 * [NS 7] LocalPart ::= NCName |
252 * | 253 * |
253 * Returns NULL if not a QName, otherwise the local part, and prefix | 254 * Returns NULL if not a QName, otherwise the local part, and prefix |
(...skipping 17 matching lines...) Expand all Loading... |
271 #endif | 272 #endif |
272 | 273 |
273 /* nasty but valid */ | 274 /* nasty but valid */ |
274 if (name[0] == ':') | 275 if (name[0] == ':') |
275 return(NULL); | 276 return(NULL); |
276 | 277 |
277 /* | 278 /* |
278 * we are not trying to validate but just to cut, and yes it will | 279 * we are not trying to validate but just to cut, and yes it will |
279 * work even if this is as set of UTF-8 encoded chars | 280 * work even if this is as set of UTF-8 encoded chars |
280 */ | 281 */ |
281 while ((name[len] != 0) && (name[len] != ':')) | 282 while ((name[len] != 0) && (name[len] != ':')) |
282 len++; | 283 len++; |
283 | 284 |
284 if (name[len] == 0) | 285 if (name[len] == 0) |
285 return(NULL); | 286 return(NULL); |
286 | 287 |
287 *prefix = xmlStrndup(name, len); | 288 *prefix = xmlStrndup(name, len); |
288 if (*prefix == NULL) { | 289 if (*prefix == NULL) { |
289 xmlTreeErrMemory("QName split"); | 290 xmlTreeErrMemory("QName split"); |
290 return(NULL); | 291 return(NULL); |
291 } | 292 } |
292 ret = xmlStrdup(&name[len + 1]); | 293 ret = xmlStrdup(&name[len + 1]); |
293 if (ret == NULL) { | 294 if (ret == NULL) { |
(...skipping 28 matching lines...) Expand all Loading... |
322 if (len == NULL) return(NULL); | 323 if (len == NULL) return(NULL); |
323 | 324 |
324 /* nasty but valid */ | 325 /* nasty but valid */ |
325 if (name[0] == ':') | 326 if (name[0] == ':') |
326 return(NULL); | 327 return(NULL); |
327 | 328 |
328 /* | 329 /* |
329 * we are not trying to validate but just to cut, and yes it will | 330 * we are not trying to validate but just to cut, and yes it will |
330 * work even if this is as set of UTF-8 encoded chars | 331 * work even if this is as set of UTF-8 encoded chars |
331 */ | 332 */ |
332 while ((name[l] != 0) && (name[l] != ':')) | 333 while ((name[l] != 0) && (name[l] != ':')) |
333 l++; | 334 l++; |
334 | 335 |
335 if (name[l] == 0) | 336 if (name[l] == 0) |
336 return(NULL); | 337 return(NULL); |
337 | 338 |
338 *len = l; | 339 *len = l; |
339 | 340 |
340 return(&name[l+1]); | 341 return(&name[l+1]); |
341 } | 342 } |
342 | 343 |
343 /************************************************************************ | 344 /************************************************************************ |
344 * * | 345 * * |
345 * Check Name, NCName and QName strings * | 346 * Check Name, NCName and QName strings * |
346 * * | 347 * * |
347 ************************************************************************/ | 348 ************************************************************************/ |
348 | 349 |
349 #define CUR_SCHAR(s, l) xmlStringCurrentChar(NULL, s, &l) | 350 #define CUR_SCHAR(s, l) xmlStringCurrentChar(NULL, s, &l) |
350 | 351 |
351 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIB
XML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) || defined (LIBXML_HTML_EN
ABLED) || defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || define
d(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) | 352 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIB
XML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) || defined (LIBXML_HTML_EN
ABLED) || defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || define
d(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) |
352 /** | 353 /** |
353 * xmlValidateNCName: | 354 * xmlValidateNCName: |
354 * @value: the value to check | 355 * @value: the value to check |
355 * @space: allow spaces in front and end of the string | 356 * @space: allow spaces in front and end of the string |
356 * | 357 * |
357 * Check that a value conforms to the lexical space of NCName | 358 * Check that a value conforms to the lexical space of NCName |
358 * | 359 * |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 return(1); | 662 return(1); |
662 return(0); | 663 return(0); |
663 } | 664 } |
664 #endif /* LIBXML_TREE_ENABLED */ | 665 #endif /* LIBXML_TREE_ENABLED */ |
665 | 666 |
666 /************************************************************************ | 667 /************************************************************************ |
667 * * | 668 * * |
668 * Allocation and deallocation of basic structures * | 669 * Allocation and deallocation of basic structures * |
669 * * | 670 * * |
670 ************************************************************************/ | 671 ************************************************************************/ |
671 | 672 |
672 /** | 673 /** |
673 * xmlSetBufferAllocationScheme: | 674 * xmlSetBufferAllocationScheme: |
674 * @scheme: allocation method to use | 675 * @scheme: allocation method to use |
675 * | 676 * |
676 * Set the buffer allocation method. Types are | 677 * Set the buffer allocation method. Types are |
677 * XML_BUFFER_ALLOC_EXACT - use exact sizes, keeps memory usage down | 678 * XML_BUFFER_ALLOC_EXACT - use exact sizes, keeps memory usage down |
678 * XML_BUFFER_ALLOC_DOUBLEIT - double buffer when extra needed, | 679 * XML_BUFFER_ALLOC_DOUBLEIT - double buffer when extra needed, |
679 * improves performance | 680 * improves performance |
680 */ | 681 */ |
681 void | 682 void |
682 xmlSetBufferAllocationScheme(xmlBufferAllocationScheme scheme) { | 683 xmlSetBufferAllocationScheme(xmlBufferAllocationScheme scheme) { |
683 xmlBufferAllocScheme = scheme; | 684 if ((scheme == XML_BUFFER_ALLOC_EXACT) || |
| 685 (scheme == XML_BUFFER_ALLOC_DOUBLEIT)) |
| 686 » xmlBufferAllocScheme = scheme; |
684 } | 687 } |
685 | 688 |
686 /** | 689 /** |
687 * xmlGetBufferAllocationScheme: | 690 * xmlGetBufferAllocationScheme: |
688 * | 691 * |
689 * Types are | 692 * Types are |
690 * XML_BUFFER_ALLOC_EXACT - use exact sizes, keeps memory usage down | 693 * XML_BUFFER_ALLOC_EXACT - use exact sizes, keeps memory usage down |
691 * XML_BUFFER_ALLOC_DOUBLEIT - double buffer when extra needed, | 694 * XML_BUFFER_ALLOC_DOUBLEIT - double buffer when extra needed, |
692 * improves performance | 695 * improves performance |
693 * | 696 * |
694 * Returns the current allocation scheme | 697 * Returns the current allocation scheme |
695 */ | 698 */ |
696 xmlBufferAllocationScheme | 699 xmlBufferAllocationScheme |
697 xmlGetBufferAllocationScheme(void) { | 700 xmlGetBufferAllocationScheme(void) { |
698 return(xmlBufferAllocScheme); | 701 return(xmlBufferAllocScheme); |
699 } | 702 } |
700 | 703 |
701 /** | 704 /** |
702 * xmlNewNs: | 705 * xmlNewNs: |
703 * @node: the element carrying the namespace | 706 * @node: the element carrying the namespace |
(...skipping 22 matching lines...) Expand all Loading... |
726 */ | 729 */ |
727 cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); | 730 cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); |
728 if (cur == NULL) { | 731 if (cur == NULL) { |
729 xmlTreeErrMemory("building namespace"); | 732 xmlTreeErrMemory("building namespace"); |
730 return(NULL); | 733 return(NULL); |
731 } | 734 } |
732 memset(cur, 0, sizeof(xmlNs)); | 735 memset(cur, 0, sizeof(xmlNs)); |
733 cur->type = XML_LOCAL_NAMESPACE; | 736 cur->type = XML_LOCAL_NAMESPACE; |
734 | 737 |
735 if (href != NULL) | 738 if (href != NULL) |
736 » cur->href = xmlStrdup(href); | 739 » cur->href = xmlStrdup(href); |
737 if (prefix != NULL) | 740 if (prefix != NULL) |
738 » cur->prefix = xmlStrdup(prefix); | 741 » cur->prefix = xmlStrdup(prefix); |
739 | 742 |
740 /* | 743 /* |
741 * Add it at the end to preserve parsing order ... | 744 * Add it at the end to preserve parsing order ... |
742 * and checks for existing use of the prefix | 745 * and checks for existing use of the prefix |
743 */ | 746 */ |
744 if (node != NULL) { | 747 if (node != NULL) { |
745 if (node->nsDef == NULL) { | 748 if (node->nsDef == NULL) { |
746 node->nsDef = cur; | 749 node->nsDef = cur; |
747 } else { | 750 } else { |
748 xmlNsPtr prev = node->nsDef; | 751 xmlNsPtr prev = node->nsDef; |
749 | 752 |
750 if (((prev->prefix == NULL) && (cur->prefix == NULL)) || | 753 if (((prev->prefix == NULL) && (cur->prefix == NULL)) || |
751 (xmlStrEqual(prev->prefix, cur->prefix))) { | 754 (xmlStrEqual(prev->prefix, cur->prefix))) { |
752 xmlFreeNs(cur); | 755 xmlFreeNs(cur); |
753 return(NULL); | 756 return(NULL); |
754 » } | 757 » } |
755 while (prev->next != NULL) { | 758 while (prev->next != NULL) { |
756 prev = prev->next; | 759 prev = prev->next; |
757 if (((prev->prefix == NULL) && (cur->prefix == NULL)) || | 760 if (((prev->prefix == NULL) && (cur->prefix == NULL)) || |
758 (xmlStrEqual(prev->prefix, cur->prefix))) { | 761 (xmlStrEqual(prev->prefix, cur->prefix))) { |
759 xmlFreeNs(cur); | 762 xmlFreeNs(cur); |
760 return(NULL); | 763 return(NULL); |
761 » » } | 764 » » } |
762 } | 765 } |
763 prev->next = cur; | 766 prev->next = cur; |
764 } | 767 } |
765 } | 768 } |
766 return(cur); | 769 return(cur); |
767 } | 770 } |
768 | 771 |
769 /** | 772 /** |
770 * xmlSetNs: | 773 * xmlSetNs: |
771 * @node: a node in the document | 774 * @node: a node in the document |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 */ | 863 */ |
861 cur = (xmlDtdPtr) xmlMalloc(sizeof(xmlDtd)); | 864 cur = (xmlDtdPtr) xmlMalloc(sizeof(xmlDtd)); |
862 if (cur == NULL) { | 865 if (cur == NULL) { |
863 xmlTreeErrMemory("building DTD"); | 866 xmlTreeErrMemory("building DTD"); |
864 return(NULL); | 867 return(NULL); |
865 } | 868 } |
866 memset(cur, 0 , sizeof(xmlDtd)); | 869 memset(cur, 0 , sizeof(xmlDtd)); |
867 cur->type = XML_DTD_NODE; | 870 cur->type = XML_DTD_NODE; |
868 | 871 |
869 if (name != NULL) | 872 if (name != NULL) |
870 » cur->name = xmlStrdup(name); | 873 » cur->name = xmlStrdup(name); |
871 if (ExternalID != NULL) | 874 if (ExternalID != NULL) |
872 » cur->ExternalID = xmlStrdup(ExternalID); | 875 » cur->ExternalID = xmlStrdup(ExternalID); |
873 if (SystemID != NULL) | 876 if (SystemID != NULL) |
874 » cur->SystemID = xmlStrdup(SystemID); | 877 » cur->SystemID = xmlStrdup(SystemID); |
875 if (doc != NULL) | 878 if (doc != NULL) |
876 doc->extSubset = cur; | 879 doc->extSubset = cur; |
877 cur->doc = doc; | 880 cur->doc = doc; |
878 | 881 |
879 if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) | 882 if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
880 xmlRegisterNodeDefaultValue((xmlNodePtr)cur); | 883 xmlRegisterNodeDefaultValue((xmlNodePtr)cur); |
881 return(cur); | 884 return(cur); |
882 } | 885 } |
883 | 886 |
884 /** | 887 /** |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 | 945 |
943 if (name != NULL) { | 946 if (name != NULL) { |
944 cur->name = xmlStrdup(name); | 947 cur->name = xmlStrdup(name); |
945 if (cur->name == NULL) { | 948 if (cur->name == NULL) { |
946 xmlTreeErrMemory("building internal subset"); | 949 xmlTreeErrMemory("building internal subset"); |
947 xmlFree(cur); | 950 xmlFree(cur); |
948 return(NULL); | 951 return(NULL); |
949 } | 952 } |
950 } | 953 } |
951 if (ExternalID != NULL) { | 954 if (ExternalID != NULL) { |
952 » cur->ExternalID = xmlStrdup(ExternalID); | 955 » cur->ExternalID = xmlStrdup(ExternalID); |
953 if (cur->ExternalID == NULL) { | 956 if (cur->ExternalID == NULL) { |
954 xmlTreeErrMemory("building internal subset"); | 957 xmlTreeErrMemory("building internal subset"); |
955 if (cur->name != NULL) | 958 if (cur->name != NULL) |
956 xmlFree((char *)cur->name); | 959 xmlFree((char *)cur->name); |
957 xmlFree(cur); | 960 xmlFree(cur); |
958 return(NULL); | 961 return(NULL); |
959 } | 962 } |
960 } | 963 } |
961 if (SystemID != NULL) { | 964 if (SystemID != NULL) { |
962 » cur->SystemID = xmlStrdup(SystemID); | 965 » cur->SystemID = xmlStrdup(SystemID); |
963 if (cur->SystemID == NULL) { | 966 if (cur->SystemID == NULL) { |
964 xmlTreeErrMemory("building internal subset"); | 967 xmlTreeErrMemory("building internal subset"); |
965 if (cur->name != NULL) | 968 if (cur->name != NULL) |
966 xmlFree((char *)cur->name); | 969 xmlFree((char *)cur->name); |
967 if (cur->ExternalID != NULL) | 970 if (cur->ExternalID != NULL) |
968 xmlFree((char *)cur->ExternalID); | 971 xmlFree((char *)cur->ExternalID); |
969 xmlFree(cur); | 972 xmlFree(cur); |
970 return(NULL); | 973 return(NULL); |
971 } | 974 } |
972 } | 975 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 } | 1018 } |
1016 | 1019 |
1017 /** | 1020 /** |
1018 * DICT_FREE: | 1021 * DICT_FREE: |
1019 * @str: a string | 1022 * @str: a string |
1020 * | 1023 * |
1021 * Free a string if it is not owned by the "dict" dictionnary in the | 1024 * Free a string if it is not owned by the "dict" dictionnary in the |
1022 * current scope | 1025 * current scope |
1023 */ | 1026 */ |
1024 #define DICT_FREE(str) \ | 1027 #define DICT_FREE(str) \ |
1025 » if ((str) && ((!dict) || » » » » \ | 1028 » if ((str) && ((!dict) ||» » » » \ |
1026 (xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \ | 1029 (xmlDictOwns(dict, (const xmlChar *)(str)) == 0))) \ |
1027 xmlFree((char *)(str)); | 1030 xmlFree((char *)(str)); |
1028 | 1031 |
1029 | 1032 |
1030 /** | 1033 /** |
1031 * DICT_COPY: | 1034 * DICT_COPY: |
1032 * @str: a string | 1035 * @str: a string |
1033 * | 1036 * |
1034 * Copy a string using a "dict" dictionnary in the current scope, | 1037 * Copy a string using a "dict" dictionnary in the current scope, |
1035 * if availabe. | 1038 * if availabe. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 } | 1101 } |
1099 c = next; | 1102 c = next; |
1100 } | 1103 } |
1101 } | 1104 } |
1102 DICT_FREE(cur->name) | 1105 DICT_FREE(cur->name) |
1103 DICT_FREE(cur->SystemID) | 1106 DICT_FREE(cur->SystemID) |
1104 DICT_FREE(cur->ExternalID) | 1107 DICT_FREE(cur->ExternalID) |
1105 /* TODO !!! */ | 1108 /* TODO !!! */ |
1106 if (cur->notations != NULL) | 1109 if (cur->notations != NULL) |
1107 xmlFreeNotationTable((xmlNotationTablePtr) cur->notations); | 1110 xmlFreeNotationTable((xmlNotationTablePtr) cur->notations); |
1108 | 1111 |
1109 if (cur->elements != NULL) | 1112 if (cur->elements != NULL) |
1110 xmlFreeElementTable((xmlElementTablePtr) cur->elements); | 1113 xmlFreeElementTable((xmlElementTablePtr) cur->elements); |
1111 if (cur->attributes != NULL) | 1114 if (cur->attributes != NULL) |
1112 xmlFreeAttributeTable((xmlAttributeTablePtr) cur->attributes); | 1115 xmlFreeAttributeTable((xmlAttributeTablePtr) cur->attributes); |
1113 if (cur->entities != NULL) | 1116 if (cur->entities != NULL) |
1114 xmlFreeEntitiesTable((xmlEntitiesTablePtr) cur->entities); | 1117 xmlFreeEntitiesTable((xmlEntitiesTablePtr) cur->entities); |
1115 if (cur->pentities != NULL) | 1118 if (cur->pentities != NULL) |
1116 xmlFreeEntitiesTable((xmlEntitiesTablePtr) cur->pentities); | 1119 xmlFreeEntitiesTable((xmlEntitiesTablePtr) cur->pentities); |
1117 | 1120 |
1118 xmlFree(cur); | 1121 xmlFree(cur); |
(...skipping 18 matching lines...) Expand all Loading... |
1137 * Allocate a new document and fill the fields. | 1140 * Allocate a new document and fill the fields. |
1138 */ | 1141 */ |
1139 cur = (xmlDocPtr) xmlMalloc(sizeof(xmlDoc)); | 1142 cur = (xmlDocPtr) xmlMalloc(sizeof(xmlDoc)); |
1140 if (cur == NULL) { | 1143 if (cur == NULL) { |
1141 xmlTreeErrMemory("building doc"); | 1144 xmlTreeErrMemory("building doc"); |
1142 return(NULL); | 1145 return(NULL); |
1143 } | 1146 } |
1144 memset(cur, 0, sizeof(xmlDoc)); | 1147 memset(cur, 0, sizeof(xmlDoc)); |
1145 cur->type = XML_DOCUMENT_NODE; | 1148 cur->type = XML_DOCUMENT_NODE; |
1146 | 1149 |
1147 cur->version = xmlStrdup(version); | 1150 cur->version = xmlStrdup(version); |
1148 if (cur->version == NULL) { | 1151 if (cur->version == NULL) { |
1149 xmlTreeErrMemory("building doc"); | 1152 xmlTreeErrMemory("building doc"); |
1150 xmlFree(cur); | 1153 xmlFree(cur); |
1151 » return(NULL); | 1154 » return(NULL); |
1152 } | 1155 } |
1153 cur->standalone = -1; | 1156 cur->standalone = -1; |
1154 cur->compression = -1; /* not initialized */ | 1157 cur->compression = -1; /* not initialized */ |
1155 cur->doc = cur; | 1158 cur->doc = cur; |
| 1159 cur->parseFlags = 0; |
| 1160 cur->properties = XML_DOC_USERBUILT; |
1156 /* | 1161 /* |
1157 * The in memory encoding is always UTF8 | 1162 * The in memory encoding is always UTF8 |
1158 * This field will never change and would | 1163 * This field will never change and would |
1159 * be obsolete if not for binary compatibility. | 1164 * be obsolete if not for binary compatibility. |
1160 */ | 1165 */ |
1161 cur->charset = XML_CHAR_ENCODING_UTF8; | 1166 cur->charset = XML_CHAR_ENCODING_UTF8; |
1162 | 1167 |
1163 if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) | 1168 if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
1164 xmlRegisterNodeDefaultValue((xmlNodePtr)cur); | 1169 xmlRegisterNodeDefaultValue((xmlNodePtr)cur); |
1165 return(cur); | 1170 return(cur); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1273 } | 1278 } |
1274 } | 1279 } |
1275 q = cur; | 1280 q = cur; |
1276 if ((cur + 2 < end) && (cur[1] == '#') && (cur[2] == 'x')) { | 1281 if ((cur + 2 < end) && (cur[1] == '#') && (cur[2] == 'x')) { |
1277 cur += 3; | 1282 cur += 3; |
1278 if (cur < end) | 1283 if (cur < end) |
1279 tmp = *cur; | 1284 tmp = *cur; |
1280 else | 1285 else |
1281 tmp = 0; | 1286 tmp = 0; |
1282 while (tmp != ';') { /* Non input consuming loop */ | 1287 while (tmp != ';') { /* Non input consuming loop */ |
1283 » » if ((tmp >= '0') && (tmp <= '9')) | 1288 » » if ((tmp >= '0') && (tmp <= '9')) |
1284 charval = charval * 16 + (tmp - '0'); | 1289 charval = charval * 16 + (tmp - '0'); |
1285 else if ((tmp >= 'a') && (tmp <= 'f')) | 1290 else if ((tmp >= 'a') && (tmp <= 'f')) |
1286 charval = charval * 16 + (tmp - 'a') + 10; | 1291 charval = charval * 16 + (tmp - 'a') + 10; |
1287 else if ((tmp >= 'A') && (tmp <= 'F')) | 1292 else if ((tmp >= 'A') && (tmp <= 'F')) |
1288 charval = charval * 16 + (tmp - 'A') + 10; | 1293 charval = charval * 16 + (tmp - 'A') + 10; |
1289 else { | 1294 else { |
1290 xmlTreeErr(XML_TREE_INVALID_HEX, (xmlNodePtr) doc, | 1295 xmlTreeErr(XML_TREE_INVALID_HEX, (xmlNodePtr) doc, |
1291 NULL); | 1296 NULL); |
1292 charval = 0; | 1297 charval = 0; |
1293 break; | 1298 break; |
1294 } | 1299 } |
1295 cur++; | 1300 cur++; |
1296 if (cur < end) | 1301 if (cur < end) |
1297 tmp = *cur; | 1302 tmp = *cur; |
1298 else | 1303 else |
1299 tmp = 0; | 1304 tmp = 0; |
1300 } | 1305 } |
1301 if (tmp == ';') | 1306 if (tmp == ';') |
1302 cur++; | 1307 cur++; |
1303 q = cur; | 1308 q = cur; |
1304 } else if ((cur + 1 < end) && (cur[1] == '#')) { | 1309 } else if ((cur + 1 < end) && (cur[1] == '#')) { |
1305 cur += 2; | 1310 cur += 2; |
1306 if (cur < end) | 1311 if (cur < end) |
1307 tmp = *cur; | 1312 tmp = *cur; |
1308 else | 1313 else |
1309 tmp = 0; | 1314 tmp = 0; |
1310 while (tmp != ';') { /* Non input consuming loops */ | 1315 while (tmp != ';') { /* Non input consuming loops */ |
1311 » » if ((tmp >= '0') && (tmp <= '9')) | 1316 » » if ((tmp >= '0') && (tmp <= '9')) |
1312 charval = charval * 10 + (tmp - '0'); | 1317 charval = charval * 10 + (tmp - '0'); |
1313 else { | 1318 else { |
1314 xmlTreeErr(XML_TREE_INVALID_DEC, (xmlNodePtr) doc, | 1319 xmlTreeErr(XML_TREE_INVALID_DEC, (xmlNodePtr) doc, |
1315 NULL); | 1320 NULL); |
1316 charval = 0; | 1321 charval = 0; |
1317 break; | 1322 break; |
1318 } | 1323 } |
1319 cur++; | 1324 cur++; |
1320 if (cur < end) | 1325 if (cur < end) |
1321 tmp = *cur; | 1326 tmp = *cur; |
(...skipping 24 matching lines...) Expand all Loading... |
1346 if ((ent != NULL) && | 1351 if ((ent != NULL) && |
1347 (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { | 1352 (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { |
1348 if (last == NULL) { | 1353 if (last == NULL) { |
1349 node = xmlNewDocText(doc, ent->content); | 1354 node = xmlNewDocText(doc, ent->content); |
1350 last = ret = node; | 1355 last = ret = node; |
1351 } else if (last->type != XML_TEXT_NODE) { | 1356 } else if (last->type != XML_TEXT_NODE) { |
1352 node = xmlNewDocText(doc, ent->content); | 1357 node = xmlNewDocText(doc, ent->content); |
1353 last = xmlAddNextSibling(last, node); | 1358 last = xmlAddNextSibling(last, node); |
1354 } else | 1359 } else |
1355 xmlNodeAddContent(last, ent->content); | 1360 xmlNodeAddContent(last, ent->content); |
1356 » » » | 1361 |
1357 } else { | 1362 } else { |
1358 /* | 1363 /* |
1359 * Create a new REFERENCE_REF node | 1364 * Create a new REFERENCE_REF node |
1360 */ | 1365 */ |
1361 node = xmlNewReference(doc, val); | 1366 node = xmlNewReference(doc, val); |
1362 if (node == NULL) { | 1367 if (node == NULL) { |
1363 if (val != NULL) xmlFree(val); | 1368 if (val != NULL) xmlFree(val); |
1364 return(ret); | 1369 return(ret); |
1365 } | 1370 } |
1366 else if ((ent != NULL) && (ent->children == NULL)) { | 1371 else if ((ent != NULL) && (ent->children == NULL)) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1409 if ((cur != q) || (ret == NULL)) { | 1414 if ((cur != q) || (ret == NULL)) { |
1410 /* | 1415 /* |
1411 * Handle the last piece of text. | 1416 * Handle the last piece of text. |
1412 */ | 1417 */ |
1413 if ((last != NULL) && (last->type == XML_TEXT_NODE)) { | 1418 if ((last != NULL) && (last->type == XML_TEXT_NODE)) { |
1414 xmlNodeAddContentLen(last, q, cur - q); | 1419 xmlNodeAddContentLen(last, q, cur - q); |
1415 } else { | 1420 } else { |
1416 node = xmlNewDocTextLen(doc, q, cur - q); | 1421 node = xmlNewDocTextLen(doc, q, cur - q); |
1417 if (node == NULL) return(ret); | 1422 if (node == NULL) return(ret); |
1418 if (last == NULL) { | 1423 if (last == NULL) { |
1419 » » last = ret = node; | 1424 » » ret = node; |
1420 } else { | 1425 } else { |
1421 » » last = xmlAddNextSibling(last, node); | 1426 » » xmlAddNextSibling(last, node); |
1422 } | 1427 } |
1423 } | 1428 } |
1424 } | 1429 } |
1425 return(ret); | 1430 return(ret); |
1426 } | 1431 } |
1427 | 1432 |
1428 /** | 1433 /** |
1429 * xmlStringGetNodeList: | 1434 * xmlStringGetNodeList: |
1430 * @doc: the document | 1435 * @doc: the document |
1431 * @value: the value of the attribute | 1436 * @value: the value of the attribute |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 node->prev = last; | 1472 node->prev = last; |
1468 last = node; | 1473 last = node; |
1469 } | 1474 } |
1470 } | 1475 } |
1471 } | 1476 } |
1472 q = cur; | 1477 q = cur; |
1473 if ((cur[1] == '#') && (cur[2] == 'x')) { | 1478 if ((cur[1] == '#') && (cur[2] == 'x')) { |
1474 cur += 3; | 1479 cur += 3; |
1475 tmp = *cur; | 1480 tmp = *cur; |
1476 while (tmp != ';') { /* Non input consuming loop */ | 1481 while (tmp != ';') { /* Non input consuming loop */ |
1477 » » if ((tmp >= '0') && (tmp <= '9')) | 1482 » » if ((tmp >= '0') && (tmp <= '9')) |
1478 charval = charval * 16 + (tmp - '0'); | 1483 charval = charval * 16 + (tmp - '0'); |
1479 else if ((tmp >= 'a') && (tmp <= 'f')) | 1484 else if ((tmp >= 'a') && (tmp <= 'f')) |
1480 charval = charval * 16 + (tmp - 'a') + 10; | 1485 charval = charval * 16 + (tmp - 'a') + 10; |
1481 else if ((tmp >= 'A') && (tmp <= 'F')) | 1486 else if ((tmp >= 'A') && (tmp <= 'F')) |
1482 charval = charval * 16 + (tmp - 'A') + 10; | 1487 charval = charval * 16 + (tmp - 'A') + 10; |
1483 else { | 1488 else { |
1484 xmlTreeErr(XML_TREE_INVALID_HEX, (xmlNodePtr) doc, | 1489 xmlTreeErr(XML_TREE_INVALID_HEX, (xmlNodePtr) doc, |
1485 NULL); | 1490 NULL); |
1486 charval = 0; | 1491 charval = 0; |
1487 break; | 1492 break; |
1488 } | 1493 } |
1489 cur++; | 1494 cur++; |
1490 tmp = *cur; | 1495 tmp = *cur; |
1491 } | 1496 } |
1492 if (tmp == ';') | 1497 if (tmp == ';') |
1493 cur++; | 1498 cur++; |
1494 q = cur; | 1499 q = cur; |
1495 } else if (cur[1] == '#') { | 1500 } else if (cur[1] == '#') { |
1496 cur += 2; | 1501 cur += 2; |
1497 tmp = *cur; | 1502 tmp = *cur; |
1498 while (tmp != ';') { /* Non input consuming loops */ | 1503 while (tmp != ';') { /* Non input consuming loops */ |
1499 » » if ((tmp >= '0') && (tmp <= '9')) | 1504 » » if ((tmp >= '0') && (tmp <= '9')) |
1500 charval = charval * 10 + (tmp - '0'); | 1505 charval = charval * 10 + (tmp - '0'); |
1501 else { | 1506 else { |
1502 xmlTreeErr(XML_TREE_INVALID_DEC, (xmlNodePtr) doc, | 1507 xmlTreeErr(XML_TREE_INVALID_DEC, (xmlNodePtr) doc, |
1503 NULL); | 1508 NULL); |
1504 charval = 0; | 1509 charval = 0; |
1505 break; | 1510 break; |
1506 } | 1511 } |
1507 cur++; | 1512 cur++; |
1508 tmp = *cur; | 1513 tmp = *cur; |
1509 } | 1514 } |
(...skipping 21 matching lines...) Expand all Loading... |
1531 if ((ent != NULL) && | 1536 if ((ent != NULL) && |
1532 (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { | 1537 (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { |
1533 if (last == NULL) { | 1538 if (last == NULL) { |
1534 node = xmlNewDocText(doc, ent->content); | 1539 node = xmlNewDocText(doc, ent->content); |
1535 last = ret = node; | 1540 last = ret = node; |
1536 } else if (last->type != XML_TEXT_NODE) { | 1541 } else if (last->type != XML_TEXT_NODE) { |
1537 node = xmlNewDocText(doc, ent->content); | 1542 node = xmlNewDocText(doc, ent->content); |
1538 last = xmlAddNextSibling(last, node); | 1543 last = xmlAddNextSibling(last, node); |
1539 } else | 1544 } else |
1540 xmlNodeAddContent(last, ent->content); | 1545 xmlNodeAddContent(last, ent->content); |
1541 » » » | 1546 |
1542 } else { | 1547 } else { |
1543 /* | 1548 /* |
1544 * Create a new REFERENCE_REF node | 1549 * Create a new REFERENCE_REF node |
1545 */ | 1550 */ |
1546 node = xmlNewReference(doc, val); | 1551 node = xmlNewReference(doc, val); |
1547 if (node == NULL) { | 1552 if (node == NULL) { |
1548 if (val != NULL) xmlFree(val); | 1553 if (val != NULL) xmlFree(val); |
1549 return(ret); | 1554 return(ret); |
1550 } | 1555 } |
1551 else if ((ent != NULL) && (ent->children == NULL)) { | 1556 else if ((ent != NULL) && (ent->children == NULL)) { |
(...skipping 26 matching lines...) Expand all Loading... |
1578 len = xmlCopyCharMultiByte(buf, charval); | 1583 len = xmlCopyCharMultiByte(buf, charval); |
1579 buf[len] = 0; | 1584 buf[len] = 0; |
1580 node = xmlNewDocText(doc, buf); | 1585 node = xmlNewDocText(doc, buf); |
1581 if (node != NULL) { | 1586 if (node != NULL) { |
1582 if (last == NULL) { | 1587 if (last == NULL) { |
1583 last = ret = node; | 1588 last = ret = node; |
1584 } else { | 1589 } else { |
1585 last = xmlAddNextSibling(last, node); | 1590 last = xmlAddNextSibling(last, node); |
1586 } | 1591 } |
1587 } | 1592 } |
1588 | |
1589 charval = 0; | |
1590 } | 1593 } |
1591 } else | 1594 } else |
1592 cur++; | 1595 cur++; |
1593 } | 1596 } |
1594 if ((cur != q) || (ret == NULL)) { | 1597 if ((cur != q) || (ret == NULL)) { |
1595 /* | 1598 /* |
1596 * Handle the last piece of text. | 1599 * Handle the last piece of text. |
1597 */ | 1600 */ |
1598 if ((last != NULL) && (last->type == XML_TEXT_NODE)) { | 1601 if ((last != NULL) && (last->type == XML_TEXT_NODE)) { |
1599 xmlNodeAddContentLen(last, q, cur - q); | 1602 xmlNodeAddContentLen(last, q, cur - q); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1789 xmlFree((xmlChar *) name); | 1792 xmlFree((xmlChar *) name); |
1790 return (NULL); | 1793 return (NULL); |
1791 } | 1794 } |
1792 | 1795 |
1793 /* | 1796 /* |
1794 * Allocate a new property and fill the fields. | 1797 * Allocate a new property and fill the fields. |
1795 */ | 1798 */ |
1796 cur = (xmlAttrPtr) xmlMalloc(sizeof(xmlAttr)); | 1799 cur = (xmlAttrPtr) xmlMalloc(sizeof(xmlAttr)); |
1797 if (cur == NULL) { | 1800 if (cur == NULL) { |
1798 if ((eatname == 1) && | 1801 if ((eatname == 1) && |
1799 » ((node->doc == NULL) || | 1802 » ((node == NULL) || (node->doc == NULL) || |
1800 (!(xmlDictOwns(node->doc->dict, name))))) | 1803 (!(xmlDictOwns(node->doc->dict, name))))) |
1801 xmlFree((xmlChar *) name); | 1804 xmlFree((xmlChar *) name); |
1802 xmlTreeErrMemory("building attribute"); | 1805 xmlTreeErrMemory("building attribute"); |
1803 return (NULL); | 1806 return (NULL); |
1804 } | 1807 } |
1805 memset(cur, 0, sizeof(xmlAttr)); | 1808 memset(cur, 0, sizeof(xmlAttr)); |
1806 cur->type = XML_ATTRIBUTE_NODE; | 1809 cur->type = XML_ATTRIBUTE_NODE; |
1807 | 1810 |
1808 cur->parent = node; | 1811 cur->parent = node; |
1809 if (node != NULL) { | 1812 if (node != NULL) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1849 } else { | 1852 } else { |
1850 xmlAttrPtr prev = node->properties; | 1853 xmlAttrPtr prev = node->properties; |
1851 | 1854 |
1852 while (prev->next != NULL) | 1855 while (prev->next != NULL) |
1853 prev = prev->next; | 1856 prev = prev->next; |
1854 prev->next = cur; | 1857 prev->next = cur; |
1855 cur->prev = prev; | 1858 cur->prev = prev; |
1856 } | 1859 } |
1857 } | 1860 } |
1858 | 1861 |
1859 if (xmlIsID((node == NULL) ? NULL : node->doc, node, cur) == 1) | 1862 if ((value != NULL) && (node != NULL) && |
| 1863 (xmlIsID(node->doc, node, cur) == 1)) |
1860 xmlAddID(NULL, node->doc, value, cur); | 1864 xmlAddID(NULL, node->doc, value, cur); |
1861 | 1865 |
1862 if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) | 1866 if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
1863 xmlRegisterNodeDefaultValue((xmlNodePtr) cur); | 1867 xmlRegisterNodeDefaultValue((xmlNodePtr) cur); |
1864 return (cur); | 1868 return (cur); |
1865 } | 1869 } |
1866 | 1870 |
1867 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_HTML_ENABLED) || \ | 1871 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_HTML_ENABLED) || \ |
1868 defined(LIBXML_SCHEMAS_ENABLED) | 1872 defined(LIBXML_SCHEMAS_ENABLED) |
1869 /** | 1873 /** |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1969 xmlTreeErrMemory("building attribute"); | 1973 xmlTreeErrMemory("building attribute"); |
1970 return(NULL); | 1974 return(NULL); |
1971 } | 1975 } |
1972 memset(cur, 0, sizeof(xmlAttr)); | 1976 memset(cur, 0, sizeof(xmlAttr)); |
1973 cur->type = XML_ATTRIBUTE_NODE; | 1977 cur->type = XML_ATTRIBUTE_NODE; |
1974 | 1978 |
1975 if ((doc != NULL) && (doc->dict != NULL)) | 1979 if ((doc != NULL) && (doc->dict != NULL)) |
1976 cur->name = xmlDictLookup(doc->dict, name, -1); | 1980 cur->name = xmlDictLookup(doc->dict, name, -1); |
1977 else | 1981 else |
1978 cur->name = xmlStrdup(name); | 1982 cur->name = xmlStrdup(name); |
1979 cur->doc = doc; | 1983 cur->doc = doc; |
1980 if (value != NULL) { | 1984 if (value != NULL) { |
1981 xmlNodePtr tmp; | 1985 xmlNodePtr tmp; |
1982 | 1986 |
1983 cur->children = xmlStringGetNodeList(doc, value); | 1987 cur->children = xmlStringGetNodeList(doc, value); |
1984 cur->last = NULL; | 1988 cur->last = NULL; |
1985 | 1989 |
1986 tmp = cur->children; | 1990 tmp = cur->children; |
1987 while (tmp != NULL) { | 1991 while (tmp != NULL) { |
1988 tmp->parent = (xmlNodePtr) cur; | 1992 tmp->parent = (xmlNodePtr) cur; |
1989 if (tmp->next == NULL) | 1993 if (tmp->next == NULL) |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2176 /* | 2180 /* |
2177 * Allocate a new node and fill the fields. | 2181 * Allocate a new node and fill the fields. |
2178 */ | 2182 */ |
2179 cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); | 2183 cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
2180 if (cur == NULL) { | 2184 if (cur == NULL) { |
2181 xmlTreeErrMemory("building node"); | 2185 xmlTreeErrMemory("building node"); |
2182 return(NULL); | 2186 return(NULL); |
2183 } | 2187 } |
2184 memset(cur, 0, sizeof(xmlNode)); | 2188 memset(cur, 0, sizeof(xmlNode)); |
2185 cur->type = XML_ELEMENT_NODE; | 2189 cur->type = XML_ELEMENT_NODE; |
2186 | 2190 |
2187 cur->name = xmlStrdup(name); | 2191 cur->name = xmlStrdup(name); |
2188 cur->ns = ns; | 2192 cur->ns = ns; |
2189 | 2193 |
2190 if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) | 2194 if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
2191 xmlRegisterNodeDefaultValue(cur); | 2195 xmlRegisterNodeDefaultValue(cur); |
2192 return(cur); | 2196 return(cur); |
2193 } | 2197 } |
2194 | 2198 |
2195 /** | 2199 /** |
2196 * xmlNewNodeEatName: | 2200 * xmlNewNodeEatName: |
(...skipping 22 matching lines...) Expand all Loading... |
2219 * Allocate a new node and fill the fields. | 2223 * Allocate a new node and fill the fields. |
2220 */ | 2224 */ |
2221 cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); | 2225 cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
2222 if (cur == NULL) { | 2226 if (cur == NULL) { |
2223 xmlTreeErrMemory("building node"); | 2227 xmlTreeErrMemory("building node"); |
2224 /* we can't check here that name comes from the doc dictionnary */ | 2228 /* we can't check here that name comes from the doc dictionnary */ |
2225 return(NULL); | 2229 return(NULL); |
2226 } | 2230 } |
2227 memset(cur, 0, sizeof(xmlNode)); | 2231 memset(cur, 0, sizeof(xmlNode)); |
2228 cur->type = XML_ELEMENT_NODE; | 2232 cur->type = XML_ELEMENT_NODE; |
2229 | 2233 |
2230 cur->name = name; | 2234 cur->name = name; |
2231 cur->ns = ns; | 2235 cur->ns = ns; |
2232 | 2236 |
2233 if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) | 2237 if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
2234 xmlRegisterNodeDefaultValue((xmlNodePtr)cur); | 2238 xmlRegisterNodeDefaultValue((xmlNodePtr)cur); |
2235 return(cur); | 2239 return(cur); |
2236 } | 2240 } |
2237 | 2241 |
2238 /** | 2242 /** |
2239 * xmlNewDocNode: | 2243 * xmlNewDocNode: |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2407 * @ns: a namespace if any | 2411 * @ns: a namespace if any |
2408 * @name: the name of the child | 2412 * @name: the name of the child |
2409 * @content: the text content of the child if any. | 2413 * @content: the text content of the child if any. |
2410 * | 2414 * |
2411 * Creation of a new child element, added at the end of @parent children list. | 2415 * Creation of a new child element, added at the end of @parent children list. |
2412 * @ns and @content parameters are optional (NULL). If @ns is NULL, the newly | 2416 * @ns and @content parameters are optional (NULL). If @ns is NULL, the newly |
2413 * created element inherits the namespace of @parent. If @content is non NULL, | 2417 * created element inherits the namespace of @parent. If @content is non NULL, |
2414 * a child TEXT node will be created containing the string @content. | 2418 * a child TEXT node will be created containing the string @content. |
2415 * NOTE: Use xmlNewChild() if @content will contain entities that need to be | 2419 * NOTE: Use xmlNewChild() if @content will contain entities that need to be |
2416 * preserved. Use this function, xmlNewTextChild(), if you need to ensure that | 2420 * preserved. Use this function, xmlNewTextChild(), if you need to ensure that |
2417 * reserved XML chars that might appear in @content, such as the ampersand, | 2421 * reserved XML chars that might appear in @content, such as the ampersand, |
2418 * greater-than or less-than signs, are automatically replaced by their XML | 2422 * greater-than or less-than signs, are automatically replaced by their XML |
2419 * escaped entity representations. | 2423 * escaped entity representations. |
2420 * | 2424 * |
2421 * Returns a pointer to the new node object. | 2425 * Returns a pointer to the new node object. |
2422 */ | 2426 */ |
2423 xmlNodePtr | 2427 xmlNodePtr |
2424 xmlNewTextChild(xmlNodePtr parent, xmlNsPtr ns, | 2428 xmlNewTextChild(xmlNodePtr parent, xmlNsPtr ns, |
2425 const xmlChar *name, const xmlChar *content) { | 2429 const xmlChar *name, const xmlChar *content) { |
2426 xmlNodePtr cur, prev; | 2430 xmlNodePtr cur, prev; |
2427 | 2431 |
2428 if (parent == NULL) { | 2432 if (parent == NULL) { |
2429 #ifdef DEBUG_TREE | 2433 #ifdef DEBUG_TREE |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2857 cur->prev = prev; | 2861 cur->prev = prev; |
2858 parent->last = cur; | 2862 parent->last = cur; |
2859 } | 2863 } |
2860 | 2864 |
2861 return(cur); | 2865 return(cur); |
2862 } | 2866 } |
2863 #endif /* LIBXML_TREE_ENABLED */ | 2867 #endif /* LIBXML_TREE_ENABLED */ |
2864 | 2868 |
2865 /** | 2869 /** |
2866 * xmlAddPropSibling: | 2870 * xmlAddPropSibling: |
2867 * @prev: the attribute to which @prop is added after | 2871 * @prev: the attribute to which @prop is added after |
2868 * @cur: the base attribute passed to calling function | 2872 * @cur: the base attribute passed to calling function |
2869 * @prop: the new attribute | 2873 * @prop: the new attribute |
2870 * | 2874 * |
2871 * Add a new attribute after @prev using @cur as base attribute. | 2875 * Add a new attribute after @prev using @cur as base attribute. |
2872 * When inserting before @cur, @prev is passed as @cur->prev. | 2876 * When inserting before @cur, @prev is passed as @cur->prev. |
2873 * When inserting after @cur, @prev is passed as @cur. | 2877 * When inserting after @cur, @prev is passed as @cur. |
2874 * If an existing attribute is found it is detroyed prior to adding @prop. | 2878 * If an existing attribute is found it is detroyed prior to adding @prop. |
2875 * | 2879 * |
2876 * Returns the attribute being inserted or NULL in case of error. | 2880 * Returns the attribute being inserted or NULL in case of error. |
2877 */ | 2881 */ |
2878 static xmlNodePtr | 2882 static xmlNodePtr |
2879 xmlAddPropSibling(xmlNodePtr prev, xmlNodePtr cur, xmlNodePtr prop) { | 2883 xmlAddPropSibling(xmlNodePtr prev, xmlNodePtr cur, xmlNodePtr prop) { |
2880 xmlAttrPtr attr; | 2884 xmlAttrPtr attr; |
2881 | 2885 |
2882 if (cur->type != XML_ATTRIBUTE_NODE) | 2886 if (cur->type != XML_ATTRIBUTE_NODE) |
2883 return(NULL); | 2887 return(NULL); |
2884 | 2888 |
(...skipping 29 matching lines...) Expand all Loading... |
2914 /** | 2918 /** |
2915 * xmlAddNextSibling: | 2919 * xmlAddNextSibling: |
2916 * @cur: the child node | 2920 * @cur: the child node |
2917 * @elem: the new node | 2921 * @elem: the new node |
2918 * | 2922 * |
2919 * Add a new node @elem as the next sibling of @cur | 2923 * Add a new node @elem as the next sibling of @cur |
2920 * If the new node was already inserted in a document it is | 2924 * If the new node was already inserted in a document it is |
2921 * first unlinked from its existing context. | 2925 * first unlinked from its existing context. |
2922 * As a result of text merging @elem may be freed. | 2926 * As a result of text merging @elem may be freed. |
2923 * If the new node is ATTRIBUTE, it is added into properties instead of children
. | 2927 * If the new node is ATTRIBUTE, it is added into properties instead of children
. |
2924 * If there is an attribute with equal name, it is first destroyed. | 2928 * If there is an attribute with equal name, it is first destroyed. |
2925 * | 2929 * |
2926 * Returns the new node or NULL in case of error. | 2930 * Returns the new node or NULL in case of error. |
2927 */ | 2931 */ |
2928 xmlNodePtr | 2932 xmlNodePtr |
2929 xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) { | 2933 xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) { |
2930 if (cur == NULL) { | 2934 if (cur == NULL) { |
2931 #ifdef DEBUG_TREE | 2935 #ifdef DEBUG_TREE |
2932 xmlGenericError(xmlGenericErrorContext, | 2936 xmlGenericError(xmlGenericErrorContext, |
2933 "xmlAddNextSibling : cur == NULL\n"); | 2937 "xmlAddNextSibling : cur == NULL\n"); |
2934 #endif | 2938 #endif |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2992 /** | 2996 /** |
2993 * xmlAddPrevSibling: | 2997 * xmlAddPrevSibling: |
2994 * @cur: the child node | 2998 * @cur: the child node |
2995 * @elem: the new node | 2999 * @elem: the new node |
2996 * | 3000 * |
2997 * Add a new node @elem as the previous sibling of @cur | 3001 * Add a new node @elem as the previous sibling of @cur |
2998 * merging adjacent TEXT nodes (@elem may be freed) | 3002 * merging adjacent TEXT nodes (@elem may be freed) |
2999 * If the new node was already inserted in a document it is | 3003 * If the new node was already inserted in a document it is |
3000 * first unlinked from its existing context. | 3004 * first unlinked from its existing context. |
3001 * If the new node is ATTRIBUTE, it is added into properties instead of children
. | 3005 * If the new node is ATTRIBUTE, it is added into properties instead of children
. |
3002 * If there is an attribute with equal name, it is first destroyed. | 3006 * If there is an attribute with equal name, it is first destroyed. |
3003 * | 3007 * |
3004 * Returns the new node or NULL in case of error. | 3008 * Returns the new node or NULL in case of error. |
3005 */ | 3009 */ |
3006 xmlNodePtr | 3010 xmlNodePtr |
3007 xmlAddPrevSibling(xmlNodePtr cur, xmlNodePtr elem) { | 3011 xmlAddPrevSibling(xmlNodePtr cur, xmlNodePtr elem) { |
3008 if (cur == NULL) { | 3012 if (cur == NULL) { |
3009 #ifdef DEBUG_TREE | 3013 #ifdef DEBUG_TREE |
3010 xmlGenericError(xmlGenericErrorContext, | 3014 xmlGenericError(xmlGenericErrorContext, |
3011 "xmlAddPrevSibling : cur == NULL\n"); | 3015 "xmlAddPrevSibling : cur == NULL\n"); |
3012 #endif | 3016 #endif |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3092 } | 3096 } |
3093 | 3097 |
3094 if (elem == NULL) { | 3098 if (elem == NULL) { |
3095 #ifdef DEBUG_TREE | 3099 #ifdef DEBUG_TREE |
3096 xmlGenericError(xmlGenericErrorContext, | 3100 xmlGenericError(xmlGenericErrorContext, |
3097 "xmlAddSibling : elem == NULL\n"); | 3101 "xmlAddSibling : elem == NULL\n"); |
3098 #endif | 3102 #endif |
3099 return(NULL); | 3103 return(NULL); |
3100 } | 3104 } |
3101 | 3105 |
| 3106 if (cur == elem) { |
| 3107 #ifdef DEBUG_TREE |
| 3108 xmlGenericError(xmlGenericErrorContext, |
| 3109 "xmlAddSibling : cur == elem\n"); |
| 3110 #endif |
| 3111 return(NULL); |
| 3112 } |
| 3113 |
3102 /* | 3114 /* |
3103 * Constant time is we can rely on the ->parent->last to find | 3115 * Constant time is we can rely on the ->parent->last to find |
3104 * the last sibling. | 3116 * the last sibling. |
3105 */ | 3117 */ |
3106 if ((cur->type != XML_ATTRIBUTE_NODE) && (cur->parent != NULL) && | 3118 if ((cur->type != XML_ATTRIBUTE_NODE) && (cur->parent != NULL) && |
3107 (cur->parent->children != NULL) && | 3119 (cur->parent->children != NULL) && |
3108 (cur->parent->last != NULL) && | 3120 (cur->parent->last != NULL) && |
3109 (cur->parent->last->next == NULL)) { | 3121 (cur->parent->last->next == NULL)) { |
3110 cur = cur->parent->last; | 3122 cur = cur->parent->last; |
3111 } else { | 3123 } else { |
3112 while (cur->next != NULL) cur = cur->next; | 3124 while (cur->next != NULL) cur = cur->next; |
3113 } | 3125 } |
3114 | 3126 |
3115 xmlUnlinkNode(elem); | 3127 xmlUnlinkNode(elem); |
3116 | 3128 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3178 /* | 3190 /* |
3179 * add the first element at the end of the children list. | 3191 * add the first element at the end of the children list. |
3180 */ | 3192 */ |
3181 | 3193 |
3182 if (parent->children == NULL) { | 3194 if (parent->children == NULL) { |
3183 parent->children = cur; | 3195 parent->children = cur; |
3184 } else { | 3196 } else { |
3185 /* | 3197 /* |
3186 * If cur and parent->last both are TEXT nodes, then merge them. | 3198 * If cur and parent->last both are TEXT nodes, then merge them. |
3187 */ | 3199 */ |
3188 » if ((cur->type == XML_TEXT_NODE) && | 3200 » if ((cur->type == XML_TEXT_NODE) && |
3189 (parent->last->type == XML_TEXT_NODE) && | 3201 (parent->last->type == XML_TEXT_NODE) && |
3190 (cur->name == parent->last->name)) { | 3202 (cur->name == parent->last->name)) { |
3191 » xmlNodeAddContent(parent->last, cur->content); | 3203 » xmlNodeAddContent(parent->last, cur->content); |
3192 /* | 3204 /* |
3193 * if it's the only child, nothing more to be done. | 3205 * if it's the only child, nothing more to be done. |
3194 */ | 3206 */ |
3195 if (cur->next == NULL) { | 3207 if (cur->next == NULL) { |
3196 xmlFreeNode(cur); | 3208 xmlFreeNode(cur); |
3197 return(parent->last); | 3209 return(parent->last); |
3198 } | 3210 } |
3199 prev = cur; | 3211 prev = cur; |
3200 cur = cur->next; | 3212 cur = cur->next; |
3201 xmlFreeNode(prev); | 3213 xmlFreeNode(prev); |
3202 } | 3214 } |
3203 prev = parent->last; | 3215 prev = parent->last; |
3204 prev->next = cur; | 3216 prev->next = cur; |
3205 cur->prev = prev; | 3217 cur->prev = prev; |
3206 } | 3218 } |
3207 while (cur->next != NULL) { | 3219 while (cur->next != NULL) { |
3208 cur->parent = parent; | 3220 cur->parent = parent; |
3209 if (cur->doc != parent->doc) { | 3221 if (cur->doc != parent->doc) { |
3210 xmlSetTreeDoc(cur, parent->doc); | 3222 xmlSetTreeDoc(cur, parent->doc); |
3211 } | 3223 } |
3212 cur = cur->next; | 3224 cur = cur->next; |
3213 } | 3225 } |
3214 cur->parent = parent; | 3226 cur->parent = parent; |
3215 cur->doc = parent->doc; /* the parent may not be linked to a doc ! */ | 3227 /* the parent may not be linked to a doc ! */ |
| 3228 if (cur->doc != parent->doc) { |
| 3229 xmlSetTreeDoc(cur, parent->doc); |
| 3230 } |
3216 parent->last = cur; | 3231 parent->last = cur; |
3217 | 3232 |
3218 return(cur); | 3233 return(cur); |
3219 } | 3234 } |
3220 | 3235 |
3221 /** | 3236 /** |
3222 * xmlAddChild: | 3237 * xmlAddChild: |
3223 * @parent: the parent node | 3238 * @parent: the parent node |
3224 * @cur: the child node | 3239 * @cur: the child node |
3225 * | 3240 * |
3226 * Add a new node to @parent, at the end of the child (or property) list | 3241 * Add a new node to @parent, at the end of the child (or property) list |
3227 * merging adjacent TEXT nodes (in which case @cur is freed) | 3242 * merging adjacent TEXT nodes (in which case @cur is freed) |
3228 * If the new node is ATTRIBUTE, it is added into properties instead of children
. | 3243 * If the new node is ATTRIBUTE, it is added into properties instead of children
. |
3229 * If there is an attribute with equal name, it is first destroyed. | 3244 * If there is an attribute with equal name, it is first destroyed. |
3230 * | 3245 * |
3231 * Returns the child or NULL in case of error. | 3246 * Returns the child or NULL in case of error. |
3232 */ | 3247 */ |
3233 xmlNodePtr | 3248 xmlNodePtr |
3234 xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { | 3249 xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { |
3235 xmlNodePtr prev; | 3250 xmlNodePtr prev; |
3236 | 3251 |
3237 if (parent == NULL) { | 3252 if (parent == NULL) { |
3238 #ifdef DEBUG_TREE | 3253 #ifdef DEBUG_TREE |
3239 xmlGenericError(xmlGenericErrorContext, | 3254 xmlGenericError(xmlGenericErrorContext, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3298 if ((parent->type == XML_TEXT_NODE) && | 3313 if ((parent->type == XML_TEXT_NODE) && |
3299 (parent->content != NULL) && | 3314 (parent->content != NULL) && |
3300 (parent != cur)) { | 3315 (parent != cur)) { |
3301 xmlNodeAddContent(parent, cur->content); | 3316 xmlNodeAddContent(parent, cur->content); |
3302 xmlFreeNode(cur); | 3317 xmlFreeNode(cur); |
3303 return(parent); | 3318 return(parent); |
3304 } | 3319 } |
3305 if (cur->type == XML_ATTRIBUTE_NODE) { | 3320 if (cur->type == XML_ATTRIBUTE_NODE) { |
3306 if (parent->type != XML_ELEMENT_NODE) | 3321 if (parent->type != XML_ELEMENT_NODE) |
3307 return(NULL); | 3322 return(NULL); |
3308 » if (parent->properties == NULL) { | 3323 » if (parent->properties != NULL) { |
3309 » parent->properties = (xmlAttrPtr) cur; | |
3310 » } else { | |
3311 /* check if an attribute with the same name exists */ | 3324 /* check if an attribute with the same name exists */ |
3312 xmlAttrPtr lastattr; | 3325 xmlAttrPtr lastattr; |
3313 | 3326 |
3314 if (cur->ns == NULL) | 3327 if (cur->ns == NULL) |
3315 lastattr = xmlHasNsProp(parent, cur->name, NULL); | 3328 lastattr = xmlHasNsProp(parent, cur->name, NULL); |
3316 else | 3329 else |
3317 lastattr = xmlHasNsProp(parent, cur->name, cur->ns->href); | 3330 lastattr = xmlHasNsProp(parent, cur->name, cur->ns->href); |
3318 if ((lastattr != NULL) && (lastattr != (xmlAttrPtr) cur) && (lastatt
r->type != XML_ATTRIBUTE_DECL)) { | 3331 if ((lastattr != NULL) && (lastattr != (xmlAttrPtr) cur) && (lastatt
r->type != XML_ATTRIBUTE_DECL)) { |
3319 /* different instance, destroy it (attributes must be unique) */ | 3332 /* different instance, destroy it (attributes must be unique) */ |
3320 xmlUnlinkNode((xmlNodePtr) lastattr); | 3333 xmlUnlinkNode((xmlNodePtr) lastattr); |
3321 xmlFreeProp(lastattr); | 3334 xmlFreeProp(lastattr); |
3322 } | 3335 } |
3323 if (lastattr == (xmlAttrPtr) cur) | 3336 if (lastattr == (xmlAttrPtr) cur) |
3324 return(cur); | 3337 return(cur); |
| 3338 |
| 3339 } |
| 3340 if (parent->properties == NULL) { |
| 3341 parent->properties = (xmlAttrPtr) cur; |
| 3342 } else { |
3325 /* find the end */ | 3343 /* find the end */ |
3326 » lastattr = parent->properties; | 3344 » xmlAttrPtr lastattr = parent->properties; |
3327 while (lastattr->next != NULL) { | 3345 while (lastattr->next != NULL) { |
3328 lastattr = lastattr->next; | 3346 lastattr = lastattr->next; |
3329 } | 3347 } |
3330 lastattr->next = (xmlAttrPtr) cur; | 3348 lastattr->next = (xmlAttrPtr) cur; |
3331 ((xmlAttrPtr) cur)->prev = lastattr; | 3349 ((xmlAttrPtr) cur)->prev = lastattr; |
3332 } | 3350 } |
3333 } else { | 3351 } else { |
3334 if (parent->children == NULL) { | 3352 if (parent->children == NULL) { |
3335 parent->children = cur; | 3353 parent->children = cur; |
3336 parent->last = cur; | 3354 parent->last = cur; |
(...skipping 19 matching lines...) Expand all Loading... |
3356 if (parent == NULL) { | 3374 if (parent == NULL) { |
3357 #ifdef DEBUG_TREE | 3375 #ifdef DEBUG_TREE |
3358 xmlGenericError(xmlGenericErrorContext, | 3376 xmlGenericError(xmlGenericErrorContext, |
3359 "xmlGetLastChild : parent == NULL\n"); | 3377 "xmlGetLastChild : parent == NULL\n"); |
3360 #endif | 3378 #endif |
3361 return(NULL); | 3379 return(NULL); |
3362 } | 3380 } |
3363 return(parent->last); | 3381 return(parent->last); |
3364 } | 3382 } |
3365 | 3383 |
| 3384 #ifdef LIBXML_TREE_ENABLED |
| 3385 /* |
| 3386 * 5 interfaces from DOM ElementTraversal |
| 3387 */ |
| 3388 |
| 3389 /** |
| 3390 * xmlChildElementCount: |
| 3391 * @parent: the parent node |
| 3392 * |
| 3393 * Finds the current number of child nodes of that element which are |
| 3394 * element nodes. |
| 3395 * Note the handling of entities references is different than in |
| 3396 * the W3C DOM element traversal spec since we don't have back reference |
| 3397 * from entities content to entities references. |
| 3398 * |
| 3399 * Returns the count of element child or 0 if not available |
| 3400 */ |
| 3401 unsigned long |
| 3402 xmlChildElementCount(xmlNodePtr parent) { |
| 3403 unsigned long ret = 0; |
| 3404 xmlNodePtr cur = NULL; |
| 3405 |
| 3406 if (parent == NULL) |
| 3407 return(0); |
| 3408 switch (parent->type) { |
| 3409 case XML_ELEMENT_NODE: |
| 3410 case XML_ENTITY_NODE: |
| 3411 case XML_DOCUMENT_NODE: |
| 3412 case XML_HTML_DOCUMENT_NODE: |
| 3413 cur = parent->children; |
| 3414 break; |
| 3415 default: |
| 3416 return(0); |
| 3417 } |
| 3418 while (cur != NULL) { |
| 3419 if (cur->type == XML_ELEMENT_NODE) |
| 3420 ret++; |
| 3421 cur = cur->next; |
| 3422 } |
| 3423 return(ret); |
| 3424 } |
| 3425 |
| 3426 /** |
| 3427 * xmlFirstElementChild: |
| 3428 * @parent: the parent node |
| 3429 * |
| 3430 * Finds the first child node of that element which is a Element node |
| 3431 * Note the handling of entities references is different than in |
| 3432 * the W3C DOM element traversal spec since we don't have back reference |
| 3433 * from entities content to entities references. |
| 3434 * |
| 3435 * Returns the first element child or NULL if not available |
| 3436 */ |
| 3437 xmlNodePtr |
| 3438 xmlFirstElementChild(xmlNodePtr parent) { |
| 3439 xmlNodePtr cur = NULL; |
| 3440 |
| 3441 if (parent == NULL) |
| 3442 return(NULL); |
| 3443 switch (parent->type) { |
| 3444 case XML_ELEMENT_NODE: |
| 3445 case XML_ENTITY_NODE: |
| 3446 case XML_DOCUMENT_NODE: |
| 3447 case XML_HTML_DOCUMENT_NODE: |
| 3448 cur = parent->children; |
| 3449 break; |
| 3450 default: |
| 3451 return(NULL); |
| 3452 } |
| 3453 while (cur != NULL) { |
| 3454 if (cur->type == XML_ELEMENT_NODE) |
| 3455 return(cur); |
| 3456 cur = cur->next; |
| 3457 } |
| 3458 return(NULL); |
| 3459 } |
| 3460 |
| 3461 /** |
| 3462 * xmlLastElementChild: |
| 3463 * @parent: the parent node |
| 3464 * |
| 3465 * Finds the last child node of that element which is a Element node |
| 3466 * Note the handling of entities references is different than in |
| 3467 * the W3C DOM element traversal spec since we don't have back reference |
| 3468 * from entities content to entities references. |
| 3469 * |
| 3470 * Returns the last element child or NULL if not available |
| 3471 */ |
| 3472 xmlNodePtr |
| 3473 xmlLastElementChild(xmlNodePtr parent) { |
| 3474 xmlNodePtr cur = NULL; |
| 3475 |
| 3476 if (parent == NULL) |
| 3477 return(NULL); |
| 3478 switch (parent->type) { |
| 3479 case XML_ELEMENT_NODE: |
| 3480 case XML_ENTITY_NODE: |
| 3481 case XML_DOCUMENT_NODE: |
| 3482 case XML_HTML_DOCUMENT_NODE: |
| 3483 cur = parent->last; |
| 3484 break; |
| 3485 default: |
| 3486 return(NULL); |
| 3487 } |
| 3488 while (cur != NULL) { |
| 3489 if (cur->type == XML_ELEMENT_NODE) |
| 3490 return(cur); |
| 3491 cur = cur->prev; |
| 3492 } |
| 3493 return(NULL); |
| 3494 } |
| 3495 |
| 3496 /** |
| 3497 * xmlPreviousElementSibling: |
| 3498 * @node: the current node |
| 3499 * |
| 3500 * Finds the first closest previous sibling of the node which is an |
| 3501 * element node. |
| 3502 * Note the handling of entities references is different than in |
| 3503 * the W3C DOM element traversal spec since we don't have back reference |
| 3504 * from entities content to entities references. |
| 3505 * |
| 3506 * Returns the previous element sibling or NULL if not available |
| 3507 */ |
| 3508 xmlNodePtr |
| 3509 xmlPreviousElementSibling(xmlNodePtr node) { |
| 3510 if (node == NULL) |
| 3511 return(NULL); |
| 3512 switch (node->type) { |
| 3513 case XML_ELEMENT_NODE: |
| 3514 case XML_TEXT_NODE: |
| 3515 case XML_CDATA_SECTION_NODE: |
| 3516 case XML_ENTITY_REF_NODE: |
| 3517 case XML_ENTITY_NODE: |
| 3518 case XML_PI_NODE: |
| 3519 case XML_COMMENT_NODE: |
| 3520 case XML_XINCLUDE_START: |
| 3521 case XML_XINCLUDE_END: |
| 3522 node = node->prev; |
| 3523 break; |
| 3524 default: |
| 3525 return(NULL); |
| 3526 } |
| 3527 while (node != NULL) { |
| 3528 if (node->type == XML_ELEMENT_NODE) |
| 3529 return(node); |
| 3530 node = node->prev; |
| 3531 } |
| 3532 return(NULL); |
| 3533 } |
| 3534 |
| 3535 /** |
| 3536 * xmlNextElementSibling: |
| 3537 * @node: the current node |
| 3538 * |
| 3539 * Finds the first closest next sibling of the node which is an |
| 3540 * element node. |
| 3541 * Note the handling of entities references is different than in |
| 3542 * the W3C DOM element traversal spec since we don't have back reference |
| 3543 * from entities content to entities references. |
| 3544 * |
| 3545 * Returns the next element sibling or NULL if not available |
| 3546 */ |
| 3547 xmlNodePtr |
| 3548 xmlNextElementSibling(xmlNodePtr node) { |
| 3549 if (node == NULL) |
| 3550 return(NULL); |
| 3551 switch (node->type) { |
| 3552 case XML_ELEMENT_NODE: |
| 3553 case XML_TEXT_NODE: |
| 3554 case XML_CDATA_SECTION_NODE: |
| 3555 case XML_ENTITY_REF_NODE: |
| 3556 case XML_ENTITY_NODE: |
| 3557 case XML_PI_NODE: |
| 3558 case XML_COMMENT_NODE: |
| 3559 case XML_DTD_NODE: |
| 3560 case XML_XINCLUDE_START: |
| 3561 case XML_XINCLUDE_END: |
| 3562 node = node->next; |
| 3563 break; |
| 3564 default: |
| 3565 return(NULL); |
| 3566 } |
| 3567 while (node != NULL) { |
| 3568 if (node->type == XML_ELEMENT_NODE) |
| 3569 return(node); |
| 3570 node = node->next; |
| 3571 } |
| 3572 return(NULL); |
| 3573 } |
| 3574 |
| 3575 #endif /* LIBXML_TREE_ENABLED */ |
| 3576 |
3366 /** | 3577 /** |
3367 * xmlFreeNodeList: | 3578 * xmlFreeNodeList: |
3368 * @cur: the first node in the list | 3579 * @cur: the first node in the list |
3369 * | 3580 * |
3370 * Free a node and all its siblings, this is a recursive behaviour, all | 3581 * Free a node and all its siblings, this is a recursive behaviour, all |
3371 * the children are freed too. | 3582 * the children are freed too. |
3372 */ | 3583 */ |
3373 void | 3584 void |
3374 xmlFreeNodeList(xmlNodePtr cur) { | 3585 xmlFreeNodeList(xmlNodePtr cur) { |
3375 xmlNodePtr next; | 3586 xmlNodePtr next; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3458 if (cur->type == XML_ATTRIBUTE_NODE) { | 3669 if (cur->type == XML_ATTRIBUTE_NODE) { |
3459 xmlFreeProp((xmlAttrPtr) cur); | 3670 xmlFreeProp((xmlAttrPtr) cur); |
3460 return; | 3671 return; |
3461 } | 3672 } |
3462 | 3673 |
3463 if ((__xmlRegisterCallbacks) && (xmlDeregisterNodeDefaultValue)) | 3674 if ((__xmlRegisterCallbacks) && (xmlDeregisterNodeDefaultValue)) |
3464 xmlDeregisterNodeDefaultValue(cur); | 3675 xmlDeregisterNodeDefaultValue(cur); |
3465 | 3676 |
3466 if (cur->doc != NULL) dict = cur->doc->dict; | 3677 if (cur->doc != NULL) dict = cur->doc->dict; |
3467 | 3678 |
| 3679 if (cur->type == XML_ENTITY_DECL) { |
| 3680 xmlEntityPtr ent = (xmlEntityPtr) cur; |
| 3681 DICT_FREE(ent->SystemID); |
| 3682 DICT_FREE(ent->ExternalID); |
| 3683 } |
3468 if ((cur->children != NULL) && | 3684 if ((cur->children != NULL) && |
3469 (cur->type != XML_ENTITY_REF_NODE)) | 3685 (cur->type != XML_ENTITY_REF_NODE)) |
3470 xmlFreeNodeList(cur->children); | 3686 xmlFreeNodeList(cur->children); |
3471 if (((cur->type == XML_ELEMENT_NODE) || | 3687 if (((cur->type == XML_ELEMENT_NODE) || |
3472 (cur->type == XML_XINCLUDE_START) || | 3688 (cur->type == XML_XINCLUDE_START) || |
3473 (cur->type == XML_XINCLUDE_END)) && | 3689 (cur->type == XML_XINCLUDE_END)) && |
3474 (cur->properties != NULL)) | 3690 (cur->properties != NULL)) |
3475 xmlFreePropList(cur->properties); | 3691 xmlFreePropList(cur->properties); |
3476 if ((cur->type != XML_ELEMENT_NODE) && | 3692 if ((cur->type != XML_ELEMENT_NODE) && |
3477 (cur->content != NULL) && | 3693 (cur->content != NULL) && |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3518 if (cur->type == XML_DTD_NODE) { | 3734 if (cur->type == XML_DTD_NODE) { |
3519 xmlDocPtr doc; | 3735 xmlDocPtr doc; |
3520 doc = cur->doc; | 3736 doc = cur->doc; |
3521 if (doc != NULL) { | 3737 if (doc != NULL) { |
3522 if (doc->intSubset == (xmlDtdPtr) cur) | 3738 if (doc->intSubset == (xmlDtdPtr) cur) |
3523 doc->intSubset = NULL; | 3739 doc->intSubset = NULL; |
3524 if (doc->extSubset == (xmlDtdPtr) cur) | 3740 if (doc->extSubset == (xmlDtdPtr) cur) |
3525 doc->extSubset = NULL; | 3741 doc->extSubset = NULL; |
3526 } | 3742 } |
3527 } | 3743 } |
| 3744 if (cur->type == XML_ENTITY_DECL) { |
| 3745 xmlDocPtr doc; |
| 3746 doc = cur->doc; |
| 3747 if (doc != NULL) { |
| 3748 if (doc->intSubset != NULL) { |
| 3749 if (xmlHashLookup(doc->intSubset->entities, cur->name) == cur) |
| 3750 xmlHashRemoveEntry(doc->intSubset->entities, cur->name, |
| 3751 NULL); |
| 3752 if (xmlHashLookup(doc->intSubset->pentities, cur->name) == cur) |
| 3753 xmlHashRemoveEntry(doc->intSubset->pentities, cur->name, |
| 3754 NULL); |
| 3755 } |
| 3756 if (doc->extSubset != NULL) { |
| 3757 if (xmlHashLookup(doc->extSubset->entities, cur->name) == cur) |
| 3758 xmlHashRemoveEntry(doc->extSubset->entities, cur->name, |
| 3759 NULL); |
| 3760 if (xmlHashLookup(doc->extSubset->pentities, cur->name) == cur) |
| 3761 xmlHashRemoveEntry(doc->extSubset->pentities, cur->name, |
| 3762 NULL); |
| 3763 } |
| 3764 } |
| 3765 } |
3528 if (cur->parent != NULL) { | 3766 if (cur->parent != NULL) { |
3529 xmlNodePtr parent; | 3767 xmlNodePtr parent; |
3530 parent = cur->parent; | 3768 parent = cur->parent; |
3531 if (cur->type == XML_ATTRIBUTE_NODE) { | 3769 if (cur->type == XML_ATTRIBUTE_NODE) { |
3532 if (parent->properties == (xmlAttrPtr) cur) | 3770 if (parent->properties == (xmlAttrPtr) cur) |
3533 parent->properties = ((xmlAttrPtr) cur)->next; | 3771 parent->properties = ((xmlAttrPtr) cur)->next; |
3534 } else { | 3772 } else { |
3535 if (parent->children == cur) | 3773 if (parent->children == cur) |
3536 parent->children = cur->next; | 3774 parent->children = cur->next; |
3537 if (parent->last == cur) | 3775 if (parent->last == cur) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3613 old->parent = NULL; | 3851 old->parent = NULL; |
3614 return(old); | 3852 return(old); |
3615 } | 3853 } |
3616 #endif /* LIBXML_TREE_ENABLED */ | 3854 #endif /* LIBXML_TREE_ENABLED */ |
3617 | 3855 |
3618 /************************************************************************ | 3856 /************************************************************************ |
3619 * * | 3857 * * |
3620 * Copy operations * | 3858 * Copy operations * |
3621 * * | 3859 * * |
3622 ************************************************************************/ | 3860 ************************************************************************/ |
3623 | 3861 |
3624 /** | 3862 /** |
3625 * xmlCopyNamespace: | 3863 * xmlCopyNamespace: |
3626 * @cur: the namespace | 3864 * @cur: the namespace |
3627 * | 3865 * |
3628 * Do a copy of the namespace. | 3866 * Do a copy of the namespace. |
3629 * | 3867 * |
3630 * Returns: a new #xmlNsPtr, or NULL in case of error. | 3868 * Returns: a new #xmlNsPtr, or NULL in case of error. |
3631 */ | 3869 */ |
3632 xmlNsPtr | 3870 xmlNsPtr |
3633 xmlCopyNamespace(xmlNsPtr cur) { | 3871 xmlCopyNamespace(xmlNsPtr cur) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3730 /* this is the nice case */ | 3968 /* this is the nice case */ |
3731 ret->ns = ns; | 3969 ret->ns = ns; |
3732 } else { | 3970 } else { |
3733 /* | 3971 /* |
3734 * we are in trouble: we need a new reconcilied namespace. | 3972 * we are in trouble: we need a new reconcilied namespace. |
3735 * This is expensive | 3973 * This is expensive |
3736 */ | 3974 */ |
3737 ret->ns = xmlNewReconciliedNs(target->doc, target, cur->ns); | 3975 ret->ns = xmlNewReconciliedNs(target->doc, target, cur->ns); |
3738 } | 3976 } |
3739 } | 3977 } |
3740 | 3978 |
3741 } else | 3979 } else |
3742 ret->ns = NULL; | 3980 ret->ns = NULL; |
3743 | 3981 |
3744 if (cur->children != NULL) { | 3982 if (cur->children != NULL) { |
3745 xmlNodePtr tmp; | 3983 xmlNodePtr tmp; |
3746 | 3984 |
3747 ret->children = xmlStaticCopyNodeList(cur->children, ret->doc, (xmlNodeP
tr) ret); | 3985 ret->children = xmlStaticCopyNodeList(cur->children, ret->doc, (xmlNodeP
tr) ret); |
3748 ret->last = NULL; | 3986 ret->last = NULL; |
3749 tmp = ret->children; | 3987 tmp = ret->children; |
3750 while (tmp != NULL) { | 3988 while (tmp != NULL) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3851 case XML_ENTITY_NODE: | 4089 case XML_ENTITY_NODE: |
3852 case XML_PI_NODE: | 4090 case XML_PI_NODE: |
3853 case XML_COMMENT_NODE: | 4091 case XML_COMMENT_NODE: |
3854 case XML_XINCLUDE_START: | 4092 case XML_XINCLUDE_START: |
3855 case XML_XINCLUDE_END: | 4093 case XML_XINCLUDE_END: |
3856 break; | 4094 break; |
3857 case XML_ATTRIBUTE_NODE: | 4095 case XML_ATTRIBUTE_NODE: |
3858 return((xmlNodePtr) xmlCopyPropInternal(doc, parent, (xmlAttrPtr
) node)); | 4096 return((xmlNodePtr) xmlCopyPropInternal(doc, parent, (xmlAttrPtr
) node)); |
3859 case XML_NAMESPACE_DECL: | 4097 case XML_NAMESPACE_DECL: |
3860 return((xmlNodePtr) xmlCopyNamespaceList((xmlNsPtr) node)); | 4098 return((xmlNodePtr) xmlCopyNamespaceList((xmlNsPtr) node)); |
3861 » | 4099 |
3862 case XML_DOCUMENT_NODE: | 4100 case XML_DOCUMENT_NODE: |
3863 case XML_HTML_DOCUMENT_NODE: | 4101 case XML_HTML_DOCUMENT_NODE: |
3864 #ifdef LIBXML_DOCB_ENABLED | 4102 #ifdef LIBXML_DOCB_ENABLED |
3865 case XML_DOCB_DOCUMENT_NODE: | 4103 case XML_DOCB_DOCUMENT_NODE: |
3866 #endif | 4104 #endif |
3867 #ifdef LIBXML_TREE_ENABLED | 4105 #ifdef LIBXML_TREE_ENABLED |
3868 return((xmlNodePtr) xmlCopyDoc((xmlDocPtr) node, extended)); | 4106 return((xmlNodePtr) xmlCopyDoc((xmlDocPtr) node, extended)); |
3869 #endif /* LIBXML_TREE_ENABLED */ | 4107 #endif /* LIBXML_TREE_ENABLED */ |
3870 case XML_DOCUMENT_TYPE_NODE: | 4108 case XML_DOCUMENT_TYPE_NODE: |
3871 case XML_NOTATION_NODE: | 4109 case XML_NOTATION_NODE: |
3872 case XML_DTD_NODE: | 4110 case XML_DTD_NODE: |
3873 case XML_ELEMENT_DECL: | 4111 case XML_ELEMENT_DECL: |
3874 case XML_ATTRIBUTE_DECL: | 4112 case XML_ATTRIBUTE_DECL: |
3875 case XML_ENTITY_DECL: | 4113 case XML_ENTITY_DECL: |
3876 return(NULL); | 4114 return(NULL); |
3877 } | 4115 } |
3878 | 4116 |
3879 /* | 4117 /* |
3880 * Allocate a new node and fill the fields. | 4118 * Allocate a new node and fill the fields. |
3881 */ | 4119 */ |
3882 ret = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); | 4120 ret = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
3883 if (ret == NULL) { | 4121 if (ret == NULL) { |
3884 xmlTreeErrMemory("copying node"); | 4122 xmlTreeErrMemory("copying node"); |
3885 return(NULL); | 4123 return(NULL); |
3886 } | 4124 } |
3887 memset(ret, 0, sizeof(xmlNode)); | 4125 memset(ret, 0, sizeof(xmlNode)); |
3888 ret->type = node->type; | 4126 ret->type = node->type; |
3889 | 4127 |
3890 ret->doc = doc; | 4128 ret->doc = doc; |
3891 ret->parent = parent; | 4129 ret->parent = parent; |
3892 if (node->name == xmlStringText) | 4130 if (node->name == xmlStringText) |
3893 ret->name = xmlStringText; | 4131 ret->name = xmlStringText; |
3894 else if (node->name == xmlStringTextNoenc) | 4132 else if (node->name == xmlStringTextNoenc) |
3895 ret->name = xmlStringTextNoenc; | 4133 ret->name = xmlStringTextNoenc; |
3896 else if (node->name == xmlStringComment) | 4134 else if (node->name == xmlStringComment) |
3897 ret->name = xmlStringComment; | 4135 ret->name = xmlStringComment; |
3898 else if (node->name != NULL) { | 4136 else if (node->name != NULL) { |
3899 if ((doc != NULL) && (doc->dict != NULL)) | 4137 if ((doc != NULL) && (doc->dict != NULL)) |
3900 ret->name = xmlDictLookup(doc->dict, node->name, -1); | 4138 ret->name = xmlDictLookup(doc->dict, node->name, -1); |
3901 else | 4139 else |
(...skipping 18 matching lines...) Expand all Loading... |
3920 * the deregister-node callback is called; so we register ret now alread
y | 4158 * the deregister-node callback is called; so we register ret now alread
y |
3921 */ | 4159 */ |
3922 if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) | 4160 if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) |
3923 xmlRegisterNodeDefaultValue((xmlNodePtr)ret); | 4161 xmlRegisterNodeDefaultValue((xmlNodePtr)ret); |
3924 | 4162 |
3925 tmp = xmlAddChild(parent, ret); | 4163 tmp = xmlAddChild(parent, ret); |
3926 /* node could have coalesced */ | 4164 /* node could have coalesced */ |
3927 if (tmp != ret) | 4165 if (tmp != ret) |
3928 return(tmp); | 4166 return(tmp); |
3929 } | 4167 } |
3930 | 4168 |
3931 if (!extended) | 4169 if (!extended) |
3932 goto out; | 4170 goto out; |
3933 if ((node->type == XML_ELEMENT_NODE) && (node->nsDef != NULL)) | 4171 if (((node->type == XML_ELEMENT_NODE) || |
| 4172 (node->type == XML_XINCLUDE_START)) && (node->nsDef != NULL)) |
3934 ret->nsDef = xmlCopyNamespaceList(node->nsDef); | 4173 ret->nsDef = xmlCopyNamespaceList(node->nsDef); |
3935 | 4174 |
3936 if (node->ns != NULL) { | 4175 if (node->ns != NULL) { |
3937 xmlNsPtr ns; | 4176 xmlNsPtr ns; |
3938 | 4177 |
3939 ns = xmlSearchNs(doc, ret, node->ns->prefix); | 4178 ns = xmlSearchNs(doc, ret, node->ns->prefix); |
3940 if (ns == NULL) { | 4179 if (ns == NULL) { |
3941 /* | 4180 /* |
3942 * Humm, we are copying an element whose namespace is defined | 4181 * Humm, we are copying an element whose namespace is defined |
3943 * out of the new tree scope. Search it in the original tree | 4182 * out of the new tree scope. Search it in the original tree |
3944 * and add it at the top of the new tree | 4183 * and add it at the top of the new tree |
3945 */ | 4184 */ |
3946 ns = xmlSearchNs(node->doc, node, node->ns->prefix); | 4185 ns = xmlSearchNs(node->doc, node, node->ns->prefix); |
3947 if (ns != NULL) { | 4186 if (ns != NULL) { |
3948 xmlNodePtr root = ret; | 4187 xmlNodePtr root = ret; |
3949 | 4188 |
3950 while (root->parent != NULL) root = root->parent; | 4189 while (root->parent != NULL) root = root->parent; |
3951 ret->ns = xmlNewNs(root, ns->href, ns->prefix); | 4190 ret->ns = xmlNewNs(root, ns->href, ns->prefix); |
| 4191 } else { |
| 4192 ret->ns = xmlNewReconciliedNs(doc, ret, node->ns); |
3952 } | 4193 } |
3953 } else { | 4194 } else { |
3954 /* | 4195 /* |
3955 * reference the existing namespace definition in our own tree. | 4196 * reference the existing namespace definition in our own tree. |
3956 */ | 4197 */ |
3957 ret->ns = ns; | 4198 ret->ns = ns; |
3958 } | 4199 } |
3959 } | 4200 } |
3960 if ((node->type == XML_ELEMENT_NODE) && (node->properties != NULL)) | 4201 if (((node->type == XML_ELEMENT_NODE) || |
| 4202 (node->type == XML_XINCLUDE_START)) && (node->properties != NULL)) |
3961 ret->properties = xmlCopyPropList(ret, node->properties); | 4203 ret->properties = xmlCopyPropList(ret, node->properties); |
3962 if (node->type == XML_ENTITY_REF_NODE) { | 4204 if (node->type == XML_ENTITY_REF_NODE) { |
3963 if ((doc == NULL) || (node->doc != doc)) { | 4205 if ((doc == NULL) || (node->doc != doc)) { |
3964 /* | 4206 /* |
3965 * The copied node will go into a separate document, so | 4207 * The copied node will go into a separate document, so |
3966 * to avoid dangling references to the ENTITY_DECL node | 4208 * to avoid dangling references to the ENTITY_DECL node |
3967 * we cannot keep the reference. Try to find it in the | 4209 * we cannot keep the reference. Try to find it in the |
3968 * target document. | 4210 * target document. |
3969 */ | 4211 */ |
3970 ret->children = (xmlNodePtr) xmlGetDocEntity(doc, ret->name); | 4212 ret->children = (xmlNodePtr) xmlGetDocEntity(doc, ret->name); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4116 (xmlNotationTablePtr) dtd->notations); | 4358 (xmlNotationTablePtr) dtd->notations); |
4117 if (dtd->elements != NULL) | 4359 if (dtd->elements != NULL) |
4118 ret->elements = (void *) xmlCopyElementTable( | 4360 ret->elements = (void *) xmlCopyElementTable( |
4119 (xmlElementTablePtr) dtd->elements); | 4361 (xmlElementTablePtr) dtd->elements); |
4120 if (dtd->attributes != NULL) | 4362 if (dtd->attributes != NULL) |
4121 ret->attributes = (void *) xmlCopyAttributeTable( | 4363 ret->attributes = (void *) xmlCopyAttributeTable( |
4122 (xmlAttributeTablePtr) dtd->attributes); | 4364 (xmlAttributeTablePtr) dtd->attributes); |
4123 if (dtd->pentities != NULL) | 4365 if (dtd->pentities != NULL) |
4124 ret->pentities = (void *) xmlCopyEntitiesTable( | 4366 ret->pentities = (void *) xmlCopyEntitiesTable( |
4125 (xmlEntitiesTablePtr) dtd->pentities); | 4367 (xmlEntitiesTablePtr) dtd->pentities); |
4126 | 4368 |
4127 cur = dtd->children; | 4369 cur = dtd->children; |
4128 while (cur != NULL) { | 4370 while (cur != NULL) { |
4129 q = NULL; | 4371 q = NULL; |
4130 | 4372 |
4131 if (cur->type == XML_ENTITY_DECL) { | 4373 if (cur->type == XML_ENTITY_DECL) { |
4132 xmlEntityPtr tmp = (xmlEntityPtr) cur; | 4374 xmlEntityPtr tmp = (xmlEntityPtr) cur; |
4133 switch (tmp->etype) { | 4375 switch (tmp->etype) { |
4134 case XML_INTERNAL_GENERAL_ENTITY: | 4376 case XML_INTERNAL_GENERAL_ENTITY: |
4135 case XML_EXTERNAL_GENERAL_PARSED_ENTITY: | 4377 case XML_EXTERNAL_GENERAL_PARSED_ENTITY: |
4136 case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: | 4378 case XML_EXTERNAL_GENERAL_UNPARSED_ENTITY: |
4137 q = (xmlNodePtr) xmlGetEntityFromDtd(ret, tmp->name); | 4379 q = (xmlNodePtr) xmlGetEntityFromDtd(ret, tmp->name); |
4138 break; | 4380 break; |
4139 case XML_INTERNAL_PARAMETER_ENTITY: | 4381 case XML_INTERNAL_PARAMETER_ENTITY: |
4140 case XML_EXTERNAL_PARAMETER_ENTITY: | 4382 case XML_EXTERNAL_PARAMETER_ENTITY: |
4141 » » q = (xmlNodePtr) | 4383 » » q = (xmlNodePtr) |
4142 xmlGetParameterEntityFromDtd(ret, tmp->name); | 4384 xmlGetParameterEntityFromDtd(ret, tmp->name); |
4143 break; | 4385 break; |
4144 case XML_INTERNAL_PREDEFINED_ENTITY: | 4386 case XML_INTERNAL_PREDEFINED_ENTITY: |
4145 break; | 4387 break; |
4146 } | 4388 } |
4147 } else if (cur->type == XML_ELEMENT_DECL) { | 4389 } else if (cur->type == XML_ELEMENT_DECL) { |
4148 xmlElementPtr tmp = (xmlElementPtr) cur; | 4390 xmlElementPtr tmp = (xmlElementPtr) cur; |
4149 q = (xmlNodePtr) | 4391 q = (xmlNodePtr) |
4150 xmlGetDtdQElementDesc(ret, tmp->name, tmp->prefix); | 4392 xmlGetDtdQElementDesc(ret, tmp->name, tmp->prefix); |
4151 } else if (cur->type == XML_ATTRIBUTE_DECL) { | 4393 } else if (cur->type == XML_ATTRIBUTE_DECL) { |
4152 xmlAttributePtr tmp = (xmlAttributePtr) cur; | 4394 xmlAttributePtr tmp = (xmlAttributePtr) cur; |
4153 » q = (xmlNodePtr) | 4395 » q = (xmlNodePtr) |
4154 xmlGetDtdQAttrDesc(ret, tmp->elem, tmp->name, tmp->prefix); | 4396 xmlGetDtdQAttrDesc(ret, tmp->elem, tmp->name, tmp->prefix); |
4155 } else if (cur->type == XML_COMMENT_NODE) { | 4397 } else if (cur->type == XML_COMMENT_NODE) { |
4156 q = xmlCopyNode(cur, 0); | 4398 q = xmlCopyNode(cur, 0); |
4157 } | 4399 } |
4158 » | 4400 |
4159 if (q == NULL) { | 4401 if (q == NULL) { |
4160 cur = cur->next; | 4402 cur = cur->next; |
4161 continue; | 4403 continue; |
4162 } | 4404 } |
4163 » | 4405 |
4164 if (p == NULL) | 4406 if (p == NULL) |
4165 ret->children = q; | 4407 ret->children = q; |
4166 else | 4408 else |
4167 » p->next = q; | 4409 » p->next = q; |
4168 » | 4410 |
4169 » q->prev = p; | 4411 » q->prev = p; |
4170 » q->parent = (xmlNodePtr) ret; | 4412 » q->parent = (xmlNodePtr) ret; |
4171 q->next = NULL; | 4413 q->next = NULL; |
4172 ret->last = q; | 4414 ret->last = q; |
4173 » p = q; | 4415 » p = q; |
4174 cur = cur->next; | 4416 cur = cur->next; |
4175 } | 4417 } |
4176 | 4418 |
4177 return(ret); | 4419 return(ret); |
4178 } | 4420 } |
4179 #endif | 4421 #endif |
4180 | 4422 |
4181 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) | 4423 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) |
4182 /** | 4424 /** |
4183 * xmlCopyDoc: | 4425 * xmlCopyDoc: |
(...skipping 29 matching lines...) Expand all Loading... |
4213 if (doc->intSubset != NULL) { | 4455 if (doc->intSubset != NULL) { |
4214 ret->intSubset = xmlCopyDtd(doc->intSubset); | 4456 ret->intSubset = xmlCopyDtd(doc->intSubset); |
4215 xmlSetTreeDoc((xmlNodePtr)ret->intSubset, ret); | 4457 xmlSetTreeDoc((xmlNodePtr)ret->intSubset, ret); |
4216 ret->intSubset->parent = ret; | 4458 ret->intSubset->parent = ret; |
4217 } | 4459 } |
4218 #endif | 4460 #endif |
4219 if (doc->oldNs != NULL) | 4461 if (doc->oldNs != NULL) |
4220 ret->oldNs = xmlCopyNamespaceList(doc->oldNs); | 4462 ret->oldNs = xmlCopyNamespaceList(doc->oldNs); |
4221 if (doc->children != NULL) { | 4463 if (doc->children != NULL) { |
4222 xmlNodePtr tmp; | 4464 xmlNodePtr tmp; |
4223 » | 4465 |
4224 ret->children = xmlStaticCopyNodeList(doc->children, ret, | 4466 ret->children = xmlStaticCopyNodeList(doc->children, ret, |
4225 (xmlNodePtr)ret); | 4467 (xmlNodePtr)ret); |
4226 ret->last = NULL; | 4468 ret->last = NULL; |
4227 tmp = ret->children; | 4469 tmp = ret->children; |
4228 while (tmp != NULL) { | 4470 while (tmp != NULL) { |
4229 if (tmp->next == NULL) | 4471 if (tmp->next == NULL) |
4230 ret->last = tmp; | 4472 ret->last = tmp; |
4231 tmp = tmp->next; | 4473 tmp = tmp->next; |
4232 } | 4474 } |
4233 } | 4475 } |
4234 return(ret); | 4476 return(ret); |
4235 } | 4477 } |
4236 #endif /* LIBXML_TREE_ENABLED */ | 4478 #endif /* LIBXML_TREE_ENABLED */ |
4237 | 4479 |
4238 /************************************************************************ | 4480 /************************************************************************ |
4239 * * | 4481 * * |
4240 * Content access functions * | 4482 * Content access functions * |
4241 * * | 4483 * * |
4242 ************************************************************************/ | 4484 ************************************************************************/ |
4243 | 4485 |
4244 /** | 4486 /** |
4245 * xmlGetLineNo: | 4487 * xmlGetLineNo: |
4246 * @node: valid node | 4488 * @node: valid node |
4247 * | 4489 * |
4248 * Get line number of @node. This requires activation of this option | 4490 * Get line number of @node. This requires activation of this option |
4249 * before invoking the parser by calling xmlLineNumbersDefault(1) | 4491 * before invoking the parser by calling xmlLineNumbersDefault(1) |
4250 * | 4492 * |
4251 * Returns the line number if successful, -1 otherwise | 4493 * Returns the line number if successful, -1 otherwise |
4252 */ | 4494 */ |
4253 long | 4495 long |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4325 break; | 4567 break; |
4326 sep = "/"; | 4568 sep = "/"; |
4327 next = NULL; | 4569 next = NULL; |
4328 } else if (cur->type == XML_ELEMENT_NODE) { | 4570 } else if (cur->type == XML_ELEMENT_NODE) { |
4329 generic = 0; | 4571 generic = 0; |
4330 sep = "/"; | 4572 sep = "/"; |
4331 name = (const char *) cur->name; | 4573 name = (const char *) cur->name; |
4332 if (cur->ns) { | 4574 if (cur->ns) { |
4333 if (cur->ns->prefix != NULL) { | 4575 if (cur->ns->prefix != NULL) { |
4334 snprintf(nametemp, sizeof(nametemp) - 1, "%s:%s", | 4576 snprintf(nametemp, sizeof(nametemp) - 1, "%s:%s", |
4335 » » » (char *)cur->ns->prefix, (char *)cur->name); | 4577 » » » (char *)cur->ns->prefix, (char *)cur->name); |
4336 nametemp[sizeof(nametemp) - 1] = 0; | 4578 nametemp[sizeof(nametemp) - 1] = 0; |
4337 name = nametemp; | 4579 name = nametemp; |
4338 } else { | 4580 } else { |
4339 /* | 4581 /* |
4340 * We cannot express named elements in the default | 4582 * We cannot express named elements in the default |
4341 * namespace, so use "*". | 4583 * namespace, so use "*". |
4342 */ | 4584 */ |
4343 generic = 1; | 4585 generic = 1; |
4344 name = "*"; | 4586 name = "*"; |
4345 » » } | 4587 » » } |
4346 } | 4588 } |
4347 next = cur->parent; | 4589 next = cur->parent; |
4348 | 4590 |
4349 /* | 4591 /* |
4350 * Thumbler index computation | 4592 * Thumbler index computation |
4351 * TODO: the ocurence test seems bogus for namespaced names | 4593 * TODO: the ocurence test seems bogus for namespaced names |
4352 */ | 4594 */ |
4353 tmp = cur->prev; | 4595 tmp = cur->prev; |
4354 while (tmp != NULL) { | 4596 while (tmp != NULL) { |
4355 if ((tmp->type == XML_ELEMENT_NODE) && | 4597 if ((tmp->type == XML_ELEMENT_NODE) && |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4423 * if yes, then we'll get "text()", otherwise "text()[1]". | 4665 * if yes, then we'll get "text()", otherwise "text()[1]". |
4424 */ | 4666 */ |
4425 if (occur == 0) { | 4667 if (occur == 0) { |
4426 tmp = cur->next; | 4668 tmp = cur->next; |
4427 while (tmp != NULL) { | 4669 while (tmp != NULL) { |
4428 if ((tmp->type == XML_TEXT_NODE) || | 4670 if ((tmp->type == XML_TEXT_NODE) || |
4429 (tmp->type == XML_CDATA_SECTION_NODE)) | 4671 (tmp->type == XML_CDATA_SECTION_NODE)) |
4430 { | 4672 { |
4431 occur = 1; | 4673 occur = 1; |
4432 break; | 4674 break; |
4433 » » }» » » | 4675 » » } |
4434 tmp = tmp->next; | 4676 tmp = tmp->next; |
4435 } | 4677 } |
4436 } else | 4678 } else |
4437 occur++; | 4679 occur++; |
4438 } else if (cur->type == XML_PI_NODE) { | 4680 } else if (cur->type == XML_PI_NODE) { |
4439 sep = "/"; | 4681 sep = "/"; |
4440 snprintf(nametemp, sizeof(nametemp) - 1, | 4682 snprintf(nametemp, sizeof(nametemp) - 1, |
4441 "processing-instruction('%s')", (char *)cur->name); | 4683 "processing-instruction('%s')", (char *)cur->name); |
4442 nametemp[sizeof(nametemp) - 1] = 0; | 4684 nametemp[sizeof(nametemp) - 1] = 0; |
4443 name = nametemp; | 4685 name = nametemp; |
(...skipping 22 matching lines...) Expand all Loading... |
4466 occur = 1; | 4708 occur = 1; |
4467 } else | 4709 } else |
4468 occur++; | 4710 occur++; |
4469 | 4711 |
4470 } else if (cur->type == XML_ATTRIBUTE_NODE) { | 4712 } else if (cur->type == XML_ATTRIBUTE_NODE) { |
4471 sep = "/@"; | 4713 sep = "/@"; |
4472 name = (const char *) (((xmlAttrPtr) cur)->name); | 4714 name = (const char *) (((xmlAttrPtr) cur)->name); |
4473 if (cur->ns) { | 4715 if (cur->ns) { |
4474 if (cur->ns->prefix != NULL) | 4716 if (cur->ns->prefix != NULL) |
4475 snprintf(nametemp, sizeof(nametemp) - 1, "%s:%s", | 4717 snprintf(nametemp, sizeof(nametemp) - 1, "%s:%s", |
4476 » » » (char *)cur->ns->prefix, (char *)cur->name); | 4718 » » » (char *)cur->ns->prefix, (char *)cur->name); |
4477 else | 4719 else |
4478 snprintf(nametemp, sizeof(nametemp) - 1, "%s", | 4720 snprintf(nametemp, sizeof(nametemp) - 1, "%s", |
4479 » » » (char *)cur->name); | 4721 » » » (char *)cur->name); |
4480 nametemp[sizeof(nametemp) - 1] = 0; | 4722 nametemp[sizeof(nametemp) - 1] = 0; |
4481 name = nametemp; | 4723 name = nametemp; |
4482 } | 4724 } |
4483 next = ((xmlAttrPtr) cur)->parent; | 4725 next = ((xmlAttrPtr) cur)->parent; |
4484 } else { | 4726 } else { |
4485 next = cur->parent; | 4727 next = cur->parent; |
4486 } | 4728 } |
4487 | 4729 |
4488 /* | 4730 /* |
4489 * Make sure there is enough room | 4731 * Make sure there is enough room |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4537 | 4779 |
4538 if (doc == NULL) return(NULL); | 4780 if (doc == NULL) return(NULL); |
4539 ret = doc->children; | 4781 ret = doc->children; |
4540 while (ret != NULL) { | 4782 while (ret != NULL) { |
4541 if (ret->type == XML_ELEMENT_NODE) | 4783 if (ret->type == XML_ELEMENT_NODE) |
4542 return(ret); | 4784 return(ret); |
4543 ret = ret->next; | 4785 ret = ret->next; |
4544 } | 4786 } |
4545 return(ret); | 4787 return(ret); |
4546 } | 4788 } |
4547 | 4789 |
4548 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_WRITER_ENABLED) | 4790 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_WRITER_ENABLED) |
4549 /** | 4791 /** |
4550 * xmlDocSetRootElement: | 4792 * xmlDocSetRootElement: |
4551 * @doc: the document | 4793 * @doc: the document |
4552 * @root: the new document root element, if root is NULL no action is taken, | 4794 * @root: the new document root element, if root is NULL no action is taken, |
4553 * to remove a node from a document use xmlUnlinkNode(root) instead. | 4795 * to remove a node from a document use xmlUnlinkNode(root) instead. |
4554 * | 4796 * |
4555 * Set the root element of the document (doc->children is a list | 4797 * Set the root element of the document (doc->children is a list |
4556 * containing possibly comments, PIs, etc ...). | 4798 * containing possibly comments, PIs, etc ...). |
4557 * | 4799 * |
(...skipping 21 matching lines...) Expand all Loading... |
4579 doc->last = root; | 4821 doc->last = root; |
4580 } else { | 4822 } else { |
4581 xmlAddSibling(doc->children, root); | 4823 xmlAddSibling(doc->children, root); |
4582 } | 4824 } |
4583 } else { | 4825 } else { |
4584 xmlReplaceNode(old, root); | 4826 xmlReplaceNode(old, root); |
4585 } | 4827 } |
4586 return(old); | 4828 return(old); |
4587 } | 4829 } |
4588 #endif | 4830 #endif |
4589 | 4831 |
4590 #if defined(LIBXML_TREE_ENABLED) | 4832 #if defined(LIBXML_TREE_ENABLED) |
4591 /** | 4833 /** |
4592 * xmlNodeSetLang: | 4834 * xmlNodeSetLang: |
4593 * @cur: the node being changed | 4835 * @cur: the node being changed |
4594 * @lang: the language description | 4836 * @lang: the language description |
4595 * | 4837 * |
4596 * Set the language of a node, i.e. the values of the xml:lang | 4838 * Set the language of a node, i.e. the values of the xml:lang |
4597 * attribute. | 4839 * attribute. |
4598 */ | 4840 */ |
4599 void | 4841 void |
(...skipping 27 matching lines...) Expand all Loading... |
4627 case XML_ELEMENT_NODE: | 4869 case XML_ELEMENT_NODE: |
4628 case XML_ATTRIBUTE_NODE: | 4870 case XML_ATTRIBUTE_NODE: |
4629 break; | 4871 break; |
4630 } | 4872 } |
4631 ns = xmlSearchNsByHref(cur->doc, cur, XML_XML_NAMESPACE); | 4873 ns = xmlSearchNsByHref(cur->doc, cur, XML_XML_NAMESPACE); |
4632 if (ns == NULL) | 4874 if (ns == NULL) |
4633 return; | 4875 return; |
4634 xmlSetNsProp(cur, ns, BAD_CAST "lang", lang); | 4876 xmlSetNsProp(cur, ns, BAD_CAST "lang", lang); |
4635 } | 4877 } |
4636 #endif /* LIBXML_TREE_ENABLED */ | 4878 #endif /* LIBXML_TREE_ENABLED */ |
4637 | 4879 |
4638 /** | 4880 /** |
4639 * xmlNodeGetLang: | 4881 * xmlNodeGetLang: |
4640 * @cur: the node being checked | 4882 * @cur: the node being checked |
4641 * | 4883 * |
4642 * Searches the language of a node, i.e. the values of the xml:lang | 4884 * Searches the language of a node, i.e. the values of the xml:lang |
4643 * attribute or the one carried by the nearest ancestor. | 4885 * attribute or the one carried by the nearest ancestor. |
4644 * | 4886 * |
4645 * Returns a pointer to the lang value, or NULL if not found | 4887 * Returns a pointer to the lang value, or NULL if not found |
4646 * It's up to the caller to free the memory with xmlFree(). | 4888 * It's up to the caller to free the memory with xmlFree(). |
4647 */ | 4889 */ |
4648 xmlChar * | 4890 xmlChar * |
4649 xmlNodeGetLang(xmlNodePtr cur) { | 4891 xmlNodeGetLang(xmlNodePtr cur) { |
4650 xmlChar *lang; | 4892 xmlChar *lang; |
4651 | 4893 |
4652 while (cur != NULL) { | 4894 while (cur != NULL) { |
4653 lang = xmlGetNsProp(cur, BAD_CAST "lang", XML_XML_NAMESPACE); | 4895 lang = xmlGetNsProp(cur, BAD_CAST "lang", XML_XML_NAMESPACE); |
4654 if (lang != NULL) | 4896 if (lang != NULL) |
4655 return(lang); | 4897 return(lang); |
4656 cur = cur->parent; | 4898 cur = cur->parent; |
4657 } | 4899 } |
4658 return(NULL); | 4900 return(NULL); |
4659 } | 4901 } |
4660 | 4902 |
4661 | 4903 |
4662 #ifdef LIBXML_TREE_ENABLED | 4904 #ifdef LIBXML_TREE_ENABLED |
4663 /** | 4905 /** |
4664 * xmlNodeSetSpacePreserve: | 4906 * xmlNodeSetSpacePreserve: |
4665 * @cur: the node being changed | 4907 * @cur: the node being changed |
4666 * @val: the xml:space value ("0": default, 1: "preserve") | 4908 * @val: the xml:space value ("0": default, 1: "preserve") |
4667 * | 4909 * |
4668 * Set (or reset) the space preserving behaviour of a node, i.e. the | 4910 * Set (or reset) the space preserving behaviour of a node, i.e. the |
4669 * value of the xml:space attribute. | 4911 * value of the xml:space attribute. |
4670 */ | 4912 */ |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4738 if (xmlStrEqual(space, BAD_CAST "default")) { | 4980 if (xmlStrEqual(space, BAD_CAST "default")) { |
4739 xmlFree(space); | 4981 xmlFree(space); |
4740 return(0); | 4982 return(0); |
4741 } | 4983 } |
4742 xmlFree(space); | 4984 xmlFree(space); |
4743 } | 4985 } |
4744 cur = cur->parent; | 4986 cur = cur->parent; |
4745 } | 4987 } |
4746 return(-1); | 4988 return(-1); |
4747 } | 4989 } |
4748 | 4990 |
4749 #ifdef LIBXML_TREE_ENABLED | 4991 #ifdef LIBXML_TREE_ENABLED |
4750 /** | 4992 /** |
4751 * xmlNodeSetName: | 4993 * xmlNodeSetName: |
4752 * @cur: the node being changed | 4994 * @cur: the node being changed |
4753 * @name: the new tag name | 4995 * @name: the new tag name |
4754 * | 4996 * |
4755 * Set (or reset) the name of a node. | 4997 * Set (or reset) the name of a node. |
4756 */ | 4998 */ |
4757 void | 4999 void |
4758 xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) { | 5000 xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4796 if (dict != NULL) { | 5038 if (dict != NULL) { |
4797 if ((cur->name != NULL) && (!xmlDictOwns(dict, cur->name))) | 5039 if ((cur->name != NULL) && (!xmlDictOwns(dict, cur->name))) |
4798 xmlFree((xmlChar *) cur->name); | 5040 xmlFree((xmlChar *) cur->name); |
4799 cur->name = xmlDictLookup(dict, name, -1); | 5041 cur->name = xmlDictLookup(dict, name, -1); |
4800 } else { | 5042 } else { |
4801 if (cur->name != NULL) xmlFree((xmlChar *) cur->name); | 5043 if (cur->name != NULL) xmlFree((xmlChar *) cur->name); |
4802 cur->name = xmlStrdup(name); | 5044 cur->name = xmlStrdup(name); |
4803 } | 5045 } |
4804 } | 5046 } |
4805 #endif | 5047 #endif |
4806 | 5048 |
4807 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED) | 5049 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED) |
4808 /** | 5050 /** |
4809 * xmlNodeSetBase: | 5051 * xmlNodeSetBase: |
4810 * @cur: the node being changed | 5052 * @cur: the node being changed |
4811 * @uri: the new base URI | 5053 * @uri: the new base URI |
4812 * | 5054 * |
4813 * Set (or reset) the base URI of a node, i.e. the value of the | 5055 * Set (or reset) the base URI of a node, i.e. the value of the |
4814 * xml:base attribute. | 5056 * xml:base attribute. |
4815 */ | 5057 */ |
4816 void | 5058 void |
4817 xmlNodeSetBase(xmlNodePtr cur, const xmlChar* uri) { | 5059 xmlNodeSetBase(xmlNodePtr cur, const xmlChar* uri) { |
4818 xmlNsPtr ns; | 5060 xmlNsPtr ns; |
4819 const xmlChar* fixed; | 5061 xmlChar* fixed; |
4820 | 5062 |
4821 if (cur == NULL) return; | 5063 if (cur == NULL) return; |
4822 switch(cur->type) { | 5064 switch(cur->type) { |
4823 case XML_TEXT_NODE: | 5065 case XML_TEXT_NODE: |
4824 case XML_CDATA_SECTION_NODE: | 5066 case XML_CDATA_SECTION_NODE: |
4825 case XML_COMMENT_NODE: | 5067 case XML_COMMENT_NODE: |
4826 case XML_DOCUMENT_TYPE_NODE: | 5068 case XML_DOCUMENT_TYPE_NODE: |
4827 case XML_DOCUMENT_FRAG_NODE: | 5069 case XML_DOCUMENT_FRAG_NODE: |
4828 case XML_NOTATION_NODE: | 5070 case XML_NOTATION_NODE: |
4829 case XML_DTD_NODE: | 5071 case XML_DTD_NODE: |
(...skipping 19 matching lines...) Expand all Loading... |
4849 | 5091 |
4850 if (doc->URL != NULL) | 5092 if (doc->URL != NULL) |
4851 xmlFree((xmlChar *) doc->URL); | 5093 xmlFree((xmlChar *) doc->URL); |
4852 if (uri == NULL) | 5094 if (uri == NULL) |
4853 doc->URL = NULL; | 5095 doc->URL = NULL; |
4854 else | 5096 else |
4855 doc->URL = xmlPathToURI(uri); | 5097 doc->URL = xmlPathToURI(uri); |
4856 return; | 5098 return; |
4857 } | 5099 } |
4858 } | 5100 } |
4859 | 5101 |
4860 ns = xmlSearchNsByHref(cur->doc, cur, XML_XML_NAMESPACE); | 5102 ns = xmlSearchNsByHref(cur->doc, cur, XML_XML_NAMESPACE); |
4861 if (ns == NULL) | 5103 if (ns == NULL) |
4862 return; | 5104 return; |
4863 fixed = xmlPathToURI(uri); | 5105 fixed = xmlPathToURI(uri); |
4864 if (fixed != NULL) { | 5106 if (fixed != NULL) { |
4865 xmlSetNsProp(cur, ns, BAD_CAST "base", fixed); | 5107 xmlSetNsProp(cur, ns, BAD_CAST "base", fixed); |
4866 » xmlFree((xmlChar *)fixed); | 5108 » xmlFree(fixed); |
4867 } else { | 5109 } else { |
4868 xmlSetNsProp(cur, ns, BAD_CAST "base", uri); | 5110 xmlSetNsProp(cur, ns, BAD_CAST "base", uri); |
4869 } | 5111 } |
4870 } | 5112 } |
4871 #endif /* LIBXML_TREE_ENABLED */ | 5113 #endif /* LIBXML_TREE_ENABLED */ |
4872 | 5114 |
4873 /** | 5115 /** |
4874 * xmlNodeGetBase: | 5116 * xmlNodeGetBase: |
4875 * @doc: the document the node pertains to | 5117 * @doc: the document the node pertains to |
4876 * @cur: the node being checked | 5118 * @cur: the node being checked |
4877 * | 5119 * |
4878 * Searches for the BASE URL. The code should work on both XML | 5120 * Searches for the BASE URL. The code should work on both XML |
4879 * and HTML document even if base mechanisms are completely different. | 5121 * and HTML document even if base mechanisms are completely different. |
4880 * It returns the base as defined in RFC 2396 sections | 5122 * It returns the base as defined in RFC 2396 sections |
4881 * 5.1.1. Base URI within Document Content | 5123 * 5.1.1. Base URI within Document Content |
4882 * and | 5124 * and |
4883 * 5.1.2. Base URI from the Encapsulating Entity | 5125 * 5.1.2. Base URI from the Encapsulating Entity |
4884 * However it does not return the document base (5.1.3), use | 5126 * However it does not return the document base (5.1.3), use |
4885 * xmlDocumentGetBase() for this | 5127 * doc->URL in this case |
4886 * | 5128 * |
4887 * Returns a pointer to the base URL, or NULL if not found | 5129 * Returns a pointer to the base URL, or NULL if not found |
4888 * It's up to the caller to free the memory with xmlFree(). | 5130 * It's up to the caller to free the memory with xmlFree(). |
4889 */ | 5131 */ |
4890 xmlChar * | 5132 xmlChar * |
4891 xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) { | 5133 xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) { |
4892 xmlChar *oldbase = NULL; | 5134 xmlChar *oldbase = NULL; |
4893 xmlChar *base, *newbase; | 5135 xmlChar *base, *newbase; |
4894 | 5136 |
4895 if ((cur == NULL) && (doc == NULL)) | 5137 if ((cur == NULL) && (doc == NULL)) |
4896 return(NULL); | 5138 return(NULL); |
4897 if (doc == NULL) doc = cur->doc;» | 5139 if (doc == NULL) doc = cur->doc; |
4898 if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) { | 5140 if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) { |
4899 cur = doc->children; | 5141 cur = doc->children; |
4900 while ((cur != NULL) && (cur->name != NULL)) { | 5142 while ((cur != NULL) && (cur->name != NULL)) { |
4901 if (cur->type != XML_ELEMENT_NODE) { | 5143 if (cur->type != XML_ELEMENT_NODE) { |
4902 cur = cur->next; | 5144 cur = cur->next; |
4903 continue; | 5145 continue; |
4904 } | 5146 } |
4905 if (!xmlStrcasecmp(cur->name, BAD_CAST "html")) { | 5147 if (!xmlStrcasecmp(cur->name, BAD_CAST "html")) { |
4906 cur = cur->children; | 5148 cur = cur->children; |
4907 continue; | 5149 continue; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4949 } | 5191 } |
4950 if ((doc != NULL) && (doc->URL != NULL)) { | 5192 if ((doc != NULL) && (doc->URL != NULL)) { |
4951 if (oldbase == NULL) | 5193 if (oldbase == NULL) |
4952 return(xmlStrdup(doc->URL)); | 5194 return(xmlStrdup(doc->URL)); |
4953 newbase = xmlBuildURI(oldbase, doc->URL); | 5195 newbase = xmlBuildURI(oldbase, doc->URL); |
4954 xmlFree(oldbase); | 5196 xmlFree(oldbase); |
4955 return(newbase); | 5197 return(newbase); |
4956 } | 5198 } |
4957 return(oldbase); | 5199 return(oldbase); |
4958 } | 5200 } |
4959 | 5201 |
4960 /** | 5202 /** |
4961 * xmlNodeBufGetContent: | 5203 * xmlNodeBufGetContent: |
4962 * @buffer: a buffer | 5204 * @buffer: a buffer |
4963 * @cur: the node being read | 5205 * @cur: the node being read |
4964 * | 5206 * |
4965 * Read the value of a node @cur, this can be either the text carried | 5207 * Read the value of a node @cur, this can be either the text carried |
4966 * directly by this node if it's a TEXT node or the aggregate string | 5208 * directly by this node if it's a TEXT node or the aggregate string |
4967 * of the values carried by this node child's (TEXT and ENTITY_REF). | 5209 * of the values carried by this node child's (TEXT and ENTITY_REF). |
4968 * Entity references are substituted. | 5210 * Entity references are substituted. |
4969 * Fills up the buffer @buffer with this value | 5211 * Fills up the buffer @buffer with this value |
4970 * | 5212 * |
4971 * Returns 0 in case of success and -1 in case of error. | 5213 * Returns 0 in case of success and -1 in case of error. |
4972 */ | 5214 */ |
4973 int | 5215 int |
4974 xmlNodeBufGetContent(xmlBufferPtr buffer, xmlNodePtr cur) | 5216 xmlNodeBufGetContent(xmlBufferPtr buffer, xmlNodePtr cur) |
4975 { | 5217 { |
4976 if ((cur == NULL) || (buffer == NULL)) return(-1); | 5218 if ((cur == NULL) || (buffer == NULL)) return(-1); |
4977 switch (cur->type) { | 5219 switch (cur->type) { |
4978 case XML_CDATA_SECTION_NODE: | 5220 case XML_CDATA_SECTION_NODE: |
4979 case XML_TEXT_NODE: | 5221 case XML_TEXT_NODE: |
4980 xmlBufferCat(buffer, cur->content); | 5222 xmlBufferCat(buffer, cur->content); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5239 case XML_CDATA_SECTION_NODE: | 5481 case XML_CDATA_SECTION_NODE: |
5240 case XML_ENTITY_REF_NODE: | 5482 case XML_ENTITY_REF_NODE: |
5241 case XML_ENTITY_NODE: | 5483 case XML_ENTITY_NODE: |
5242 case XML_PI_NODE: | 5484 case XML_PI_NODE: |
5243 case XML_COMMENT_NODE: | 5485 case XML_COMMENT_NODE: |
5244 if ((cur->content != NULL) && | 5486 if ((cur->content != NULL) && |
5245 (cur->content != (xmlChar *) &(cur->properties))) { | 5487 (cur->content != (xmlChar *) &(cur->properties))) { |
5246 if (!((cur->doc != NULL) && (cur->doc->dict != NULL) && | 5488 if (!((cur->doc != NULL) && (cur->doc->dict != NULL) && |
5247 (xmlDictOwns(cur->doc->dict, cur->content)))) | 5489 (xmlDictOwns(cur->doc->dict, cur->content)))) |
5248 xmlFree(cur->content); | 5490 xmlFree(cur->content); |
5249 » }» | 5491 » } |
5250 if (cur->children != NULL) xmlFreeNodeList(cur->children); | 5492 if (cur->children != NULL) xmlFreeNodeList(cur->children); |
5251 cur->last = cur->children = NULL; | 5493 cur->last = cur->children = NULL; |
5252 if (content != NULL) { | 5494 if (content != NULL) { |
5253 cur->content = xmlStrdup(content); | 5495 cur->content = xmlStrdup(content); |
5254 » } else | 5496 » } else |
5255 cur->content = NULL; | 5497 cur->content = NULL; |
5256 cur->properties = NULL; | 5498 cur->properties = NULL; |
5257 cur->nsDef = NULL; | 5499 cur->nsDef = NULL; |
5258 break; | 5500 break; |
5259 case XML_DOCUMENT_NODE: | 5501 case XML_DOCUMENT_NODE: |
5260 case XML_HTML_DOCUMENT_NODE: | 5502 case XML_HTML_DOCUMENT_NODE: |
5261 case XML_DOCUMENT_TYPE_NODE: | 5503 case XML_DOCUMENT_TYPE_NODE: |
5262 case XML_XINCLUDE_START: | 5504 case XML_XINCLUDE_START: |
5263 case XML_XINCLUDE_END: | 5505 case XML_XINCLUDE_END: |
5264 #ifdef LIBXML_DOCB_ENABLED | 5506 #ifdef LIBXML_DOCB_ENABLED |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5317 case XML_ENTITY_REF_NODE: | 5559 case XML_ENTITY_REF_NODE: |
5318 case XML_ENTITY_NODE: | 5560 case XML_ENTITY_NODE: |
5319 case XML_PI_NODE: | 5561 case XML_PI_NODE: |
5320 case XML_COMMENT_NODE: | 5562 case XML_COMMENT_NODE: |
5321 case XML_NOTATION_NODE: | 5563 case XML_NOTATION_NODE: |
5322 if ((cur->content != NULL) && | 5564 if ((cur->content != NULL) && |
5323 (cur->content != (xmlChar *) &(cur->properties))) { | 5565 (cur->content != (xmlChar *) &(cur->properties))) { |
5324 if (!((cur->doc != NULL) && (cur->doc->dict != NULL) && | 5566 if (!((cur->doc != NULL) && (cur->doc->dict != NULL) && |
5325 (xmlDictOwns(cur->doc->dict, cur->content)))) | 5567 (xmlDictOwns(cur->doc->dict, cur->content)))) |
5326 xmlFree(cur->content); | 5568 xmlFree(cur->content); |
5327 » }» | 5569 » } |
5328 if (cur->children != NULL) xmlFreeNodeList(cur->children); | 5570 if (cur->children != NULL) xmlFreeNodeList(cur->children); |
5329 cur->children = cur->last = NULL; | 5571 cur->children = cur->last = NULL; |
5330 if (content != NULL) { | 5572 if (content != NULL) { |
5331 cur->content = xmlStrndup(content, len); | 5573 cur->content = xmlStrndup(content, len); |
5332 » } else | 5574 » } else |
5333 cur->content = NULL; | 5575 cur->content = NULL; |
5334 cur->properties = NULL; | 5576 cur->properties = NULL; |
5335 cur->nsDef = NULL; | 5577 cur->nsDef = NULL; |
5336 break; | 5578 break; |
5337 case XML_DOCUMENT_NODE: | 5579 case XML_DOCUMENT_NODE: |
5338 case XML_DTD_NODE: | 5580 case XML_DTD_NODE: |
5339 case XML_HTML_DOCUMENT_NODE: | 5581 case XML_HTML_DOCUMENT_NODE: |
5340 case XML_DOCUMENT_TYPE_NODE: | 5582 case XML_DOCUMENT_TYPE_NODE: |
5341 case XML_NAMESPACE_DECL: | 5583 case XML_NAMESPACE_DECL: |
5342 case XML_XINCLUDE_START: | 5584 case XML_XINCLUDE_START: |
(...skipping 13 matching lines...) Expand all Loading... |
5356 break; | 5598 break; |
5357 } | 5599 } |
5358 } | 5600 } |
5359 #endif /* LIBXML_TREE_ENABLED */ | 5601 #endif /* LIBXML_TREE_ENABLED */ |
5360 | 5602 |
5361 /** | 5603 /** |
5362 * xmlNodeAddContentLen: | 5604 * xmlNodeAddContentLen: |
5363 * @cur: the node being modified | 5605 * @cur: the node being modified |
5364 * @content: extra content | 5606 * @content: extra content |
5365 * @len: the size of @content | 5607 * @len: the size of @content |
5366 * | 5608 * |
5367 * Append the extra substring to the node content. | 5609 * Append the extra substring to the node content. |
5368 * NOTE: In contrast to xmlNodeSetContentLen(), @content is supposed to be | 5610 * NOTE: In contrast to xmlNodeSetContentLen(), @content is supposed to be |
5369 * raw text, so unescaped XML special chars are allowed, entity | 5611 * raw text, so unescaped XML special chars are allowed, entity |
5370 * references are not supported. | 5612 * references are not supported. |
5371 */ | 5613 */ |
5372 void | 5614 void |
5373 xmlNodeAddContentLen(xmlNodePtr cur, const xmlChar *content, int len) { | 5615 xmlNodeAddContentLen(xmlNodePtr cur, const xmlChar *content, int len) { |
5374 if (cur == NULL) { | 5616 if (cur == NULL) { |
5375 #ifdef DEBUG_TREE | 5617 #ifdef DEBUG_TREE |
5376 xmlGenericError(xmlGenericErrorContext, | 5618 xmlGenericError(xmlGenericErrorContext, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5431 case XML_ATTRIBUTE_DECL: | 5673 case XML_ATTRIBUTE_DECL: |
5432 case XML_ENTITY_DECL: | 5674 case XML_ENTITY_DECL: |
5433 break; | 5675 break; |
5434 } | 5676 } |
5435 } | 5677 } |
5436 | 5678 |
5437 /** | 5679 /** |
5438 * xmlNodeAddContent: | 5680 * xmlNodeAddContent: |
5439 * @cur: the node being modified | 5681 * @cur: the node being modified |
5440 * @content: extra content | 5682 * @content: extra content |
5441 * | 5683 * |
5442 * Append the extra substring to the node content. | 5684 * Append the extra substring to the node content. |
5443 * NOTE: In contrast to xmlNodeSetContent(), @content is supposed to be | 5685 * NOTE: In contrast to xmlNodeSetContent(), @content is supposed to be |
5444 * raw text, so unescaped XML special chars are allowed, entity | 5686 * raw text, so unescaped XML special chars are allowed, entity |
5445 * references are not supported. | 5687 * references are not supported. |
5446 */ | 5688 */ |
5447 void | 5689 void |
5448 xmlNodeAddContent(xmlNodePtr cur, const xmlChar *content) { | 5690 xmlNodeAddContent(xmlNodePtr cur, const xmlChar *content) { |
5449 int len; | 5691 int len; |
5450 | 5692 |
5451 if (cur == NULL) { | 5693 if (cur == NULL) { |
5452 #ifdef DEBUG_TREE | 5694 #ifdef DEBUG_TREE |
5453 xmlGenericError(xmlGenericErrorContext, | 5695 xmlGenericError(xmlGenericErrorContext, |
5454 "xmlNodeAddContent : node == NULL\n"); | 5696 "xmlNodeAddContent : node == NULL\n"); |
5455 #endif | 5697 #endif |
5456 return; | 5698 return; |
5457 } | 5699 } |
5458 if (content == NULL) return; | 5700 if (content == NULL) return; |
5459 len = xmlStrlen(content); | 5701 len = xmlStrlen(content); |
5460 xmlNodeAddContentLen(cur, content, len); | 5702 xmlNodeAddContentLen(cur, content, len); |
5461 } | 5703 } |
5462 | 5704 |
5463 /** | 5705 /** |
5464 * xmlTextMerge: | 5706 * xmlTextMerge: |
5465 * @first: the first text node | 5707 * @first: the first text node |
5466 * @second: the second text node being merged | 5708 * @second: the second text node being merged |
5467 * | 5709 * |
5468 * Merge two text nodes into one | 5710 * Merge two text nodes into one |
5469 * Returns the first text node augmented | 5711 * Returns the first text node augmented |
5470 */ | 5712 */ |
5471 xmlNodePtr | 5713 xmlNodePtr |
5472 xmlTextMerge(xmlNodePtr first, xmlNodePtr second) { | 5714 xmlTextMerge(xmlNodePtr first, xmlNodePtr second) { |
5473 if (first == NULL) return(second); | 5715 if (first == NULL) return(second); |
5474 if (second == NULL) return(first); | 5716 if (second == NULL) return(first); |
5475 if (first->type != XML_TEXT_NODE) return(first); | 5717 if (first->type != XML_TEXT_NODE) return(first); |
5476 if (second->type != XML_TEXT_NODE) return(first); | 5718 if (second->type != XML_TEXT_NODE) return(first); |
5477 if (second->name != first->name) | 5719 if (second->name != first->name) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5542 } | 5784 } |
5543 node = node->parent; | 5785 node = node->parent; |
5544 } | 5786 } |
5545 return (ret); | 5787 return (ret); |
5546 } | 5788 } |
5547 #endif /* LIBXML_TREE_ENABLED */ | 5789 #endif /* LIBXML_TREE_ENABLED */ |
5548 | 5790 |
5549 /* | 5791 /* |
5550 * xmlTreeEnsureXMLDecl: | 5792 * xmlTreeEnsureXMLDecl: |
5551 * @doc: the doc | 5793 * @doc: the doc |
5552 * | 5794 * |
5553 * Ensures that there is an XML namespace declaration on the doc. | 5795 * Ensures that there is an XML namespace declaration on the doc. |
5554 * | 5796 * |
5555 * Returns the XML ns-struct or NULL on API and internal errors. | 5797 * Returns the XML ns-struct or NULL on API and internal errors. |
5556 */ | 5798 */ |
5557 static xmlNsPtr | 5799 static xmlNsPtr |
5558 xmlTreeEnsureXMLDecl(xmlDocPtr doc) | 5800 xmlTreeEnsureXMLDecl(xmlDocPtr doc) |
5559 { | 5801 { |
5560 if (doc == NULL) | 5802 if (doc == NULL) |
5561 return (NULL); | 5803 return (NULL); |
5562 if (doc->oldNs != NULL) | 5804 if (doc->oldNs != NULL) |
5563 return (doc->oldNs); | 5805 return (doc->oldNs); |
5564 { | 5806 { |
5565 xmlNsPtr ns; | 5807 xmlNsPtr ns; |
5566 ns = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); | 5808 ns = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); |
5567 if (ns == NULL) { | 5809 if (ns == NULL) { |
5568 xmlTreeErrMemory( | 5810 xmlTreeErrMemory( |
5569 "allocating the XML namespace"); | 5811 "allocating the XML namespace"); |
5570 return (NULL); | 5812 return (NULL); |
5571 } | 5813 } |
5572 memset(ns, 0, sizeof(xmlNs)); | 5814 memset(ns, 0, sizeof(xmlNs)); |
5573 ns->type = XML_LOCAL_NAMESPACE; | 5815 ns->type = XML_LOCAL_NAMESPACE; |
5574 » ns->href = xmlStrdup(XML_XML_NAMESPACE); | 5816 » ns->href = xmlStrdup(XML_XML_NAMESPACE); |
5575 ns->prefix = xmlStrdup((const xmlChar *)"xml"); | 5817 ns->prefix = xmlStrdup((const xmlChar *)"xml"); |
5576 doc->oldNs = ns; | 5818 doc->oldNs = ns; |
5577 return (ns); | 5819 return (ns); |
5578 } | 5820 } |
5579 } | 5821 } |
5580 | 5822 |
5581 /** | 5823 /** |
5582 * xmlSearchNs: | 5824 * xmlSearchNs: |
5583 * @doc: the document | 5825 * @doc: the document |
5584 * @node: the current node | 5826 * @node: the current node |
5585 * @nameSpace: the namespace prefix | 5827 * @nameSpace: the namespace prefix |
5586 * | 5828 * |
5587 * Search a Ns registered under a given name space for a document. | 5829 * Search a Ns registered under a given name space for a document. |
5588 * recurse on the parents until it finds the defined namespace | 5830 * recurse on the parents until it finds the defined namespace |
5589 * or return NULL otherwise. | 5831 * or return NULL otherwise. |
5590 * @nameSpace can be NULL, this is a search for the default namespace. | 5832 * @nameSpace can be NULL, this is a search for the default namespace. |
5591 * We don't allow to cross entities boundaries. If you don't declare | 5833 * We don't allow to cross entities boundaries. If you don't declare |
5592 * the namespace within those you will be in troubles !!! A warning | 5834 * the namespace within those you will be in troubles !!! A warning |
5593 * is generated to cover this case. | 5835 * is generated to cover this case. |
5594 * | 5836 * |
5595 * Returns the namespace pointer or NULL. | 5837 * Returns the namespace pointer or NULL. |
5596 */ | 5838 */ |
5597 xmlNsPtr | 5839 xmlNsPtr |
5598 xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace) { | 5840 xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace) { |
5599 » | 5841 |
5600 xmlNsPtr cur; | 5842 xmlNsPtr cur; |
5601 xmlNodePtr orig = node; | 5843 xmlNodePtr orig = node; |
5602 | 5844 |
5603 if (node == NULL) return(NULL); | 5845 if (node == NULL) return(NULL); |
5604 if ((nameSpace != NULL) && | 5846 if ((nameSpace != NULL) && |
5605 (xmlStrEqual(nameSpace, (const xmlChar *)"xml"))) { | 5847 (xmlStrEqual(nameSpace, (const xmlChar *)"xml"))) { |
5606 if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) { | 5848 if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) { |
5607 /* | 5849 /* |
5608 * The XML-1.0 namespace is normally held on the root | 5850 * The XML-1.0 namespace is normally held on the root |
5609 * element. In this case exceptionally create it on the | 5851 * element. In this case exceptionally create it on the |
5610 * node element. | 5852 * node element. |
5611 */ | 5853 */ |
5612 cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); | 5854 cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); |
5613 if (cur == NULL) { | 5855 if (cur == NULL) { |
5614 xmlTreeErrMemory("searching namespace"); | 5856 xmlTreeErrMemory("searching namespace"); |
5615 return(NULL); | 5857 return(NULL); |
5616 } | 5858 } |
5617 memset(cur, 0, sizeof(xmlNs)); | 5859 memset(cur, 0, sizeof(xmlNs)); |
5618 cur->type = XML_LOCAL_NAMESPACE; | 5860 cur->type = XML_LOCAL_NAMESPACE; |
5619 » cur->href = xmlStrdup(XML_XML_NAMESPACE); | 5861 » cur->href = xmlStrdup(XML_XML_NAMESPACE); |
5620 » cur->prefix = xmlStrdup((const xmlChar *)"xml"); | 5862 » cur->prefix = xmlStrdup((const xmlChar *)"xml"); |
5621 cur->next = node->nsDef; | 5863 cur->next = node->nsDef; |
5622 node->nsDef = cur; | 5864 node->nsDef = cur; |
5623 return(cur); | 5865 return(cur); |
5624 } | 5866 } |
5625 if (doc == NULL) { | 5867 if (doc == NULL) { |
5626 doc = node->doc; | 5868 doc = node->doc; |
5627 if (doc == NULL) | 5869 if (doc == NULL) |
5628 return(NULL); | 5870 return(NULL); |
5629 } | 5871 } |
5630 /* | 5872 /* |
(...skipping 14 matching lines...) Expand all Loading... |
5645 while (cur != NULL) { | 5887 while (cur != NULL) { |
5646 if ((cur->prefix == NULL) && (nameSpace == NULL) && | 5888 if ((cur->prefix == NULL) && (nameSpace == NULL) && |
5647 (cur->href != NULL)) | 5889 (cur->href != NULL)) |
5648 return(cur); | 5890 return(cur); |
5649 if ((cur->prefix != NULL) && (nameSpace != NULL) && | 5891 if ((cur->prefix != NULL) && (nameSpace != NULL) && |
5650 (cur->href != NULL) && | 5892 (cur->href != NULL) && |
5651 (xmlStrEqual(cur->prefix, nameSpace))) | 5893 (xmlStrEqual(cur->prefix, nameSpace))) |
5652 return(cur); | 5894 return(cur); |
5653 cur = cur->next; | 5895 cur = cur->next; |
5654 } | 5896 } |
5655 » if (orig != node) { | 5897 » if (orig != node) { |
5656 cur = node->ns; | 5898 cur = node->ns; |
5657 if (cur != NULL) { | 5899 if (cur != NULL) { |
5658 if ((cur->prefix == NULL) && (nameSpace == NULL) && | 5900 if ((cur->prefix == NULL) && (nameSpace == NULL) && |
5659 (cur->href != NULL)) | 5901 (cur->href != NULL)) |
5660 return(cur); | 5902 return(cur); |
5661 if ((cur->prefix != NULL) && (nameSpace != NULL) && | 5903 if ((cur->prefix != NULL) && (nameSpace != NULL) && |
5662 (cur->href != NULL) && | 5904 (cur->href != NULL) && |
5663 (xmlStrEqual(cur->prefix, nameSpace))) | 5905 (xmlStrEqual(cur->prefix, nameSpace))) |
5664 return(cur); | 5906 return(cur); |
5665 } | 5907 } |
5666 » } | 5908 » } |
5667 } | 5909 } |
5668 node = node->parent; | 5910 node = node->parent; |
5669 } | 5911 } |
5670 return(NULL); | 5912 return(NULL); |
5671 } | 5913 } |
5672 | 5914 |
5673 /** | 5915 /** |
5674 * xmlNsInScope: | 5916 * xmlNsInScope: |
5675 * @doc: the document | 5917 * @doc: the document |
5676 * @node: the current node | 5918 * @node: the current node |
5677 * @ancestor: the ancestor carrying the namespace | 5919 * @ancestor: the ancestor carrying the namespace |
5678 * @prefix: the namespace prefix | 5920 * @prefix: the namespace prefix |
5679 * | 5921 * |
5680 * Verify that the given namespace held on @ancestor is still in scope | 5922 * Verify that the given namespace held on @ancestor is still in scope |
5681 * on node. | 5923 * on node. |
5682 * | 5924 * |
5683 * Returns 1 if true, 0 if false and -1 in case of error. | 5925 * Returns 1 if true, 0 if false and -1 in case of error. |
5684 */ | 5926 */ |
5685 static int | 5927 static int |
5686 xmlNsInScope(xmlDocPtr doc ATTRIBUTE_UNUSED, xmlNodePtr node, | 5928 xmlNsInScope(xmlDocPtr doc ATTRIBUTE_UNUSED, xmlNodePtr node, |
5687 xmlNodePtr ancestor, const xmlChar * prefix) | 5929 xmlNodePtr ancestor, const xmlChar * prefix) |
5688 { | 5930 { |
5689 xmlNsPtr tst; | 5931 xmlNsPtr tst; |
5690 | 5932 |
5691 while ((node != NULL) && (node != ancestor)) { | 5933 while ((node != NULL) && (node != ancestor)) { |
5692 if ((node->type == XML_ENTITY_REF_NODE) || | 5934 if ((node->type == XML_ENTITY_REF_NODE) || |
(...skipping 12 matching lines...) Expand all Loading... |
5705 return (0); | 5947 return (0); |
5706 tst = tst->next; | 5948 tst = tst->next; |
5707 } | 5949 } |
5708 } | 5950 } |
5709 node = node->parent; | 5951 node = node->parent; |
5710 } | 5952 } |
5711 if (node != ancestor) | 5953 if (node != ancestor) |
5712 return (-1); | 5954 return (-1); |
5713 return (1); | 5955 return (1); |
5714 } | 5956 } |
5715 | 5957 |
5716 /** | 5958 /** |
5717 * xmlSearchNsByHref: | 5959 * xmlSearchNsByHref: |
5718 * @doc: the document | 5960 * @doc: the document |
5719 * @node: the current node | 5961 * @node: the current node |
5720 * @href: the namespace value | 5962 * @href: the namespace value |
5721 * | 5963 * |
5722 * Search a Ns aliasing a given URI. Recurse on the parents until it finds | 5964 * Search a Ns aliasing a given URI. Recurse on the parents until it finds |
5723 * the defined namespace or return NULL otherwise. | 5965 * the defined namespace or return NULL otherwise. |
5724 * Returns the namespace pointer or NULL. | 5966 * Returns the namespace pointer or NULL. |
5725 */ | 5967 */ |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5759 doc = node->doc; | 6001 doc = node->doc; |
5760 if (doc == NULL) | 6002 if (doc == NULL) |
5761 return(NULL); | 6003 return(NULL); |
5762 } | 6004 } |
5763 /* | 6005 /* |
5764 * Return the XML namespace declaration held by the doc. | 6006 * Return the XML namespace declaration held by the doc. |
5765 */ | 6007 */ |
5766 if (doc->oldNs == NULL) | 6008 if (doc->oldNs == NULL) |
5767 return(xmlTreeEnsureXMLDecl(doc)); | 6009 return(xmlTreeEnsureXMLDecl(doc)); |
5768 else | 6010 else |
5769 » return(doc->oldNs); | 6011 » return(doc->oldNs); |
5770 } | 6012 } |
5771 is_attr = (node->type == XML_ATTRIBUTE_NODE); | 6013 is_attr = (node->type == XML_ATTRIBUTE_NODE); |
5772 while (node != NULL) { | 6014 while (node != NULL) { |
5773 if ((node->type == XML_ENTITY_REF_NODE) || | 6015 if ((node->type == XML_ENTITY_REF_NODE) || |
5774 (node->type == XML_ENTITY_NODE) || | 6016 (node->type == XML_ENTITY_NODE) || |
5775 (node->type == XML_ENTITY_DECL)) | 6017 (node->type == XML_ENTITY_DECL)) |
5776 return (NULL); | 6018 return (NULL); |
5777 if (node->type == XML_ELEMENT_NODE) { | 6019 if (node->type == XML_ELEMENT_NODE) { |
5778 cur = node->nsDef; | 6020 cur = node->nsDef; |
5779 while (cur != NULL) { | 6021 while (cur != NULL) { |
5780 if ((cur->href != NULL) && (href != NULL) && | 6022 if ((cur->href != NULL) && (href != NULL) && |
5781 (xmlStrEqual(cur->href, href))) { | 6023 (xmlStrEqual(cur->href, href))) { |
5782 if (((!is_attr) || (cur->prefix != NULL)) && | 6024 if (((!is_attr) || (cur->prefix != NULL)) && |
5783 (xmlNsInScope(doc, orig, node, cur->prefix) == 1)) | 6025 (xmlNsInScope(doc, orig, node, cur->prefix) == 1)) |
5784 return (cur); | 6026 return (cur); |
5785 } | 6027 } |
5786 cur = cur->next; | 6028 cur = cur->next; |
5787 } | 6029 } |
5788 if (orig != node) { | 6030 if (orig != node) { |
5789 cur = node->ns; | 6031 cur = node->ns; |
5790 if (cur != NULL) { | 6032 if (cur != NULL) { |
5791 if ((cur->href != NULL) && (href != NULL) && | 6033 if ((cur->href != NULL) && (href != NULL) && |
5792 (xmlStrEqual(cur->href, href))) { | 6034 (xmlStrEqual(cur->href, href))) { |
5793 if (((!is_attr) || (cur->prefix != NULL)) && | 6035 if (((!is_attr) || (cur->prefix != NULL)) && |
5794 (xmlNsInScope(doc, orig, node, cur->prefix) == 1)) | 6036 (xmlNsInScope(doc, orig, node, cur->prefix) == 1)) |
5795 return (cur); | 6037 return (cur); |
5796 } | 6038 } |
5797 } | 6039 } |
5798 } | 6040 } |
5799 } | 6041 } |
5800 node = node->parent; | 6042 node = node->parent; |
5801 } | 6043 } |
5802 return (NULL); | 6044 return (NULL); |
5803 } | 6045 } |
5804 | 6046 |
5805 /** | 6047 /** |
5806 * xmlNewReconciliedNs: | 6048 * xmlNewReconciliedNs: |
5807 * @doc: the document | 6049 * @doc: the document |
5808 * @tree: a node expected to hold the new namespace | 6050 * @tree: a node expected to hold the new namespace |
5809 * @ns: the original namespace | 6051 * @ns: the original namespace |
5810 * | 6052 * |
5811 * This function tries to locate a namespace definition in a tree | 6053 * This function tries to locate a namespace definition in a tree |
5812 * ancestors, or create a new namespace definition node similar to | 6054 * ancestors, or create a new namespace definition node similar to |
5813 * @ns trying to reuse the same prefix. However if the given prefix is | 6055 * @ns trying to reuse the same prefix. However if the given prefix is |
5814 * null (default namespace) or reused within the subtree defined by | 6056 * null (default namespace) or reused within the subtree defined by |
5815 * @tree or on one of its ancestors then a new prefix is generated. | 6057 * @tree or on one of its ancestors then a new prefix is generated. |
5816 * Returns the (new) namespace definition or NULL in case of error | 6058 * Returns the (new) namespace definition or NULL in case of error |
5817 */ | 6059 */ |
5818 xmlNsPtr | 6060 static xmlNsPtr |
5819 xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) { | 6061 xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) { |
5820 xmlNsPtr def; | 6062 xmlNsPtr def; |
5821 xmlChar prefix[50]; | 6063 xmlChar prefix[50]; |
5822 int counter = 1; | 6064 int counter = 1; |
5823 | 6065 |
5824 if (tree == NULL) { | 6066 if (tree == NULL) { |
5825 #ifdef DEBUG_TREE | 6067 #ifdef DEBUG_TREE |
5826 xmlGenericError(xmlGenericErrorContext, | 6068 xmlGenericError(xmlGenericErrorContext, |
5827 "xmlNewReconciliedNs : tree == NULL\n"); | 6069 "xmlNewReconciliedNs : tree == NULL\n"); |
5828 #endif | 6070 #endif |
(...skipping 22 matching lines...) Expand all Loading... |
5851 else | 6093 else |
5852 snprintf((char *) prefix, sizeof(prefix), "%.20s", (char *)ns->prefix); | 6094 snprintf((char *) prefix, sizeof(prefix), "%.20s", (char *)ns->prefix); |
5853 | 6095 |
5854 def = xmlSearchNs(doc, tree, prefix); | 6096 def = xmlSearchNs(doc, tree, prefix); |
5855 while (def != NULL) { | 6097 while (def != NULL) { |
5856 if (counter > 1000) return(NULL); | 6098 if (counter > 1000) return(NULL); |
5857 if (ns->prefix == NULL) | 6099 if (ns->prefix == NULL) |
5858 snprintf((char *) prefix, sizeof(prefix), "default%d", counter++); | 6100 snprintf((char *) prefix, sizeof(prefix), "default%d", counter++); |
5859 else | 6101 else |
5860 snprintf((char *) prefix, sizeof(prefix), "%.20s%d", | 6102 snprintf((char *) prefix, sizeof(prefix), "%.20s%d", |
5861 » » (char *)ns->prefix, counter++); | 6103 » » (char *)ns->prefix, counter++); |
5862 def = xmlSearchNs(doc, tree, prefix); | 6104 def = xmlSearchNs(doc, tree, prefix); |
5863 } | 6105 } |
5864 | 6106 |
5865 /* | 6107 /* |
5866 * OK, now we are ready to create a new one. | 6108 * OK, now we are ready to create a new one. |
5867 */ | 6109 */ |
5868 def = xmlNewNs(tree, ns->href, prefix); | 6110 def = xmlNewNs(tree, ns->href, prefix); |
5869 return(def); | 6111 return(def); |
5870 } | 6112 } |
5871 | 6113 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6046 if ((node != tree) && (node->next != NULL)) { | 6288 if ((node != tree) && (node->next != NULL)) { |
6047 node = node->next; | 6289 node = node->next; |
6048 break; | 6290 break; |
6049 } | 6291 } |
6050 if (node->parent == NULL) { | 6292 if (node->parent == NULL) { |
6051 node = NULL; | 6293 node = NULL; |
6052 break; | 6294 break; |
6053 } | 6295 } |
6054 } | 6296 } |
6055 /* exit condition */ | 6297 /* exit condition */ |
6056 » if (node == tree) | 6298 » if (node == tree) |
6057 node = NULL; | 6299 node = NULL; |
6058 } else | 6300 } else |
6059 break; | 6301 break; |
6060 } | 6302 } |
6061 if (oldNs != NULL) | 6303 if (oldNs != NULL) |
6062 xmlFree(oldNs); | 6304 xmlFree(oldNs); |
6063 if (newNs != NULL) | 6305 if (newNs != NULL) |
6064 xmlFree(newNs); | 6306 xmlFree(newNs); |
6065 return(ret); | 6307 return(ret); |
6066 } | 6308 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6102 } while (prop != NULL); | 6344 } while (prop != NULL); |
6103 } | 6345 } |
6104 } | 6346 } |
6105 | 6347 |
6106 #ifdef LIBXML_TREE_ENABLED | 6348 #ifdef LIBXML_TREE_ENABLED |
6107 if (! useDTD) | 6349 if (! useDTD) |
6108 return(NULL); | 6350 return(NULL); |
6109 /* | 6351 /* |
6110 * Check if there is a default/fixed attribute declaration in | 6352 * Check if there is a default/fixed attribute declaration in |
6111 * the internal or external subset. | 6353 * the internal or external subset. |
6112 */ | 6354 */ |
6113 if ((node->doc != NULL) && (node->doc->intSubset != NULL)) { | 6355 if ((node->doc != NULL) && (node->doc->intSubset != NULL)) { |
6114 xmlDocPtr doc = node->doc; | 6356 xmlDocPtr doc = node->doc; |
6115 xmlAttributePtr attrDecl = NULL; | 6357 xmlAttributePtr attrDecl = NULL; |
6116 xmlChar *elemQName, *tmpstr = NULL; | 6358 xmlChar *elemQName, *tmpstr = NULL; |
6117 | 6359 |
6118 /* | 6360 /* |
6119 » * We need the QName of the element for the DTD-lookup.» | 6361 » * We need the QName of the element for the DTD-lookup. |
6120 */ | 6362 */ |
6121 if ((node->ns != NULL) && (node->ns->prefix != NULL)) { | 6363 if ((node->ns != NULL) && (node->ns->prefix != NULL)) { |
6122 tmpstr = xmlStrdup(node->ns->prefix); | 6364 tmpstr = xmlStrdup(node->ns->prefix); |
6123 tmpstr = xmlStrcat(tmpstr, BAD_CAST ":"); | 6365 tmpstr = xmlStrcat(tmpstr, BAD_CAST ":"); |
6124 tmpstr = xmlStrcat(tmpstr, node->name); | 6366 tmpstr = xmlStrcat(tmpstr, node->name); |
6125 if (tmpstr == NULL) | 6367 if (tmpstr == NULL) |
6126 return(NULL); | 6368 return(NULL); |
6127 elemQName = tmpstr; | 6369 elemQName = tmpstr; |
6128 } else | 6370 } else |
6129 elemQName = (xmlChar *) node->name; | 6371 elemQName = (xmlChar *) node->name; |
(...skipping 30 matching lines...) Expand all Loading... |
6160 if (doc->extSubset != NULL) { | 6402 if (doc->extSubset != NULL) { |
6161 attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, elemQName, | 6403 attrDecl = xmlGetDtdQAttrDesc(doc->extSubset, elemQName, |
6162 name, (*cur)->prefix); | 6404 name, (*cur)->prefix); |
6163 if (attrDecl) | 6405 if (attrDecl) |
6164 break; | 6406 break; |
6165 } | 6407 } |
6166 } | 6408 } |
6167 cur++; | 6409 cur++; |
6168 } | 6410 } |
6169 xmlFree(nsList); | 6411 xmlFree(nsList); |
6170 » }» | 6412 » } |
6171 if (tmpstr != NULL) | 6413 if (tmpstr != NULL) |
6172 xmlFree(tmpstr); | 6414 xmlFree(tmpstr); |
6173 /* | 6415 /* |
6174 * Only default/fixed attrs are relevant. | 6416 * Only default/fixed attrs are relevant. |
6175 */ | 6417 */ |
6176 if ((attrDecl != NULL) && (attrDecl->defaultValue != NULL)) | 6418 if ((attrDecl != NULL) && (attrDecl->defaultValue != NULL)) |
6177 return((xmlAttrPtr) attrDecl); | 6419 return((xmlAttrPtr) attrDecl); |
6178 } | 6420 } |
6179 #endif /* LIBXML_TREE_ENABLED */ | 6421 #endif /* LIBXML_TREE_ENABLED */ |
6180 return(NULL); | 6422 return(NULL); |
(...skipping 23 matching lines...) Expand all Loading... |
6204 | 6446 |
6205 ret = xmlNodeListGetString(prop->doc, prop->children, 1); | 6447 ret = xmlNodeListGetString(prop->doc, prop->children, 1); |
6206 if (ret != NULL) | 6448 if (ret != NULL) |
6207 return(ret); | 6449 return(ret); |
6208 } | 6450 } |
6209 } | 6451 } |
6210 return(xmlStrdup((xmlChar *)"")); | 6452 return(xmlStrdup((xmlChar *)"")); |
6211 } else if (prop->type == XML_ATTRIBUTE_DECL) { | 6453 } else if (prop->type == XML_ATTRIBUTE_DECL) { |
6212 return(xmlStrdup(((xmlAttributePtr)prop)->defaultValue)); | 6454 return(xmlStrdup(((xmlAttributePtr)prop)->defaultValue)); |
6213 } | 6455 } |
6214 return(NULL); | 6456 return(NULL); |
6215 } | 6457 } |
6216 | 6458 |
6217 /** | 6459 /** |
6218 * xmlHasProp: | 6460 * xmlHasProp: |
6219 * @node: the node | 6461 * @node: the node |
6220 * @name: the attribute name | 6462 * @name: the attribute name |
6221 * | 6463 * |
6222 * Search an attribute associated to a node | 6464 * Search an attribute associated to a node |
6223 * This function also looks in DTD attribute declaration for #FIXED or | 6465 * This function also looks in DTD attribute declaration for #FIXED or |
6224 * default declaration values unless DTD use has been turned off. | 6466 * default declaration values unless DTD use has been turned off. |
6225 * | 6467 * |
6226 * Returns the attribute or the attribute declaration or NULL if | 6468 * Returns the attribute or the attribute declaration or NULL if |
6227 * neither was found. | 6469 * neither was found. |
6228 */ | 6470 */ |
6229 xmlAttrPtr | 6471 xmlAttrPtr |
6230 xmlHasProp(xmlNodePtr node, const xmlChar *name) { | 6472 xmlHasProp(xmlNodePtr node, const xmlChar *name) { |
6231 xmlAttrPtr prop; | 6473 xmlAttrPtr prop; |
6232 xmlDocPtr doc; | 6474 xmlDocPtr doc; |
6233 | 6475 |
6234 if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) | 6476 if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) |
6235 return(NULL); | 6477 return(NULL); |
6236 /* | 6478 /* |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6298 * default declaration values unless DTD use has been turned off. | 6540 * default declaration values unless DTD use has been turned off. |
6299 * NOTE: this function acts independently of namespaces associated | 6541 * NOTE: this function acts independently of namespaces associated |
6300 * to the attribute. Use xmlGetNsProp() or xmlGetNoNsProp() | 6542 * to the attribute. Use xmlGetNsProp() or xmlGetNoNsProp() |
6301 * for namespace aware processing. | 6543 * for namespace aware processing. |
6302 * | 6544 * |
6303 * Returns the attribute value or NULL if not found. | 6545 * Returns the attribute value or NULL if not found. |
6304 * It's up to the caller to free the memory with xmlFree(). | 6546 * It's up to the caller to free the memory with xmlFree(). |
6305 */ | 6547 */ |
6306 xmlChar * | 6548 xmlChar * |
6307 xmlGetProp(xmlNodePtr node, const xmlChar *name) { | 6549 xmlGetProp(xmlNodePtr node, const xmlChar *name) { |
6308 xmlAttrPtr prop; | 6550 xmlAttrPtr prop; |
6309 | 6551 |
6310 prop = xmlHasProp(node, name); | 6552 prop = xmlHasProp(node, name); |
6311 if (prop == NULL) | 6553 if (prop == NULL) |
6312 return(NULL); | 6554 return(NULL); |
6313 return(xmlGetPropNodeValueInternal(prop)); | 6555 return(xmlGetPropNodeValueInternal(prop)); |
6314 } | 6556 } |
6315 | 6557 |
6316 /** | 6558 /** |
6317 * xmlGetNoNsProp: | 6559 * xmlGetNoNsProp: |
6318 * @node: the node | 6560 * @node: the node |
6319 * @name: the attribute name | 6561 * @name: the attribute name |
6320 * | 6562 * |
6321 * Search and get the value of an attribute associated to a node | 6563 * Search and get the value of an attribute associated to a node |
6322 * This does the entity substitution. | 6564 * This does the entity substitution. |
6323 * This function looks in DTD attribute declaration for #FIXED or | 6565 * This function looks in DTD attribute declaration for #FIXED or |
6324 * default declaration values unless DTD use has been turned off. | 6566 * default declaration values unless DTD use has been turned off. |
6325 * This function is similar to xmlGetProp except it will accept only | 6567 * This function is similar to xmlGetProp except it will accept only |
6326 * an attribute in no namespace. | 6568 * an attribute in no namespace. |
6327 * | 6569 * |
6328 * Returns the attribute value or NULL if not found. | 6570 * Returns the attribute value or NULL if not found. |
6329 * It's up to the caller to free the memory with xmlFree(). | 6571 * It's up to the caller to free the memory with xmlFree(). |
6330 */ | 6572 */ |
6331 xmlChar * | 6573 xmlChar * |
6332 xmlGetNoNsProp(xmlNodePtr node, const xmlChar *name) { | 6574 xmlGetNoNsProp(xmlNodePtr node, const xmlChar *name) { |
6333 xmlAttrPtr prop; | 6575 xmlAttrPtr prop; |
6334 | 6576 |
6335 prop = xmlGetPropNodeInternal(node, name, NULL, xmlCheckDTD); | 6577 prop = xmlGetPropNodeInternal(node, name, NULL, xmlCheckDTD); |
6336 if (prop == NULL) | 6578 if (prop == NULL) |
6337 return(NULL); | 6579 return(NULL); |
6338 return(xmlGetPropNodeValueInternal(prop)); | 6580 return(xmlGetPropNodeValueInternal(prop)); |
6339 } | 6581 } |
6340 | 6582 |
6341 /** | 6583 /** |
6342 * xmlGetNsProp: | 6584 * xmlGetNsProp: |
6343 * @node: the node | 6585 * @node: the node |
6344 * @name: the attribute name | 6586 * @name: the attribute name |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6390 * @node: the node | 6632 * @node: the node |
6391 * @ns: the namespace definition | 6633 * @ns: the namespace definition |
6392 * @name: the attribute name | 6634 * @name: the attribute name |
6393 * | 6635 * |
6394 * Remove an attribute carried by a node. | 6636 * Remove an attribute carried by a node. |
6395 * Returns 0 if successful, -1 if not found | 6637 * Returns 0 if successful, -1 if not found |
6396 */ | 6638 */ |
6397 int | 6639 int |
6398 xmlUnsetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name) { | 6640 xmlUnsetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name) { |
6399 xmlAttrPtr prop; | 6641 xmlAttrPtr prop; |
6400 | 6642 |
6401 prop = xmlGetPropNodeInternal(node, name, (ns != NULL) ? ns->href : NULL, 0)
; | 6643 prop = xmlGetPropNodeInternal(node, name, (ns != NULL) ? ns->href : NULL, 0)
; |
6402 if (prop == NULL) | 6644 if (prop == NULL) |
6403 return(-1); | 6645 return(-1); |
6404 xmlUnlinkNode((xmlNodePtr) prop); | 6646 xmlUnlinkNode((xmlNodePtr) prop); |
6405 xmlFreeProp(prop); | 6647 xmlFreeProp(prop); |
6406 return(0); | 6648 return(0); |
6407 } | 6649 } |
6408 #endif | 6650 #endif |
6409 | 6651 |
6410 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED) || defined(
LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_HTML_ENABLED) | 6652 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED) || defined(
LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_HTML_ENABLED) |
6411 /** | 6653 /** |
6412 * xmlSetProp: | 6654 * xmlSetProp: |
6413 * @node: the node | 6655 * @node: the node |
6414 * @name: the attribute name (a QName) | 6656 * @name: the attribute name (a QName) |
6415 * @value: the attribute value | 6657 * @value: the attribute value |
6416 * | 6658 * |
6417 * Set (or reset) an attribute carried by a node. | 6659 * Set (or reset) an attribute carried by a node. |
6418 * If @name has a prefix, then the corresponding | 6660 * If @name has a prefix, then the corresponding |
6419 * namespace-binding will be used, if in scope; it is an | 6661 * namespace-binding will be used, if in scope; it is an |
6420 * error it there's no such ns-binding for the prefix in | 6662 * error it there's no such ns-binding for the prefix in |
6421 * scope. | 6663 * scope. |
6422 * Returns the attribute pointer. | 6664 * Returns the attribute pointer. |
6423 * | 6665 * |
6424 */ | 6666 */ |
6425 xmlAttrPtr | 6667 xmlAttrPtr |
6426 xmlSetProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { | 6668 xmlSetProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { |
6427 int len; | 6669 int len; |
6428 const xmlChar *nqname; | 6670 const xmlChar *nqname; |
6429 | 6671 |
6430 if ((node == NULL) || (name == NULL) || (node->type != XML_ELEMENT_NODE)) | 6672 if ((node == NULL) || (name == NULL) || (node->type != XML_ELEMENT_NODE)) |
6431 return(NULL); | 6673 return(NULL); |
6432 | 6674 |
6433 /* | 6675 /* |
(...skipping 22 matching lines...) Expand all Loading... |
6456 * Set (or reset) an attribute carried by a node. | 6698 * Set (or reset) an attribute carried by a node. |
6457 * The ns structure must be in scope, this is not checked | 6699 * The ns structure must be in scope, this is not checked |
6458 * | 6700 * |
6459 * Returns the attribute pointer. | 6701 * Returns the attribute pointer. |
6460 */ | 6702 */ |
6461 xmlAttrPtr | 6703 xmlAttrPtr |
6462 xmlSetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name, | 6704 xmlSetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name, |
6463 const xmlChar *value) | 6705 const xmlChar *value) |
6464 { | 6706 { |
6465 xmlAttrPtr prop; | 6707 xmlAttrPtr prop; |
6466 | 6708 |
6467 if (ns && (ns->href == NULL)) | 6709 if (ns && (ns->href == NULL)) |
6468 return(NULL); | 6710 return(NULL); |
6469 prop = xmlGetPropNodeInternal(node, name, (ns != NULL) ? ns->href : NULL, 0)
; | 6711 prop = xmlGetPropNodeInternal(node, name, (ns != NULL) ? ns->href : NULL, 0)
; |
6470 if (prop != NULL) { | 6712 if (prop != NULL) { |
6471 /* | 6713 /* |
6472 * Modify the attribute's value. | 6714 * Modify the attribute's value. |
6473 */ | 6715 */ |
6474 if (prop->atype == XML_ATTRIBUTE_ID) { | 6716 if (prop->atype == XML_ATTRIBUTE_ID) { |
6475 xmlRemoveID(node->doc, prop); | 6717 xmlRemoveID(node->doc, prop); |
6476 prop->atype = XML_ATTRIBUTE_ID; | 6718 prop->atype = XML_ATTRIBUTE_ID; |
6477 } | 6719 } |
6478 » if (prop->children != NULL) | 6720 » if (prop->children != NULL) |
6479 xmlFreeNodeList(prop->children); | 6721 xmlFreeNodeList(prop->children); |
6480 prop->children = NULL; | 6722 prop->children = NULL; |
6481 prop->last = NULL; | 6723 prop->last = NULL; |
6482 prop->ns = ns; | 6724 prop->ns = ns; |
6483 if (value != NULL) { | 6725 if (value != NULL) { |
6484 xmlNodePtr tmp; | 6726 xmlNodePtr tmp; |
6485 » | 6727 |
6486 if(!xmlCheckUTF8(value)) { | 6728 if(!xmlCheckUTF8(value)) { |
6487 xmlTreeErr(XML_TREE_NOT_UTF8, (xmlNodePtr) node->doc, | 6729 xmlTreeErr(XML_TREE_NOT_UTF8, (xmlNodePtr) node->doc, |
6488 NULL); | 6730 NULL); |
6489 if (node->doc != NULL) | 6731 if (node->doc != NULL) |
6490 node->doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); | 6732 node->doc->encoding = xmlStrdup(BAD_CAST "ISO-8859-1"); |
6491 } | 6733 } |
6492 prop->children = xmlNewDocText(node->doc, value); | 6734 prop->children = xmlNewDocText(node->doc, value); |
6493 prop->last = NULL; | 6735 prop->last = NULL; |
6494 tmp = prop->children; | 6736 tmp = prop->children; |
6495 while (tmp != NULL) { | 6737 while (tmp != NULL) { |
(...skipping 11 matching lines...) Expand all Loading... |
6507 * No equal attr found; create a new one. | 6749 * No equal attr found; create a new one. |
6508 */ | 6750 */ |
6509 return(xmlNewPropInternal(node, ns, name, value, 0)); | 6751 return(xmlNewPropInternal(node, ns, name, value, 0)); |
6510 } | 6752 } |
6511 | 6753 |
6512 #endif /* LIBXML_TREE_ENABLED */ | 6754 #endif /* LIBXML_TREE_ENABLED */ |
6513 | 6755 |
6514 /** | 6756 /** |
6515 * xmlNodeIsText: | 6757 * xmlNodeIsText: |
6516 * @node: the node | 6758 * @node: the node |
6517 * | 6759 * |
6518 * Is this node a Text node ? | 6760 * Is this node a Text node ? |
6519 * Returns 1 yes, 0 no | 6761 * Returns 1 yes, 0 no |
6520 */ | 6762 */ |
6521 int | 6763 int |
6522 xmlNodeIsText(xmlNodePtr node) { | 6764 xmlNodeIsText(xmlNodePtr node) { |
6523 if (node == NULL) return(0); | 6765 if (node == NULL) return(0); |
6524 | 6766 |
6525 if (node->type == XML_TEXT_NODE) return(1); | 6767 if (node->type == XML_TEXT_NODE) return(1); |
6526 return(0); | 6768 return(0); |
6527 } | 6769 } |
6528 | 6770 |
6529 /** | 6771 /** |
6530 * xmlIsBlankNode: | 6772 * xmlIsBlankNode: |
6531 * @node: the node | 6773 * @node: the node |
6532 * | 6774 * |
6533 * Checks whether this node is an empty or whitespace only | 6775 * Checks whether this node is an empty or whitespace only |
6534 * (and possibly ignorable) text-node. | 6776 * (and possibly ignorable) text-node. |
6535 * | 6777 * |
6536 * Returns 1 yes, 0 no | 6778 * Returns 1 yes, 0 no |
6537 */ | 6779 */ |
6538 int | 6780 int |
6539 xmlIsBlankNode(xmlNodePtr node) { | 6781 xmlIsBlankNode(xmlNodePtr node) { |
6540 const xmlChar *cur; | 6782 const xmlChar *cur; |
6541 if (node == NULL) return(0); | 6783 if (node == NULL) return(0); |
6542 | 6784 |
6543 if ((node->type != XML_TEXT_NODE) && | 6785 if ((node->type != XML_TEXT_NODE) && |
6544 (node->type != XML_CDATA_SECTION_NODE)) | 6786 (node->type != XML_CDATA_SECTION_NODE)) |
6545 return(0); | 6787 return(0); |
6546 if (node->content == NULL) return(1); | 6788 if (node->content == NULL) return(1); |
6547 cur = node->content; | 6789 cur = node->content; |
6548 while (*cur != 0) { | 6790 while (*cur != 0) { |
6549 if (!IS_BLANK_CH(*cur)) return(0); | 6791 if (!IS_BLANK_CH(*cur)) return(0); |
6550 cur++; | 6792 cur++; |
6551 } | 6793 } |
6552 | 6794 |
6553 return(1); | 6795 return(1); |
6554 } | 6796 } |
6555 | 6797 |
6556 /** | 6798 /** |
6557 * xmlTextConcat: | 6799 * xmlTextConcat: |
6558 * @node: the node | 6800 * @node: the node |
6559 * @content: the content | 6801 * @content: the content |
6560 * @len: @content length | 6802 * @len: @content length |
6561 * | 6803 * |
6562 * Concat the given string at the end of the existing node content | 6804 * Concat the given string at the end of the existing node content |
6563 * | 6805 * |
6564 * Returns -1 in case of error, 0 otherwise | 6806 * Returns -1 in case of error, 0 otherwise |
6565 */ | 6807 */ |
6566 | 6808 |
6567 int | 6809 int |
6568 xmlTextConcat(xmlNodePtr node, const xmlChar *content, int len) { | 6810 xmlTextConcat(xmlNodePtr node, const xmlChar *content, int len) { |
6569 if (node == NULL) return(-1); | 6811 if (node == NULL) return(-1); |
6570 | 6812 |
6571 if ((node->type != XML_TEXT_NODE) && | 6813 if ((node->type != XML_TEXT_NODE) && |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6616 ret->use = 0; | 6858 ret->use = 0; |
6617 ret->size = xmlDefaultBufferSize; | 6859 ret->size = xmlDefaultBufferSize; |
6618 ret->alloc = xmlBufferAllocScheme; | 6860 ret->alloc = xmlBufferAllocScheme; |
6619 ret->content = (xmlChar *) xmlMallocAtomic(ret->size * sizeof(xmlChar)); | 6861 ret->content = (xmlChar *) xmlMallocAtomic(ret->size * sizeof(xmlChar)); |
6620 if (ret->content == NULL) { | 6862 if (ret->content == NULL) { |
6621 xmlTreeErrMemory("creating buffer"); | 6863 xmlTreeErrMemory("creating buffer"); |
6622 xmlFree(ret); | 6864 xmlFree(ret); |
6623 return(NULL); | 6865 return(NULL); |
6624 } | 6866 } |
6625 ret->content[0] = 0; | 6867 ret->content[0] = 0; |
| 6868 ret->contentIO = NULL; |
6626 return(ret); | 6869 return(ret); |
6627 } | 6870 } |
6628 | 6871 |
6629 /** | 6872 /** |
6630 * xmlBufferCreateSize: | 6873 * xmlBufferCreateSize: |
6631 * @size: initial size of buffer | 6874 * @size: initial size of buffer |
6632 * | 6875 * |
6633 * routine to create an XML buffer. | 6876 * routine to create an XML buffer. |
6634 * returns the new structure. | 6877 * returns the new structure. |
6635 */ | 6878 */ |
(...skipping 12 matching lines...) Expand all Loading... |
6648 if (ret->size){ | 6891 if (ret->size){ |
6649 ret->content = (xmlChar *) xmlMallocAtomic(ret->size * sizeof(xmlChar)); | 6892 ret->content = (xmlChar *) xmlMallocAtomic(ret->size * sizeof(xmlChar)); |
6650 if (ret->content == NULL) { | 6893 if (ret->content == NULL) { |
6651 xmlTreeErrMemory("creating buffer"); | 6894 xmlTreeErrMemory("creating buffer"); |
6652 xmlFree(ret); | 6895 xmlFree(ret); |
6653 return(NULL); | 6896 return(NULL); |
6654 } | 6897 } |
6655 ret->content[0] = 0; | 6898 ret->content[0] = 0; |
6656 } else | 6899 } else |
6657 ret->content = NULL; | 6900 ret->content = NULL; |
| 6901 ret->contentIO = NULL; |
6658 return(ret); | 6902 return(ret); |
6659 } | 6903 } |
6660 | 6904 |
6661 /** | 6905 /** |
6662 * xmlBufferCreateStatic: | 6906 * xmlBufferCreateStatic: |
6663 * @mem: the memory area | 6907 * @mem: the memory area |
6664 * @size: the size in byte | 6908 * @size: the size in byte |
6665 * | 6909 * |
6666 * routine to create an XML buffer from an immutable memory area. | 6910 * routine to create an XML buffer from an immutable memory area. |
6667 * The area won't be modified nor copied, and is expected to be | 6911 * The area won't be modified nor copied, and is expected to be |
(...skipping 21 matching lines...) Expand all Loading... |
6689 } | 6933 } |
6690 | 6934 |
6691 /** | 6935 /** |
6692 * xmlBufferSetAllocationScheme: | 6936 * xmlBufferSetAllocationScheme: |
6693 * @buf: the buffer to tune | 6937 * @buf: the buffer to tune |
6694 * @scheme: allocation scheme to use | 6938 * @scheme: allocation scheme to use |
6695 * | 6939 * |
6696 * Sets the allocation scheme for this buffer | 6940 * Sets the allocation scheme for this buffer |
6697 */ | 6941 */ |
6698 void | 6942 void |
6699 xmlBufferSetAllocationScheme(xmlBufferPtr buf, | 6943 xmlBufferSetAllocationScheme(xmlBufferPtr buf, |
6700 xmlBufferAllocationScheme scheme) { | 6944 xmlBufferAllocationScheme scheme) { |
6701 if (buf == NULL) { | 6945 if (buf == NULL) { |
6702 #ifdef DEBUG_BUFFER | 6946 #ifdef DEBUG_BUFFER |
6703 xmlGenericError(xmlGenericErrorContext, | 6947 xmlGenericError(xmlGenericErrorContext, |
6704 "xmlBufferSetAllocationScheme: buf == NULL\n"); | 6948 "xmlBufferSetAllocationScheme: buf == NULL\n"); |
6705 #endif | 6949 #endif |
6706 return; | 6950 return; |
6707 } | 6951 } |
6708 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return; | 6952 if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) || |
6709 | 6953 (buf->alloc == XML_BUFFER_ALLOC_IO)) return; |
6710 buf->alloc = scheme; | 6954 if ((scheme == XML_BUFFER_ALLOC_DOUBLEIT) || |
| 6955 (scheme == XML_BUFFER_ALLOC_EXACT) || |
| 6956 (scheme == XML_BUFFER_ALLOC_IMMUTABLE)) |
| 6957 » buf->alloc = scheme; |
6711 } | 6958 } |
6712 | 6959 |
6713 /** | 6960 /** |
6714 * xmlBufferFree: | 6961 * xmlBufferFree: |
6715 * @buf: the buffer to free | 6962 * @buf: the buffer to free |
6716 * | 6963 * |
6717 * Frees an XML buffer. It frees both the content and the structure which | 6964 * Frees an XML buffer. It frees both the content and the structure which |
6718 * encapsulate it. | 6965 * encapsulate it. |
6719 */ | 6966 */ |
6720 void | 6967 void |
6721 xmlBufferFree(xmlBufferPtr buf) { | 6968 xmlBufferFree(xmlBufferPtr buf) { |
6722 if (buf == NULL) { | 6969 if (buf == NULL) { |
6723 #ifdef DEBUG_BUFFER | 6970 #ifdef DEBUG_BUFFER |
6724 xmlGenericError(xmlGenericErrorContext, | 6971 xmlGenericError(xmlGenericErrorContext, |
6725 "xmlBufferFree: buf == NULL\n"); | 6972 "xmlBufferFree: buf == NULL\n"); |
6726 #endif | 6973 #endif |
6727 return; | 6974 return; |
6728 } | 6975 } |
6729 | 6976 |
6730 if ((buf->content != NULL) && | 6977 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && |
| 6978 (buf->contentIO != NULL)) { |
| 6979 xmlFree(buf->contentIO); |
| 6980 } else if ((buf->content != NULL) && |
6731 (buf->alloc != XML_BUFFER_ALLOC_IMMUTABLE)) { | 6981 (buf->alloc != XML_BUFFER_ALLOC_IMMUTABLE)) { |
6732 xmlFree(buf->content); | 6982 xmlFree(buf->content); |
6733 } | 6983 } |
6734 xmlFree(buf); | 6984 xmlFree(buf); |
6735 } | 6985 } |
6736 | 6986 |
6737 /** | 6987 /** |
6738 * xmlBufferEmpty: | 6988 * xmlBufferEmpty: |
6739 * @buf: the buffer | 6989 * @buf: the buffer |
6740 * | 6990 * |
6741 * empty a buffer. | 6991 * empty a buffer. |
6742 */ | 6992 */ |
6743 void | 6993 void |
6744 xmlBufferEmpty(xmlBufferPtr buf) { | 6994 xmlBufferEmpty(xmlBufferPtr buf) { |
6745 if (buf == NULL) return; | 6995 if (buf == NULL) return; |
6746 if (buf->content == NULL) return; | 6996 if (buf->content == NULL) return; |
6747 buf->use = 0; | 6997 buf->use = 0; |
6748 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) { | 6998 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) { |
6749 buf->content = BAD_CAST ""; | 6999 buf->content = BAD_CAST ""; |
| 7000 } else if ((buf->alloc == XML_BUFFER_ALLOC_IO) && |
| 7001 (buf->contentIO != NULL)) { |
| 7002 size_t start_buf = buf->content - buf->contentIO; |
| 7003 |
| 7004 buf->size += start_buf; |
| 7005 buf->content = buf->contentIO; |
| 7006 buf->content[0] = 0; |
6750 } else { | 7007 } else { |
6751 » memset(buf->content, 0, buf->size); | 7008 buf->content[0] = 0; |
6752 } | 7009 } |
6753 } | 7010 } |
6754 | 7011 |
6755 /** | 7012 /** |
6756 * xmlBufferShrink: | 7013 * xmlBufferShrink: |
6757 * @buf: the buffer to dump | 7014 * @buf: the buffer to dump |
6758 * @len: the number of xmlChar to remove | 7015 * @len: the number of xmlChar to remove |
6759 * | 7016 * |
6760 * Remove the beginning of an XML buffer. | 7017 * Remove the beginning of an XML buffer. |
6761 * | 7018 * |
6762 * Returns the number of #xmlChar removed, or -1 in case of failure. | 7019 * Returns the number of #xmlChar removed, or -1 in case of failure. |
6763 */ | 7020 */ |
6764 int | 7021 int |
6765 xmlBufferShrink(xmlBufferPtr buf, unsigned int len) { | 7022 xmlBufferShrink(xmlBufferPtr buf, unsigned int len) { |
6766 if (buf == NULL) return(-1); | 7023 if (buf == NULL) return(-1); |
6767 if (len == 0) return(0); | 7024 if (len == 0) return(0); |
6768 if (len > buf->use) return(-1); | 7025 if (len > buf->use) return(-1); |
6769 | 7026 |
6770 buf->use -= len; | 7027 buf->use -= len; |
6771 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) { | 7028 if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) || |
| 7029 ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL))) { |
| 7030 » /* |
| 7031 » * we just move the content pointer, but also make sure |
| 7032 » * the perceived buffer size has shrinked accordingly |
| 7033 » */ |
6772 buf->content += len; | 7034 buf->content += len; |
| 7035 buf->size -= len; |
| 7036 |
| 7037 /* |
| 7038 * sometimes though it maybe be better to really shrink |
| 7039 * on IO buffers |
| 7040 */ |
| 7041 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { |
| 7042 size_t start_buf = buf->content - buf->contentIO; |
| 7043 if (start_buf >= buf->size) { |
| 7044 memmove(buf->contentIO, &buf->content[0], buf->use); |
| 7045 buf->content = buf->contentIO; |
| 7046 buf->content[buf->use] = 0; |
| 7047 buf->size += start_buf; |
| 7048 } |
| 7049 } |
6773 } else { | 7050 } else { |
6774 » memmove(buf->content, &buf->content[len], buf->use * sizeof(xmlChar)); | 7051 » memmove(buf->content, &buf->content[len], buf->use); |
6775 buf->content[buf->use] = 0; | 7052 buf->content[buf->use] = 0; |
6776 } | 7053 } |
6777 return(len); | 7054 return(len); |
6778 } | 7055 } |
6779 | 7056 |
6780 /** | 7057 /** |
6781 * xmlBufferGrow: | 7058 * xmlBufferGrow: |
6782 * @buf: the buffer | 7059 * @buf: the buffer |
6783 * @len: the minimum free size to allocate | 7060 * @len: the minimum free size to allocate |
6784 * | 7061 * |
6785 * Grow the available space of an XML buffer. | 7062 * Grow the available space of an XML buffer. |
6786 * | 7063 * |
6787 * Returns the new available space or -1 in case of error | 7064 * Returns the new available space or -1 in case of error |
6788 */ | 7065 */ |
6789 int | 7066 int |
6790 xmlBufferGrow(xmlBufferPtr buf, unsigned int len) { | 7067 xmlBufferGrow(xmlBufferPtr buf, unsigned int len) { |
6791 int size; | 7068 int size; |
6792 xmlChar *newbuf; | 7069 xmlChar *newbuf; |
6793 | 7070 |
6794 if (buf == NULL) return(-1); | 7071 if (buf == NULL) return(-1); |
6795 | 7072 |
6796 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0); | 7073 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0); |
6797 if (len + buf->use < buf->size) return(0); | 7074 if (len + buf->use < buf->size) return(0); |
6798 | 7075 |
6799 /* | 7076 /* |
6800 * Windows has a BIG problem on realloc timing, so we try to double | 7077 * Windows has a BIG problem on realloc timing, so we try to double |
6801 * the buffer size (if that's enough) (bug 146697) | 7078 * the buffer size (if that's enough) (bug 146697) |
6802 */ | 7079 * Apparently BSD too, and it's probably best for linux too |
6803 #ifdef WIN32 | 7080 * On an embedded system this may be something to change |
| 7081 */ |
| 7082 #if 1 |
6804 if (buf->size > len) | 7083 if (buf->size > len) |
6805 size = buf->size * 2; | 7084 size = buf->size * 2; |
6806 else | 7085 else |
6807 size = buf->use + len + 100; | 7086 size = buf->use + len + 100; |
6808 #else | 7087 #else |
6809 size = buf->use + len + 100; | 7088 size = buf->use + len + 100; |
6810 #endif | 7089 #endif |
6811 | 7090 |
6812 newbuf = (xmlChar *) xmlRealloc(buf->content, size); | 7091 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { |
6813 if (newbuf == NULL) { | 7092 size_t start_buf = buf->content - buf->contentIO; |
6814 » xmlTreeErrMemory("growing buffer"); | 7093 |
6815 return(-1); | 7094 » newbuf = (xmlChar *) xmlRealloc(buf->contentIO, start_buf + size); |
| 7095 » if (newbuf == NULL) { |
| 7096 » xmlTreeErrMemory("growing buffer"); |
| 7097 » return(-1); |
| 7098 » } |
| 7099 » buf->contentIO = newbuf; |
| 7100 » buf->content = newbuf + start_buf; |
| 7101 } else { |
| 7102 » newbuf = (xmlChar *) xmlRealloc(buf->content, size); |
| 7103 » if (newbuf == NULL) { |
| 7104 » xmlTreeErrMemory("growing buffer"); |
| 7105 » return(-1); |
| 7106 » } |
| 7107 » buf->content = newbuf; |
6816 } | 7108 } |
6817 buf->content = newbuf; | |
6818 buf->size = size; | 7109 buf->size = size; |
6819 return(buf->size - buf->use); | 7110 return(buf->size - buf->use); |
6820 } | 7111 } |
6821 | 7112 |
6822 /** | 7113 /** |
6823 * xmlBufferDump: | 7114 * xmlBufferDump: |
6824 * @file: the file output | 7115 * @file: the file output |
6825 * @buf: the buffer to dump | 7116 * @buf: the buffer to dump |
6826 * | 7117 * |
6827 * Dumps an XML buffer to a FILE *. | 7118 * Dumps an XML buffer to a FILE *. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6864 xmlBufferContent(const xmlBufferPtr buf) | 7155 xmlBufferContent(const xmlBufferPtr buf) |
6865 { | 7156 { |
6866 if(!buf) | 7157 if(!buf) |
6867 return NULL; | 7158 return NULL; |
6868 | 7159 |
6869 return buf->content; | 7160 return buf->content; |
6870 } | 7161 } |
6871 | 7162 |
6872 /** | 7163 /** |
6873 * xmlBufferLength: | 7164 * xmlBufferLength: |
6874 * @buf: the buffer | 7165 * @buf: the buffer |
6875 * | 7166 * |
6876 * Function to get the length of a buffer | 7167 * Function to get the length of a buffer |
6877 * | 7168 * |
6878 * Returns the length of data in the internal content | 7169 * Returns the length of data in the internal content |
6879 */ | 7170 */ |
6880 | 7171 |
6881 int | 7172 int |
6882 xmlBufferLength(const xmlBufferPtr buf) | 7173 xmlBufferLength(const xmlBufferPtr buf) |
6883 { | 7174 { |
6884 if(!buf) | 7175 if(!buf) |
6885 return 0; | 7176 return 0; |
6886 | 7177 |
6887 return buf->use; | 7178 return buf->use; |
6888 } | 7179 } |
6889 | 7180 |
6890 /** | 7181 /** |
6891 * xmlBufferResize: | 7182 * xmlBufferResize: |
6892 * @buf: the buffer to resize | 7183 * @buf: the buffer to resize |
6893 * @size: the desired size | 7184 * @size: the desired size |
6894 * | 7185 * |
6895 * Resize a buffer to accommodate minimum size of @size. | 7186 * Resize a buffer to accommodate minimum size of @size. |
6896 * | 7187 * |
6897 * Returns 0 in case of problems, 1 otherwise | 7188 * Returns 0 in case of problems, 1 otherwise |
6898 */ | 7189 */ |
6899 int | 7190 int |
6900 xmlBufferResize(xmlBufferPtr buf, unsigned int size) | 7191 xmlBufferResize(xmlBufferPtr buf, unsigned int size) |
6901 { | 7192 { |
6902 unsigned int newSize; | 7193 unsigned int newSize; |
6903 xmlChar* rebuf = NULL; | 7194 xmlChar* rebuf = NULL; |
| 7195 size_t start_buf; |
6904 | 7196 |
6905 if (buf == NULL) | 7197 if (buf == NULL) |
6906 return(0); | 7198 return(0); |
6907 | 7199 |
6908 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0); | 7200 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) return(0); |
6909 | 7201 |
6910 /* Don't resize if we don't have to */ | 7202 /* Don't resize if we don't have to */ |
6911 if (size < buf->size) | 7203 if (size < buf->size) |
6912 return 1; | 7204 return 1; |
6913 | 7205 |
6914 /* figure out new size */ | 7206 /* figure out new size */ |
6915 switch (buf->alloc){ | 7207 switch (buf->alloc){ |
6916 case XML_BUFFER_ALLOC_DOUBLEIT: | 7208 » case XML_BUFFER_ALLOC_IO: |
6917 » /*take care of empty case*/ | 7209 » case XML_BUFFER_ALLOC_DOUBLEIT: |
6918 newSize = (buf->size ? buf->size*2 : size + 10); | 7210 » /*take care of empty case*/ |
6919 while (size > newSize) newSize *= 2; | 7211 » newSize = (buf->size ? buf->size*2 : size + 10); |
6920 break; | 7212 » while (size > newSize) { |
6921 case XML_BUFFER_ALLOC_EXACT: | 7213 » if (newSize > UINT_MAX / 2) { |
6922 newSize = size+10; | 7214 » xmlTreeErrMemory("growing buffer"); |
6923 break; | 7215 » return 0; |
6924 default: | 7216 » } |
6925 newSize = size+10; | 7217 » newSize *= 2; |
6926 break; | 7218 » } |
| 7219 » break; |
| 7220 » case XML_BUFFER_ALLOC_EXACT: |
| 7221 » newSize = size+10; |
| 7222 » break; |
| 7223 » default: |
| 7224 » newSize = size+10; |
| 7225 » break; |
6927 } | 7226 } |
6928 | 7227 |
6929 if (buf->content == NULL) | 7228 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { |
6930 » rebuf = (xmlChar *) xmlMallocAtomic(newSize * sizeof(xmlChar)); | 7229 start_buf = buf->content - buf->contentIO; |
6931 else if (buf->size - buf->use < 100) { | 7230 |
6932 » rebuf = (xmlChar *) xmlRealloc(buf->content, | 7231 if (start_buf > newSize) { |
6933 » » » » newSize * sizeof(xmlChar)); | 7232 » /* move data back to start */ |
6934 } else { | 7233 » memmove(buf->contentIO, buf->content, buf->use); |
6935 /* | 7234 » buf->content = buf->contentIO; |
6936 » * if we are reallocating a buffer far from being full, it's | 7235 » buf->content[buf->use] = 0; |
6937 » * better to make a new allocation and copy only the used range | 7236 » buf->size += start_buf; |
6938 » * and free the old one. | 7237 » } else { |
6939 » */ | 7238 » rebuf = (xmlChar *) xmlRealloc(buf->contentIO, start_buf + newSize); |
6940 » rebuf = (xmlChar *) xmlMallocAtomic(newSize * sizeof(xmlChar)); | 7239 » if (rebuf == NULL) { |
6941 » if (rebuf != NULL) { | 7240 » » xmlTreeErrMemory("growing buffer"); |
6942 » memcpy(rebuf, buf->content, buf->use); | 7241 » » return 0; |
6943 » xmlFree(buf->content); | 7242 » } |
6944 » rebuf[buf->use] = 0; | 7243 » buf->contentIO = rebuf; |
| 7244 » buf->content = rebuf + start_buf; |
6945 } | 7245 } |
| 7246 } else { |
| 7247 if (buf->content == NULL) { |
| 7248 rebuf = (xmlChar *) xmlMallocAtomic(newSize); |
| 7249 } else if (buf->size - buf->use < 100) { |
| 7250 rebuf = (xmlChar *) xmlRealloc(buf->content, newSize); |
| 7251 } else { |
| 7252 /* |
| 7253 * if we are reallocating a buffer far from being full, it's |
| 7254 * better to make a new allocation and copy only the used range |
| 7255 * and free the old one. |
| 7256 */ |
| 7257 rebuf = (xmlChar *) xmlMallocAtomic(newSize); |
| 7258 if (rebuf != NULL) { |
| 7259 memcpy(rebuf, buf->content, buf->use); |
| 7260 xmlFree(buf->content); |
| 7261 rebuf[buf->use] = 0; |
| 7262 } |
| 7263 } |
| 7264 if (rebuf == NULL) { |
| 7265 xmlTreeErrMemory("growing buffer"); |
| 7266 return 0; |
| 7267 } |
| 7268 buf->content = rebuf; |
6946 } | 7269 } |
6947 if (rebuf == NULL) { | |
6948 xmlTreeErrMemory("growing buffer"); | |
6949 return 0; | |
6950 } | |
6951 buf->content = rebuf; | |
6952 buf->size = newSize; | 7270 buf->size = newSize; |
6953 | 7271 |
6954 return 1; | 7272 return 1; |
6955 } | 7273 } |
6956 | 7274 |
6957 /** | 7275 /** |
6958 * xmlBufferAdd: | 7276 * xmlBufferAdd: |
6959 * @buf: the buffer to dump | 7277 * @buf: the buffer to dump |
6960 * @str: the #xmlChar string | 7278 * @str: the #xmlChar string |
6961 * @len: the number of #xmlChar to add | 7279 * @len: the number of #xmlChar to add |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7036 #endif | 7354 #endif |
7037 return -1; | 7355 return -1; |
7038 } | 7356 } |
7039 if (len == 0) return 0; | 7357 if (len == 0) return 0; |
7040 | 7358 |
7041 if (len < 0) | 7359 if (len < 0) |
7042 len = xmlStrlen(str); | 7360 len = xmlStrlen(str); |
7043 | 7361 |
7044 if (len <= 0) return -1; | 7362 if (len <= 0) return -1; |
7045 | 7363 |
| 7364 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { |
| 7365 size_t start_buf = buf->content - buf->contentIO; |
| 7366 |
| 7367 if (start_buf > (unsigned int) len) { |
| 7368 /* |
| 7369 * We can add it in the space previously shrinked |
| 7370 */ |
| 7371 buf->content -= len; |
| 7372 memmove(&buf->content[0], str, len); |
| 7373 buf->use += len; |
| 7374 buf->size += len; |
| 7375 return(0); |
| 7376 } |
| 7377 } |
7046 needSize = buf->use + len + 2; | 7378 needSize = buf->use + len + 2; |
7047 if (needSize > buf->size){ | 7379 if (needSize > buf->size){ |
7048 if (!xmlBufferResize(buf, needSize)){ | 7380 if (!xmlBufferResize(buf, needSize)){ |
7049 xmlTreeErrMemory("growing buffer"); | 7381 xmlTreeErrMemory("growing buffer"); |
7050 return XML_ERR_NO_MEMORY; | 7382 return XML_ERR_NO_MEMORY; |
7051 } | 7383 } |
7052 } | 7384 } |
7053 | 7385 |
7054 memmove(&buf->content[len], &buf->content[0], buf->use * sizeof(xmlChar)); | 7386 memmove(&buf->content[len], &buf->content[0], buf->use); |
7055 memmove(&buf->content[0], str, len * sizeof(xmlChar)); | 7387 memmove(&buf->content[0], str, len); |
7056 buf->use += len; | 7388 buf->use += len; |
7057 buf->content[buf->use] = 0; | 7389 buf->content[buf->use] = 0; |
7058 return 0; | 7390 return 0; |
7059 } | 7391 } |
7060 | 7392 |
7061 /** | 7393 /** |
7062 * xmlBufferCat: | 7394 * xmlBufferCat: |
7063 * @buf: the buffer to add to | 7395 * @buf: the buffer to add to |
7064 * @str: the #xmlChar string | 7396 * @str: the #xmlChar string |
7065 * | 7397 * |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7292 if ((m)->last == NULL) \ | 7624 if ((m)->last == NULL) \ |
7293 (m)->first = NULL; \ | 7625 (m)->first = NULL; \ |
7294 else \ | 7626 else \ |
7295 (m)->last->next = NULL; \ | 7627 (m)->last->next = NULL; \ |
7296 (i)->next = (m)->pool; \ | 7628 (i)->next = (m)->pool; \ |
7297 (m)->pool = i; | 7629 (m)->pool = i; |
7298 | 7630 |
7299 /* | 7631 /* |
7300 * xmlDOMWrapNsMapFree: | 7632 * xmlDOMWrapNsMapFree: |
7301 * @map: the ns-map | 7633 * @map: the ns-map |
7302 * | 7634 * |
7303 * Frees the ns-map | 7635 * Frees the ns-map |
7304 */ | 7636 */ |
7305 static void | 7637 static void |
7306 xmlDOMWrapNsMapFree(xmlNsMapPtr nsmap) | 7638 xmlDOMWrapNsMapFree(xmlNsMapPtr nsmap) |
7307 { | 7639 { |
7308 xmlNsMapItemPtr cur, tmp; | 7640 xmlNsMapItemPtr cur, tmp; |
7309 | 7641 |
7310 if (nsmap == NULL) | 7642 if (nsmap == NULL) |
7311 return; | 7643 return; |
7312 cur = nsmap->pool; | 7644 cur = nsmap->pool; |
(...skipping 10 matching lines...) Expand all Loading... |
7323 } | 7655 } |
7324 xmlFree(nsmap); | 7656 xmlFree(nsmap); |
7325 } | 7657 } |
7326 | 7658 |
7327 /* | 7659 /* |
7328 * xmlDOMWrapNsMapAddItem: | 7660 * xmlDOMWrapNsMapAddItem: |
7329 * @map: the ns-map | 7661 * @map: the ns-map |
7330 * @oldNs: the old ns-struct | 7662 * @oldNs: the old ns-struct |
7331 * @newNs: the new ns-struct | 7663 * @newNs: the new ns-struct |
7332 * @depth: depth and ns-kind information | 7664 * @depth: depth and ns-kind information |
7333 * | 7665 * |
7334 * Adds an ns-mapping item. | 7666 * Adds an ns-mapping item. |
7335 */ | 7667 */ |
7336 static xmlNsMapItemPtr | 7668 static xmlNsMapItemPtr |
7337 xmlDOMWrapNsMapAddItem(xmlNsMapPtr *nsmap, int position, | 7669 xmlDOMWrapNsMapAddItem(xmlNsMapPtr *nsmap, int position, |
7338 xmlNsPtr oldNs, xmlNsPtr newNs, int depth) | 7670 xmlNsPtr oldNs, xmlNsPtr newNs, int depth) |
7339 { | 7671 { |
7340 xmlNsMapItemPtr ret; | 7672 xmlNsMapItemPtr ret; |
7341 xmlNsMapPtr map; | 7673 xmlNsMapPtr map; |
7342 | 7674 |
7343 if (nsmap == NULL) | 7675 if (nsmap == NULL) |
7344 return(NULL); | 7676 return(NULL); |
7345 if ((position != -1) && (position != 0)) | 7677 if ((position != -1) && (position != 0)) |
7346 return(NULL); | 7678 return(NULL); |
7347 map = *nsmap; | 7679 map = *nsmap; |
7348 | 7680 |
7349 if (map == NULL) { | 7681 if (map == NULL) { |
7350 /* | 7682 /* |
7351 * Create the ns-map. | 7683 * Create the ns-map. |
7352 */ | 7684 */ |
7353 map = (xmlNsMapPtr) xmlMalloc(sizeof(struct xmlNsMap)); | 7685 map = (xmlNsMapPtr) xmlMalloc(sizeof(struct xmlNsMap)); |
7354 if (map == NULL) { | 7686 if (map == NULL) { |
7355 xmlTreeErrMemory("allocating namespace map"); | 7687 xmlTreeErrMemory("allocating namespace map"); |
7356 return (NULL); | 7688 return (NULL); |
7357 } | 7689 } |
7358 memset(map, 0, sizeof(struct xmlNsMap)); | 7690 memset(map, 0, sizeof(struct xmlNsMap)); |
7359 *nsmap = map; | 7691 *nsmap = map; |
7360 } | 7692 } |
7361 | 7693 |
7362 if (map->pool != NULL) { | 7694 if (map->pool != NULL) { |
7363 /* | 7695 /* |
7364 * Reuse an item from the pool. | 7696 * Reuse an item from the pool. |
7365 */ | 7697 */ |
7366 ret = map->pool; | 7698 ret = map->pool; |
7367 map->pool = ret->next; | 7699 map->pool = ret->next; |
7368 memset(ret, 0, sizeof(struct xmlNsMapItem)); | 7700 memset(ret, 0, sizeof(struct xmlNsMapItem)); |
7369 } else { | 7701 } else { |
7370 /* | 7702 /* |
7371 * Create a new item. | 7703 * Create a new item. |
7372 */ | 7704 */ |
7373 ret = (xmlNsMapItemPtr) xmlMalloc(sizeof(struct xmlNsMapItem)); | 7705 ret = (xmlNsMapItemPtr) xmlMalloc(sizeof(struct xmlNsMapItem)); |
7374 if (ret == NULL) { | 7706 if (ret == NULL) { |
7375 xmlTreeErrMemory("allocating namespace map item"); | 7707 xmlTreeErrMemory("allocating namespace map item"); |
7376 return (NULL); | 7708 return (NULL); |
7377 } | 7709 } |
7378 memset(ret, 0, sizeof(struct xmlNsMapItem)); | 7710 memset(ret, 0, sizeof(struct xmlNsMapItem)); |
7379 } | 7711 } |
7380 | 7712 |
7381 if (map->first == NULL) { | 7713 if (map->first == NULL) { |
7382 /* | 7714 /* |
7383 * First ever. | 7715 * First ever. |
7384 » */» | 7716 » */ |
7385 map->first = ret; | 7717 map->first = ret; |
7386 map->last = ret; | 7718 map->last = ret; |
7387 } else if (position == -1) { | 7719 } else if (position == -1) { |
7388 /* | 7720 /* |
7389 * Append. | 7721 * Append. |
7390 */ | 7722 */ |
7391 ret->prev = map->last; | 7723 ret->prev = map->last; |
7392 map->last->next = ret; | 7724 map->last->next = ret; |
7393 » map->last = ret;» » | 7725 » map->last = ret; |
7394 } else if (position == 0) { | 7726 } else if (position == 0) { |
7395 /* | 7727 /* |
7396 * Set on first position. | 7728 * Set on first position. |
7397 */ | 7729 */ |
7398 map->first->prev = ret; | 7730 map->first->prev = ret; |
7399 » ret->next = map->first;»» | 7731 » ret->next = map->first; |
7400 » map->first = ret;» » | 7732 » map->first = ret; |
7401 } else | 7733 } else |
7402 return(NULL); | 7734 return(NULL); |
7403 | 7735 |
7404 ret->oldNs = oldNs; | 7736 ret->oldNs = oldNs; |
7405 ret->newNs = newNs; | 7737 ret->newNs = newNs; |
7406 ret->shadowDepth = -1; | 7738 ret->shadowDepth = -1; |
7407 ret->depth = depth; | 7739 ret->depth = depth; |
7408 return (ret); | 7740 return (ret); |
7409 } | 7741 } |
7410 | 7742 |
7411 /* | 7743 /* |
7412 * xmlDOMWrapStoreNs: | 7744 * xmlDOMWrapStoreNs: |
7413 * @doc: the doc | 7745 * @doc: the doc |
7414 * @nsName: the namespace name | 7746 * @nsName: the namespace name |
7415 * @prefix: the prefix | 7747 * @prefix: the prefix |
7416 * | 7748 * |
7417 * Creates or reuses an xmlNs struct on doc->oldNs with | 7749 * Creates or reuses an xmlNs struct on doc->oldNs with |
7418 * the given prefix and namespace name. | 7750 * the given prefix and namespace name. |
7419 * | 7751 * |
7420 * Returns the aquired ns struct or NULL in case of an API | 7752 * Returns the aquired ns struct or NULL in case of an API |
7421 * or internal error. | 7753 * or internal error. |
7422 */ | 7754 */ |
7423 static xmlNsPtr | 7755 static xmlNsPtr |
7424 xmlDOMWrapStoreNs(xmlDocPtr doc, | 7756 xmlDOMWrapStoreNs(xmlDocPtr doc, |
7425 const xmlChar *nsName, | 7757 const xmlChar *nsName, |
7426 const xmlChar *prefix) | 7758 const xmlChar *prefix) |
7427 { | 7759 { |
7428 xmlNsPtr ns; | 7760 xmlNsPtr ns; |
7429 | 7761 |
(...skipping 10 matching lines...) Expand all Loading... |
7440 xmlStrEqual(ns->prefix, prefix)) && | 7772 xmlStrEqual(ns->prefix, prefix)) && |
7441 xmlStrEqual(ns->href, nsName)) { | 7773 xmlStrEqual(ns->href, nsName)) { |
7442 return (ns); | 7774 return (ns); |
7443 } | 7775 } |
7444 if (ns->next == NULL) | 7776 if (ns->next == NULL) |
7445 break; | 7777 break; |
7446 ns = ns->next; | 7778 ns = ns->next; |
7447 } | 7779 } |
7448 } | 7780 } |
7449 /* Create. */ | 7781 /* Create. */ |
7450 ns->next = xmlNewNs(NULL, nsName, prefix); | 7782 if (ns != NULL) { |
7451 return (ns->next); | 7783 ns->next = xmlNewNs(NULL, nsName, prefix); |
| 7784 return (ns->next); |
| 7785 } |
| 7786 return(NULL); |
7452 } | 7787 } |
7453 | 7788 |
7454 /* | 7789 /* |
7455 * xmlDOMWrapNewCtxt: | 7790 * xmlDOMWrapNewCtxt: |
7456 * | 7791 * |
7457 * Allocates and initializes a new DOM-wrapper context. | 7792 * Allocates and initializes a new DOM-wrapper context. |
7458 * | 7793 * |
7459 * Returns the xmlDOMWrapCtxtPtr or NULL in case of an internal errror. | 7794 * Returns the xmlDOMWrapCtxtPtr or NULL in case of an internal errror. |
7460 */ | 7795 */ |
7461 xmlDOMWrapCtxtPtr | 7796 xmlDOMWrapCtxtPtr |
7462 xmlDOMWrapNewCtxt(void) | 7797 xmlDOMWrapNewCtxt(void) |
7463 { | 7798 { |
7464 xmlDOMWrapCtxtPtr ret; | 7799 xmlDOMWrapCtxtPtr ret; |
7465 | 7800 |
7466 ret = xmlMalloc(sizeof(xmlDOMWrapCtxt)); | 7801 ret = xmlMalloc(sizeof(xmlDOMWrapCtxt)); |
7467 if (ret == NULL) { | 7802 if (ret == NULL) { |
7468 xmlTreeErrMemory("allocating DOM-wrapper context"); | 7803 xmlTreeErrMemory("allocating DOM-wrapper context"); |
7469 return (NULL); | 7804 return (NULL); |
(...skipping 18 matching lines...) Expand all Loading... |
7488 /* | 7823 /* |
7489 * TODO: Store the namespace map in the context. | 7824 * TODO: Store the namespace map in the context. |
7490 */ | 7825 */ |
7491 xmlFree(ctxt); | 7826 xmlFree(ctxt); |
7492 } | 7827 } |
7493 | 7828 |
7494 /* | 7829 /* |
7495 * xmlTreeLookupNsListByPrefix: | 7830 * xmlTreeLookupNsListByPrefix: |
7496 * @nsList: a list of ns-structs | 7831 * @nsList: a list of ns-structs |
7497 * @prefix: the searched prefix | 7832 * @prefix: the searched prefix |
7498 * | 7833 * |
7499 * Searches for a ns-decl with the given prefix in @nsList. | 7834 * Searches for a ns-decl with the given prefix in @nsList. |
7500 * | 7835 * |
7501 * Returns the ns-decl if found, NULL if not found and on | 7836 * Returns the ns-decl if found, NULL if not found and on |
7502 * API errors. | 7837 * API errors. |
7503 */ | 7838 */ |
7504 static xmlNsPtr | 7839 static xmlNsPtr |
7505 xmlTreeNSListLookupByPrefix(xmlNsPtr nsList, const xmlChar *prefix) | 7840 xmlTreeNSListLookupByPrefix(xmlNsPtr nsList, const xmlChar *prefix) |
7506 { | 7841 { |
7507 if (nsList == NULL) | 7842 if (nsList == NULL) |
7508 return (NULL); | 7843 return (NULL); |
7509 { | 7844 { |
7510 xmlNsPtr ns; | 7845 xmlNsPtr ns; |
7511 ns = nsList; | 7846 ns = nsList; |
7512 do { | 7847 do { |
7513 if ((prefix == ns->prefix) || | 7848 if ((prefix == ns->prefix) || |
7514 xmlStrEqual(prefix, ns->prefix)) { | 7849 xmlStrEqual(prefix, ns->prefix)) { |
7515 return (ns); | 7850 return (ns); |
7516 } | 7851 } |
7517 ns = ns->next; | 7852 ns = ns->next; |
7518 } while (ns != NULL); | 7853 } while (ns != NULL); |
7519 } | 7854 } |
7520 return (NULL); | 7855 return (NULL); |
7521 } | 7856 } |
7522 | 7857 |
7523 /* | 7858 /* |
7524 * | 7859 * |
7525 * xmlDOMWrapNSNormGatherInScopeNs: | 7860 * xmlDOMWrapNSNormGatherInScopeNs: |
7526 * @map: the namespace map | 7861 * @map: the namespace map |
7527 * @node: the node to start with | 7862 * @node: the node to start with |
7528 * | 7863 * |
7529 * Puts in-scope namespaces into the ns-map. | 7864 * Puts in-scope namespaces into the ns-map. |
7530 * | 7865 * |
7531 * Returns 0 on success, -1 on API or internal errors. | 7866 * Returns 0 on success, -1 on API or internal errors. |
7532 */ | 7867 */ |
7533 static int | 7868 static int |
7534 xmlDOMWrapNSNormGatherInScopeNs(xmlNsMapPtr *map, | 7869 xmlDOMWrapNSNormGatherInScopeNs(xmlNsMapPtr *map, |
7535 xmlNodePtr node) | 7870 xmlNodePtr node) |
7536 { | 7871 { |
7537 xmlNodePtr cur; | 7872 xmlNodePtr cur; |
7538 xmlNsPtr ns; | 7873 xmlNsPtr ns; |
7539 xmlNsMapItemPtr mi; | 7874 xmlNsMapItemPtr mi; |
7540 int shadowed; | 7875 int shadowed; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7612 xmlDictLookup(destDoc->dict, cur->content, -1); \ | 7947 xmlDictLookup(destDoc->dict, cur->content, -1); \ |
7613 else \ | 7948 else \ |
7614 cur->content = xmlStrdup(BAD_CAST cur->content); \ | 7949 cur->content = xmlStrdup(BAD_CAST cur->content); \ |
7615 } | 7950 } |
7616 | 7951 |
7617 /* | 7952 /* |
7618 * xmlDOMWrapNSNormAddNsMapItem2: | 7953 * xmlDOMWrapNSNormAddNsMapItem2: |
7619 * | 7954 * |
7620 * For internal use. Adds a ns-decl mapping. | 7955 * For internal use. Adds a ns-decl mapping. |
7621 * | 7956 * |
7622 * Returns 0 on success, -1 on internal errors. | 7957 * Returns 0 on success, -1 on internal errors. |
7623 */ | 7958 */ |
7624 static int | 7959 static int |
7625 xmlDOMWrapNSNormAddNsMapItem2(xmlNsPtr **list, int *size, int *number, | 7960 xmlDOMWrapNSNormAddNsMapItem2(xmlNsPtr **list, int *size, int *number, |
7626 xmlNsPtr oldNs, xmlNsPtr newNs) | 7961 xmlNsPtr oldNs, xmlNsPtr newNs) |
7627 { | 7962 { |
7628 if (*list == NULL) { | 7963 if (*list == NULL) { |
7629 *list = (xmlNsPtr *) xmlMalloc(6 * sizeof(xmlNsPtr)); | 7964 *list = (xmlNsPtr *) xmlMalloc(6 * sizeof(xmlNsPtr)); |
7630 if (*list == NULL) { | 7965 if (*list == NULL) { |
7631 xmlTreeErrMemory("alloc ns map item"); | 7966 xmlTreeErrMemory("alloc ns map item"); |
7632 return(-1); | 7967 return(-1); |
(...skipping 23 matching lines...) Expand all Loading... |
7656 * @options: set of options, unused at the moment | 7991 * @options: set of options, unused at the moment |
7657 * | 7992 * |
7658 * Unlinks the given node from its owner. | 7993 * Unlinks the given node from its owner. |
7659 * This will substitute ns-references to node->nsDef for | 7994 * This will substitute ns-references to node->nsDef for |
7660 * ns-references to doc->oldNs, thus ensuring the removed | 7995 * ns-references to doc->oldNs, thus ensuring the removed |
7661 * branch to be autark wrt ns-references. | 7996 * branch to be autark wrt ns-references. |
7662 * | 7997 * |
7663 * NOTE: This function was not intensively tested. | 7998 * NOTE: This function was not intensively tested. |
7664 * | 7999 * |
7665 * Returns 0 on success, 1 if the node is not supported, | 8000 * Returns 0 on success, 1 if the node is not supported, |
7666 * -1 on API and internal errors. | 8001 * -1 on API and internal errors. |
7667 */ | 8002 */ |
7668 int | 8003 int |
7669 xmlDOMWrapRemoveNode(xmlDOMWrapCtxtPtr ctxt, xmlDocPtr doc, | 8004 xmlDOMWrapRemoveNode(xmlDOMWrapCtxtPtr ctxt, xmlDocPtr doc, |
7670 xmlNodePtr node, int options ATTRIBUTE_UNUSED) | 8005 xmlNodePtr node, int options ATTRIBUTE_UNUSED) |
7671 { | 8006 { |
7672 xmlNsPtr *list = NULL; | 8007 xmlNsPtr *list = NULL; |
7673 int sizeList, nbList, i, j; | 8008 int sizeList, nbList, i, j; |
7674 xmlNsPtr ns; | 8009 xmlNsPtr ns; |
7675 | 8010 |
7676 if ((node == NULL) || (doc == NULL) || (node->doc != doc)) | 8011 if ((node == NULL) || (doc == NULL) || (node->doc != doc)) |
7677 return (-1); | 8012 return (-1); |
7678 | 8013 |
7679 /* TODO: 0 or -1 ? */ | 8014 /* TODO: 0 or -1 ? */ |
7680 if (node->parent == NULL) | 8015 if (node->parent == NULL) |
7681 return (0); | 8016 return (0); |
7682 | 8017 |
7683 switch (node->type) { » | 8018 switch (node->type) { |
7684 case XML_TEXT_NODE: | 8019 case XML_TEXT_NODE: |
7685 case XML_CDATA_SECTION_NODE: | 8020 case XML_CDATA_SECTION_NODE: |
7686 case XML_ENTITY_REF_NODE: | 8021 case XML_ENTITY_REF_NODE: |
7687 case XML_PI_NODE: | 8022 case XML_PI_NODE: |
7688 case XML_COMMENT_NODE: | 8023 case XML_COMMENT_NODE: |
7689 xmlUnlinkNode(node); | 8024 xmlUnlinkNode(node); |
7690 return (0); | 8025 return (0); |
7691 » case XML_ELEMENT_NODE:» | 8026 » case XML_ELEMENT_NODE: |
7692 case XML_ATTRIBUTE_NODE: | 8027 case XML_ATTRIBUTE_NODE: |
7693 break; | 8028 break; |
7694 default: | 8029 default: |
7695 return (1); | 8030 return (1); |
7696 } | 8031 } |
7697 xmlUnlinkNode(node); | 8032 xmlUnlinkNode(node); |
7698 /* | 8033 /* |
7699 * Save out-of-scope ns-references in doc->oldNs. | 8034 * Save out-of-scope ns-references in doc->oldNs. |
7700 */ | 8035 */ |
7701 do { | 8036 do { |
7702 switch (node->type) { | 8037 switch (node->type) { |
7703 case XML_ELEMENT_NODE: | 8038 case XML_ELEMENT_NODE: |
7704 if ((ctxt == NULL) && (node->nsDef != NULL)) { | 8039 if ((ctxt == NULL) && (node->nsDef != NULL)) { |
7705 ns = node->nsDef; | 8040 ns = node->nsDef; |
7706 do { | 8041 do { |
7707 if (xmlDOMWrapNSNormAddNsMapItem2(&list, &sizeList, | 8042 if (xmlDOMWrapNSNormAddNsMapItem2(&list, &sizeList, |
7708 &nbList, ns, ns) == -1) | 8043 &nbList, ns, ns) == -1) |
7709 goto internal_error; | 8044 goto internal_error; |
7710 ns = ns->next; | 8045 ns = ns->next; |
7711 } while (ns != NULL); | 8046 } while (ns != NULL); |
7712 } | 8047 } |
7713 /* No break on purpose. */ | 8048 /* No break on purpose. */ |
7714 case XML_ATTRIBUTE_NODE: | 8049 case XML_ATTRIBUTE_NODE: |
7715 » » if (node->ns != NULL) {»» | 8050 » » if (node->ns != NULL) { |
7716 /* | 8051 /* |
7717 * Find a mapping. | 8052 * Find a mapping. |
7718 */ | 8053 */ |
7719 if (list != NULL) { | 8054 if (list != NULL) { |
7720 for (i = 0, j = 0; i < nbList; i++, j += 2) { | 8055 for (i = 0, j = 0; i < nbList; i++, j += 2) { |
7721 if (node->ns == list[j]) { | 8056 if (node->ns == list[j]) { |
7722 node->ns = list[++j]; | 8057 node->ns = list[++j]; |
7723 goto next_node; | 8058 goto next_node; |
7724 } | 8059 } |
7725 } | 8060 } |
(...skipping 23 matching lines...) Expand all Loading... |
7749 node->ns = ns; | 8084 node->ns = ns; |
7750 } | 8085 } |
7751 if ((node->type == XML_ELEMENT_NODE) && | 8086 if ((node->type == XML_ELEMENT_NODE) && |
7752 (node->properties != NULL)) { | 8087 (node->properties != NULL)) { |
7753 node = (xmlNodePtr) node->properties; | 8088 node = (xmlNodePtr) node->properties; |
7754 continue; | 8089 continue; |
7755 } | 8090 } |
7756 break; | 8091 break; |
7757 default: | 8092 default: |
7758 goto next_sibling; | 8093 goto next_sibling; |
7759 » }» | 8094 » } |
7760 next_node:» | 8095 next_node: |
7761 if ((node->type == XML_ELEMENT_NODE) && | 8096 if ((node->type == XML_ELEMENT_NODE) && |
7762 (node->children != NULL)) { | 8097 (node->children != NULL)) { |
7763 node = node->children; | 8098 node = node->children; |
7764 continue; | 8099 continue; |
7765 } | 8100 } |
7766 next_sibling:» | 8101 next_sibling: |
7767 if (node == NULL) | 8102 if (node == NULL) |
7768 break; | 8103 break; |
7769 if (node->next != NULL) | 8104 if (node->next != NULL) |
7770 node = node->next; | 8105 node = node->next; |
7771 else { | 8106 else { |
7772 node = node->parent; | 8107 node = node->parent; |
7773 goto next_sibling; | 8108 goto next_sibling; |
7774 } | 8109 } |
7775 } while (node != NULL); | 8110 } while (node != NULL); |
7776 | 8111 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7849 */ | 8184 */ |
7850 if ((nsName == ns->href) || | 8185 if ((nsName == ns->href) || |
7851 xmlStrEqual(nsName, ns->href)) { | 8186 xmlStrEqual(nsName, ns->href)) { |
7852 /* | 8187 /* |
7853 * At this point the prefix can only be shadowed, | 8188 * At this point the prefix can only be shadowed, |
7854 * if we are the the (at least) 3rd level of | 8189 * if we are the the (at least) 3rd level of |
7855 * ns-decls. | 8190 * ns-decls. |
7856 */ | 8191 */ |
7857 if (out) { | 8192 if (out) { |
7858 int ret; | 8193 int ret; |
7859 » » » | 8194 |
7860 ret = xmlNsInScope(doc, node, prev, ns->prefix); | 8195 ret = xmlNsInScope(doc, node, prev, ns->prefix); |
7861 if (ret < 0) | 8196 if (ret < 0) |
7862 return (-1); | 8197 return (-1); |
7863 /* | 8198 /* |
7864 * TODO: Should we try to find a matching ns-name | 8199 * TODO: Should we try to find a matching ns-name |
7865 * only once? This here keeps on searching. | 8200 * only once? This here keeps on searching. |
7866 * I think we should try further since, there might | 8201 * I think we should try further since, there might |
7867 * be an other matching ns-decl with an unshadowed | 8202 * be an other matching ns-decl with an unshadowed |
7868 * prefix. | 8203 * prefix. |
7869 */ | 8204 */ |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7917 if (*retNs == NULL) | 8252 if (*retNs == NULL) |
7918 return (-1); | 8253 return (-1); |
7919 } | 8254 } |
7920 return (1); | 8255 return (1); |
7921 } | 8256 } |
7922 cur = node; | 8257 cur = node; |
7923 do { | 8258 do { |
7924 if (cur->type == XML_ELEMENT_NODE) { | 8259 if (cur->type == XML_ELEMENT_NODE) { |
7925 if (cur->nsDef != NULL) { | 8260 if (cur->nsDef != NULL) { |
7926 ns = cur->nsDef; | 8261 ns = cur->nsDef; |
7927 » » do {» » | 8262 » » do { |
7928 if ((prefix == ns->prefix) || | 8263 if ((prefix == ns->prefix) || |
7929 xmlStrEqual(prefix, ns->prefix)) | 8264 xmlStrEqual(prefix, ns->prefix)) |
7930 { | 8265 { |
7931 /* | 8266 /* |
7932 * Disabled namespaces, e.g. xmlns:abc="". | 8267 * Disabled namespaces, e.g. xmlns:abc="". |
7933 */ | 8268 */ |
7934 if (ns->href == NULL) | 8269 if (ns->href == NULL) |
7935 return(0); | 8270 return(0); |
7936 if (retNs) | 8271 if (retNs) |
7937 *retNs = ns; | 8272 *retNs = ns; |
7938 return (1); | 8273 return (1); |
7939 } | 8274 } |
7940 ns = ns->next; | 8275 ns = ns->next; |
7941 » » } while (ns != NULL);» | 8276 » » } while (ns != NULL); |
7942 } | 8277 } |
7943 } else if ((cur->type == XML_ENTITY_NODE) || | 8278 } else if ((cur->type == XML_ENTITY_NODE) || |
7944 (cur->type == XML_ENTITY_DECL)) | 8279 (cur->type == XML_ENTITY_DECL)) |
7945 return (0); | 8280 return (0); |
7946 cur = cur->parent; | 8281 cur = cur->parent; |
7947 } while ((cur != NULL) && (cur->doc != (xmlDocPtr) cur)); | 8282 } while ((cur != NULL) && (cur->doc != (xmlDocPtr) cur)); |
7948 return (0); | 8283 return (0); |
7949 } | 8284 } |
7950 | 8285 |
7951 /* | 8286 /* |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8038 * change the prefix or the new ns-decl. | 8373 * change the prefix or the new ns-decl. |
8039 * | 8374 * |
8040 * Returns 0 if succeeded, -1 otherwise and on API/internal errors. | 8375 * Returns 0 if succeeded, -1 otherwise and on API/internal errors. |
8041 */ | 8376 */ |
8042 static int | 8377 static int |
8043 xmlDOMWrapNSNormAquireNormalizedNs(xmlDocPtr doc, | 8378 xmlDOMWrapNSNormAquireNormalizedNs(xmlDocPtr doc, |
8044 xmlNodePtr elem, | 8379 xmlNodePtr elem, |
8045 xmlNsPtr ns, | 8380 xmlNsPtr ns, |
8046 xmlNsPtr *retNs, | 8381 xmlNsPtr *retNs, |
8047 xmlNsMapPtr *nsMap, | 8382 xmlNsMapPtr *nsMap, |
8048 » » » » | 8383 |
8049 int depth, | 8384 int depth, |
8050 int ancestorsOnly, | 8385 int ancestorsOnly, |
8051 int prefixed) | 8386 int prefixed) |
8052 { | 8387 { |
8053 xmlNsMapItemPtr mi; | 8388 xmlNsMapItemPtr mi; |
8054 | 8389 |
8055 if ((doc == NULL) || (ns == NULL) || (retNs == NULL) || | 8390 if ((doc == NULL) || (ns == NULL) || (retNs == NULL) || |
8056 (nsMap == NULL)) | 8391 (nsMap == NULL)) |
8057 return (-1); | 8392 return (-1); |
8058 | 8393 |
8059 *retNs = NULL; | 8394 *retNs = NULL; |
8060 /* | 8395 /* |
8061 * Handle XML namespace. | 8396 * Handle XML namespace. |
8062 */ | 8397 */ |
8063 if (IS_STR_XML(ns->prefix)) { | 8398 if (IS_STR_XML(ns->prefix)) { |
8064 /* | 8399 /* |
8065 * Insert XML namespace mapping. | 8400 * Insert XML namespace mapping. |
8066 */ | 8401 */ |
8067 *retNs = xmlTreeEnsureXMLDecl(doc); | 8402 *retNs = xmlTreeEnsureXMLDecl(doc); |
8068 if (*retNs == NULL) | 8403 if (*retNs == NULL) |
8069 return (-1); | 8404 return (-1); |
8070 return (0); | 8405 return (0); |
8071 } | 8406 } |
8072 /* | 8407 /* |
8073 * If the search should be done in ancestors only and no | 8408 * If the search should be done in ancestors only and no |
8074 * @elem (the first ancestor) was specified, then skip the search. | 8409 * @elem (the first ancestor) was specified, then skip the search. |
8075 */ | 8410 */ |
8076 if ((XML_NSMAP_NOTEMPTY(*nsMap)) && | 8411 if ((XML_NSMAP_NOTEMPTY(*nsMap)) && |
8077 (! (ancestorsOnly && (elem == NULL)))) | 8412 (! (ancestorsOnly && (elem == NULL)))) |
8078 {» | 8413 { |
8079 /* | 8414 /* |
8080 * Try to find an equal ns-name in in-scope ns-decls. | 8415 * Try to find an equal ns-name in in-scope ns-decls. |
8081 */ | 8416 */ |
8082 XML_NSMAP_FOREACH(*nsMap, mi) { | 8417 XML_NSMAP_FOREACH(*nsMap, mi) { |
8083 » if ((mi->depth >= XML_TREE_NSMAP_PARENT) && » » »
» | 8418 » if ((mi->depth >= XML_TREE_NSMAP_PARENT) && |
8084 » » /* | 8419 » » /* |
8085 * ancestorsOnly: This should be turned on to gain speed, | 8420 * ancestorsOnly: This should be turned on to gain speed, |
8086 * if one knows that the branch itself was already | 8421 * if one knows that the branch itself was already |
8087 * ns-wellformed and no stale references existed. | 8422 * ns-wellformed and no stale references existed. |
8088 * I.e. it searches in the ancestor axis only. | 8423 * I.e. it searches in the ancestor axis only. |
8089 */ | 8424 */ |
8090 ((! ancestorsOnly) || (mi->depth == XML_TREE_NSMAP_PARENT)) && | 8425 ((! ancestorsOnly) || (mi->depth == XML_TREE_NSMAP_PARENT)) && |
8091 /* Skip shadowed prefixes. */ | 8426 /* Skip shadowed prefixes. */ |
8092 » » (mi->shadowDepth == -1) &&» » | 8427 » » (mi->shadowDepth == -1) && |
8093 /* Skip xmlns="" or xmlns:foo="". */ | 8428 /* Skip xmlns="" or xmlns:foo="". */ |
8094 ((mi->newNs->href != NULL) && | 8429 ((mi->newNs->href != NULL) && |
8095 » » (mi->newNs->href[0] != 0)) &&» » | 8430 » » (mi->newNs->href[0] != 0)) && |
8096 /* Ensure a prefix if wanted. */ | 8431 /* Ensure a prefix if wanted. */ |
8097 ((! prefixed) || (mi->newNs->prefix != NULL)) && | 8432 ((! prefixed) || (mi->newNs->prefix != NULL)) && |
8098 /* Equal ns name */ | 8433 /* Equal ns name */ |
8099 ((mi->newNs->href == ns->href) || | 8434 ((mi->newNs->href == ns->href) || |
8100 xmlStrEqual(mi->newNs->href, ns->href))) { | 8435 xmlStrEqual(mi->newNs->href, ns->href))) { |
8101 /* Set the mapping. */ | 8436 /* Set the mapping. */ |
8102 mi->oldNs = ns; | 8437 mi->oldNs = ns; |
8103 *retNs = mi->newNs; | 8438 *retNs = mi->newNs; |
8104 return (0); | 8439 return (0); |
8105 } | 8440 } |
8106 } | 8441 } |
8107 } | 8442 } |
8108 /* | 8443 /* |
8109 * No luck, the namespace is out of scope or shadowed. | 8444 * No luck, the namespace is out of scope or shadowed. |
8110 */ | 8445 */ |
8111 if (elem == NULL) { | 8446 if (elem == NULL) { |
8112 xmlNsPtr tmpns; | 8447 xmlNsPtr tmpns; |
8113 | 8448 |
8114 /* | 8449 /* |
8115 * Store ns-decls in "oldNs" of the document-node. | 8450 * Store ns-decls in "oldNs" of the document-node. |
8116 */ | 8451 */ |
8117 tmpns = xmlDOMWrapStoreNs(doc, ns->href, ns->prefix); | 8452 tmpns = xmlDOMWrapStoreNs(doc, ns->href, ns->prefix); |
8118 if (tmpns == NULL) | 8453 if (tmpns == NULL) |
8119 return (-1); | 8454 return (-1); |
8120 /* | 8455 /* |
8121 * Insert mapping. | 8456 * Insert mapping. |
8122 » */» | 8457 » */ |
8123 if (xmlDOMWrapNsMapAddItem(nsMap, -1, ns, | 8458 if (xmlDOMWrapNsMapAddItem(nsMap, -1, ns, |
8124 tmpns, XML_TREE_NSMAP_DOC) == NULL) { | 8459 tmpns, XML_TREE_NSMAP_DOC) == NULL) { |
8125 xmlFreeNs(tmpns); | 8460 xmlFreeNs(tmpns); |
8126 return (-1); | 8461 return (-1); |
8127 } | 8462 } |
8128 *retNs = tmpns; | 8463 *retNs = tmpns; |
8129 } else { | 8464 } else { |
8130 xmlNsPtr tmpns; | 8465 xmlNsPtr tmpns; |
8131 | 8466 |
8132 tmpns = xmlDOMWrapNSNormDeclareNsForced(doc, elem, ns->href, | 8467 tmpns = xmlDOMWrapNSNormDeclareNsForced(doc, elem, ns->href, |
(...skipping 21 matching lines...) Expand all Loading... |
8154 if (xmlDOMWrapNsMapAddItem(nsMap, -1, ns, tmpns, depth) == NULL) { | 8489 if (xmlDOMWrapNsMapAddItem(nsMap, -1, ns, tmpns, depth) == NULL) { |
8155 xmlFreeNs(tmpns); | 8490 xmlFreeNs(tmpns); |
8156 return (-1); | 8491 return (-1); |
8157 } | 8492 } |
8158 *retNs = tmpns; | 8493 *retNs = tmpns; |
8159 } | 8494 } |
8160 return (0); | 8495 return (0); |
8161 } | 8496 } |
8162 | 8497 |
8163 typedef enum { | 8498 typedef enum { |
8164 XML_DOM_RECONNS_REMOVEREDUND = 1<<0 | 8499 XML_DOM_RECONNS_REMOVEREDUND = 1<<0 |
8165 } xmlDOMReconcileNSOptions; | 8500 } xmlDOMReconcileNSOptions; |
8166 | 8501 |
8167 /* | 8502 /* |
8168 * xmlDOMWrapReconcileNamespaces: | 8503 * xmlDOMWrapReconcileNamespaces: |
8169 * @ctxt: DOM wrapper context, unused at the moment | 8504 * @ctxt: DOM wrapper context, unused at the moment |
8170 * @elem: the element-node | 8505 * @elem: the element-node |
8171 * @options: option flags | 8506 * @options: option flags |
8172 * | 8507 * |
8173 * Ensures that ns-references point to ns-decls hold on element-nodes. | 8508 * Ensures that ns-references point to ns-decls hold on element-nodes. |
8174 * Ensures that the tree is namespace wellformed by creating additional | 8509 * Ensures that the tree is namespace wellformed by creating additional |
8175 * ns-decls where needed. Note that, since prefixes of already existent | 8510 * ns-decls where needed. Note that, since prefixes of already existent |
8176 * ns-decls can be shadowed by this process, it could break QNames in | 8511 * ns-decls can be shadowed by this process, it could break QNames in |
8177 * attribute values or element content. | 8512 * attribute values or element content. |
8178 * | 8513 * |
8179 * NOTE: This function was not intensively tested. | 8514 * NOTE: This function was not intensively tested. |
8180 * | 8515 * |
8181 * Returns 0 if succeeded, -1 otherwise and on API/internal errors. | 8516 * Returns 0 if succeeded, -1 otherwise and on API/internal errors. |
8182 */ | 8517 */ |
8183 | 8518 |
8184 int | 8519 int |
8185 xmlDOMWrapReconcileNamespaces(xmlDOMWrapCtxtPtr ctxt ATTRIBUTE_UNUSED, | 8520 xmlDOMWrapReconcileNamespaces(xmlDOMWrapCtxtPtr ctxt ATTRIBUTE_UNUSED, |
8186 xmlNodePtr elem, | 8521 xmlNodePtr elem, |
8187 int options) | 8522 int options) |
8188 { | 8523 { |
8189 int depth = -1, adoptns = 0, parnsdone = 0; | 8524 int depth = -1, adoptns = 0, parnsdone = 0; |
8190 xmlNsPtr ns, prevns; | 8525 xmlNsPtr ns, prevns; |
8191 xmlDocPtr doc; | 8526 xmlDocPtr doc; |
8192 xmlNodePtr cur, curElem = NULL; | 8527 xmlNodePtr cur, curElem = NULL; |
8193 xmlNsMapPtr nsMap = NULL; | 8528 xmlNsMapPtr nsMap = NULL; |
8194 xmlNsMapItemPtr /* topmi = NULL, */ mi; | 8529 xmlNsMapItemPtr /* topmi = NULL, */ mi; |
8195 /* @ancestorsOnly should be set by an option flag. */ | 8530 /* @ancestorsOnly should be set by an option flag. */ |
8196 int ancestorsOnly = 0; | 8531 int ancestorsOnly = 0; |
8197 int optRemoveRedundantNS = | 8532 int optRemoveRedundantNS = |
8198 ((xmlDOMReconcileNSOptions) options & XML_DOM_RECONNS_REMOVEREDUND) ? 1
: 0; | 8533 ((xmlDOMReconcileNSOptions) options & XML_DOM_RECONNS_REMOVEREDUND) ? 1
: 0; |
8199 xmlNsPtr *listRedund = NULL; | 8534 xmlNsPtr *listRedund = NULL; |
8200 int sizeRedund = 0, nbRedund = 0, ret, i, j; | 8535 int sizeRedund = 0, nbRedund = 0, ret, i, j; |
8201 | 8536 |
8202 if ((elem == NULL) || (elem->doc == NULL) || | 8537 if ((elem == NULL) || (elem->doc == NULL) || |
8203 (elem->type != XML_ELEMENT_NODE)) | 8538 (elem->type != XML_ELEMENT_NODE)) |
8204 return (-1); | 8539 return (-1); |
8205 | 8540 |
8206 doc = elem->doc; | 8541 doc = elem->doc; |
8207 cur = elem; | 8542 cur = elem; |
(...skipping 15 matching lines...) Expand all Loading... |
8223 ((xmlNodePtr) elem->parent->doc != elem->parent)
) { | 8558 ((xmlNodePtr) elem->parent->doc != elem->parent)
) { |
8224 /* | 8559 /* |
8225 * Gather ancestor in-scope ns-decls. | 8560 * Gather ancestor in-scope ns-decls. |
8226 */ | 8561 */ |
8227 if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, | 8562 if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, |
8228 elem->parent) == -1) | 8563 elem->parent) == -1) |
8229 goto internal_error; | 8564 goto internal_error; |
8230 } | 8565 } |
8231 parnsdone = 1; | 8566 parnsdone = 1; |
8232 } | 8567 } |
8233 » » » | 8568 |
8234 /* | 8569 /* |
8235 * Lookup the ns ancestor-axis for equal ns-decls in scop
e. | 8570 * Lookup the ns ancestor-axis for equal ns-decls in scop
e. |
8236 */ | 8571 */ |
8237 if (optRemoveRedundantNS && XML_NSMAP_NOTEMPTY(nsMap)) { | 8572 if (optRemoveRedundantNS && XML_NSMAP_NOTEMPTY(nsMap)) { |
8238 XML_NSMAP_FOREACH(nsMap, mi) { | 8573 XML_NSMAP_FOREACH(nsMap, mi) { |
8239 if ((mi->depth >= XML_TREE_NSMAP_PARENT) && | 8574 if ((mi->depth >= XML_TREE_NSMAP_PARENT) && |
8240 (mi->shadowDepth == -1) && | 8575 (mi->shadowDepth == -1) && |
8241 ((ns->prefix == mi->newNs->prefix) || | 8576 ((ns->prefix == mi->newNs->prefix) || |
8242 xmlStrEqual(ns->prefix, mi->newNs->prefix)
) && | 8577 xmlStrEqual(ns->prefix, mi->newNs->prefix)
) && |
8243 ((ns->href == mi->newNs->href) || | 8578 ((ns->href == mi->newNs->href) || |
8244 xmlStrEqual(ns->href, mi->newNs->href))) | 8579 xmlStrEqual(ns->href, mi->newNs->href))) |
8245 » » » » {» » » » | 8580 » » » » { |
8246 /* | 8581 /* |
8247 * A redundant ns-decl was found. | 8582 * A redundant ns-decl was found. |
8248 * Add it to the list of redundant ns-decls. | 8583 * Add it to the list of redundant ns-decls. |
8249 */ | 8584 */ |
8250 if (xmlDOMWrapNSNormAddNsMapItem2(&listRedun
d, | 8585 if (xmlDOMWrapNSNormAddNsMapItem2(&listRedun
d, |
8251 &sizeRedund, &nbRedund, ns, mi->newNs) =
= -1) | 8586 &sizeRedund, &nbRedund, ns, mi->newNs) =
= -1) |
8252 goto internal_error; | 8587 goto internal_error; |
8253 /* | 8588 /* |
8254 * Remove the ns-decl from the element-node. | 8589 * Remove the ns-decl from the element-node. |
8255 » » » » */» » » » | 8590 » » » » */ |
8256 if (prevns) | 8591 if (prevns) |
8257 prevns->next = ns->next; | 8592 prevns->next = ns->next; |
8258 else | 8593 else |
8259 » » » » » cur->nsDef = ns->next;» » »
» » » » » | 8594 » » » » » cur->nsDef = ns->next; |
8260 goto next_ns_decl; | 8595 goto next_ns_decl; |
8261 } | 8596 } |
8262 } | 8597 } |
8263 } | 8598 } |
8264 | 8599 |
8265 /* | 8600 /* |
8266 * Skip ns-references handling if the referenced | 8601 * Skip ns-references handling if the referenced |
8267 * ns-decl is declared on the same element. | 8602 * ns-decl is declared on the same element. |
8268 */ | 8603 */ |
8269 if ((cur->ns != NULL) && adoptns && (cur->ns == ns)) | 8604 if ((cur->ns != NULL) && adoptns && (cur->ns == ns)) |
8270 » » » adoptns = 0;» » » » »
» | 8605 » » » adoptns = 0; |
8271 /* | 8606 /* |
8272 * Does it shadow any ns-decl? | 8607 * Does it shadow any ns-decl? |
8273 */ | 8608 */ |
8274 if (XML_NSMAP_NOTEMPTY(nsMap)) { | 8609 if (XML_NSMAP_NOTEMPTY(nsMap)) { |
8275 XML_NSMAP_FOREACH(nsMap, mi) { | 8610 XML_NSMAP_FOREACH(nsMap, mi) { |
8276 if ((mi->depth >= XML_TREE_NSMAP_PARENT) && | 8611 if ((mi->depth >= XML_TREE_NSMAP_PARENT) && |
8277 (mi->shadowDepth == -1) && | 8612 (mi->shadowDepth == -1) && |
8278 ((ns->prefix == mi->newNs->prefix) || | 8613 ((ns->prefix == mi->newNs->prefix) || |
8279 xmlStrEqual(ns->prefix, mi->newNs->prefix)))
{ | 8614 xmlStrEqual(ns->prefix, mi->newNs->prefix)))
{ |
8280 » » » » | 8615 |
8281 mi->shadowDepth = depth; | 8616 mi->shadowDepth = depth; |
8282 } | 8617 } |
8283 } | 8618 } |
8284 } | 8619 } |
8285 /* | 8620 /* |
8286 * Push mapping. | 8621 * Push mapping. |
8287 */ | 8622 */ |
8288 if (xmlDOMWrapNsMapAddItem(&nsMap, -1, ns, ns, | 8623 if (xmlDOMWrapNsMapAddItem(&nsMap, -1, ns, ns, |
8289 depth) == NULL) | 8624 depth) == NULL) |
8290 » » » goto internal_error;» » » | 8625 » » » goto internal_error; |
8291 | 8626 |
8292 prevns = ns; | 8627 prevns = ns; |
8293 next_ns_decl: | 8628 next_ns_decl: |
8294 » » » ns = ns->next;» » » | 8629 » » » ns = ns->next; |
8295 } | 8630 } |
8296 } | 8631 } |
8297 if (! adoptns) | 8632 if (! adoptns) |
8298 goto ns_end; | 8633 goto ns_end; |
8299 /* No break on purpose. */ | 8634 /* No break on purpose. */ |
8300 case XML_ATTRIBUTE_NODE: | 8635 case XML_ATTRIBUTE_NODE: |
8301 /* No ns, no fun. */ | 8636 /* No ns, no fun. */ |
8302 if (cur->ns == NULL) | 8637 if (cur->ns == NULL) |
8303 goto ns_end; | 8638 goto ns_end; |
8304 » » | 8639 |
8305 if (! parnsdone) { | 8640 if (! parnsdone) { |
8306 if ((elem->parent) && | 8641 if ((elem->parent) && |
8307 ((xmlNodePtr) elem->parent->doc != elem->parent)) { | 8642 ((xmlNodePtr) elem->parent->doc != elem->parent)) { |
8308 if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, | 8643 if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, |
8309 elem->parent) == -1) | 8644 elem->parent) == -1) |
8310 goto internal_error; | 8645 goto internal_error; |
8311 } | 8646 } |
8312 parnsdone = 1; | 8647 parnsdone = 1; |
8313 } | 8648 } |
8314 /* | 8649 /* |
8315 * Adjust the reference if this was a redundant ns-decl. | 8650 * Adjust the reference if this was a redundant ns-decl. |
8316 */ | 8651 */ |
8317 if (listRedund) { | 8652 if (listRedund) { |
8318 for (i = 0, j = 0; i < nbRedund; i++, j += 2) { | 8653 for (i = 0, j = 0; i < nbRedund; i++, j += 2) { |
8319 if (cur->ns == listRedund[j]) { | 8654 if (cur->ns == listRedund[j]) { |
8320 cur->ns = listRedund[++j]; | 8655 cur->ns = listRedund[++j]; |
8321 break; | 8656 break; |
8322 } | 8657 } |
8323 » » } | 8658 » » } |
8324 } | 8659 } |
8325 /* | 8660 /* |
8326 * Adopt ns-references. | 8661 * Adopt ns-references. |
8327 */ | 8662 */ |
8328 if (XML_NSMAP_NOTEMPTY(nsMap)) { | 8663 if (XML_NSMAP_NOTEMPTY(nsMap)) { |
8329 /* | 8664 /* |
8330 * Search for a mapping. | 8665 * Search for a mapping. |
8331 */ | 8666 */ |
8332 XML_NSMAP_FOREACH(nsMap, mi) { | 8667 XML_NSMAP_FOREACH(nsMap, mi) { |
8333 if ((mi->shadowDepth == -1) && | 8668 if ((mi->shadowDepth == -1) && |
(...skipping 17 matching lines...) Expand all Loading... |
8351 | 8686 |
8352 ns_end: | 8687 ns_end: |
8353 if ((cur->type == XML_ELEMENT_NODE) && | 8688 if ((cur->type == XML_ELEMENT_NODE) && |
8354 (cur->properties != NULL)) { | 8689 (cur->properties != NULL)) { |
8355 /* | 8690 /* |
8356 * Process attributes. | 8691 * Process attributes. |
8357 */ | 8692 */ |
8358 cur = (xmlNodePtr) cur->properties; | 8693 cur = (xmlNodePtr) cur->properties; |
8359 continue; | 8694 continue; |
8360 } | 8695 } |
8361 » » break;» » | 8696 » » break; |
8362 default: | 8697 default: |
8363 goto next_sibling; | 8698 goto next_sibling; |
8364 } | 8699 } |
8365 into_content: | 8700 into_content: |
8366 if ((cur->type == XML_ELEMENT_NODE) && | 8701 if ((cur->type == XML_ELEMENT_NODE) && |
8367 (cur->children != NULL)) { | 8702 (cur->children != NULL)) { |
8368 /* | 8703 /* |
8369 * Process content of element-nodes only. | 8704 * Process content of element-nodes only. |
8370 */ | 8705 */ |
8371 cur = cur->children; | 8706 cur = cur->children; |
8372 continue; | 8707 continue; |
8373 } | 8708 } |
8374 next_sibling:» | 8709 next_sibling: |
8375 if (cur == elem) | 8710 if (cur == elem) |
8376 break; | 8711 break; |
8377 if (cur->type == XML_ELEMENT_NODE) { | 8712 if (cur->type == XML_ELEMENT_NODE) { |
8378 » if (XML_NSMAP_NOTEMPTY(nsMap)) {» | 8713 » if (XML_NSMAP_NOTEMPTY(nsMap)) { |
8379 /* | 8714 /* |
8380 * Pop mappings. | 8715 * Pop mappings. |
8381 */ | 8716 */ |
8382 while ((nsMap->last != NULL) && | 8717 while ((nsMap->last != NULL) && |
8383 (nsMap->last->depth >= depth)) | 8718 (nsMap->last->depth >= depth)) |
8384 { | 8719 { |
8385 » » XML_NSMAP_POP(nsMap, mi)» » | 8720 » » XML_NSMAP_POP(nsMap, mi) |
8386 } | 8721 } |
8387 /* | 8722 /* |
8388 * Unshadow. | 8723 * Unshadow. |
8389 */ | 8724 */ |
8390 XML_NSMAP_FOREACH(nsMap, mi) { | 8725 XML_NSMAP_FOREACH(nsMap, mi) { |
8391 if (mi->shadowDepth >= depth) | 8726 if (mi->shadowDepth >= depth) |
8392 mi->shadowDepth = -1; | 8727 mi->shadowDepth = -1; |
8393 } | 8728 } |
8394 » }» | 8729 » } |
8395 depth--; | 8730 depth--; |
8396 } | 8731 } |
8397 if (cur->next != NULL) | 8732 if (cur->next != NULL) |
8398 cur = cur->next; | 8733 cur = cur->next; |
8399 else { | 8734 else { |
8400 if (cur->type == XML_ATTRIBUTE_NODE) { | 8735 if (cur->type == XML_ATTRIBUTE_NODE) { |
8401 cur = cur->parent; | 8736 cur = cur->parent; |
8402 goto into_content; | 8737 goto into_content; |
8403 } | 8738 } |
8404 cur = cur->parent; | 8739 cur = cur->parent; |
8405 goto next_sibling; | 8740 goto next_sibling; |
8406 } | 8741 } |
8407 } while (cur != NULL); | 8742 } while (cur != NULL); |
8408 | 8743 |
8409 ret = 0; | 8744 ret = 0; |
8410 goto exit; | 8745 goto exit; |
8411 internal_error: | 8746 internal_error: |
8412 ret = -1; | 8747 ret = -1; |
8413 exit: | 8748 exit: |
8414 if (listRedund) {» | 8749 if (listRedund) { |
8415 for (i = 0, j = 0; i < nbRedund; i++, j += 2) { | 8750 for (i = 0, j = 0; i < nbRedund; i++, j += 2) { |
8416 xmlFreeNs(listRedund[j]); | 8751 xmlFreeNs(listRedund[j]); |
8417 } | 8752 } |
8418 xmlFree(listRedund); | 8753 xmlFree(listRedund); |
8419 } | 8754 } |
8420 if (nsMap != NULL) | 8755 if (nsMap != NULL) |
8421 xmlDOMWrapNsMapFree(nsMap); | 8756 xmlDOMWrapNsMapFree(nsMap); |
8422 return (ret); | 8757 return (ret); |
8423 } | 8758 } |
8424 | 8759 |
(...skipping 30 matching lines...) Expand all Loading... |
8455 int ret = 0; | 8790 int ret = 0; |
8456 xmlNodePtr cur, curElem = NULL; | 8791 xmlNodePtr cur, curElem = NULL; |
8457 xmlNsMapPtr nsMap = NULL; | 8792 xmlNsMapPtr nsMap = NULL; |
8458 xmlNsMapItemPtr mi; | 8793 xmlNsMapItemPtr mi; |
8459 xmlNsPtr ns = NULL; | 8794 xmlNsPtr ns = NULL; |
8460 int depth = -1, adoptStr = 1; | 8795 int depth = -1, adoptStr = 1; |
8461 /* gather @parent's ns-decls. */ | 8796 /* gather @parent's ns-decls. */ |
8462 int parnsdone; | 8797 int parnsdone; |
8463 /* @ancestorsOnly should be set per option. */ | 8798 /* @ancestorsOnly should be set per option. */ |
8464 int ancestorsOnly = 0; | 8799 int ancestorsOnly = 0; |
8465 | 8800 |
8466 /* | 8801 /* |
8467 * Optimize string adoption for equal or none dicts. | 8802 * Optimize string adoption for equal or none dicts. |
8468 */ | 8803 */ |
8469 if ((sourceDoc != NULL) && | 8804 if ((sourceDoc != NULL) && |
8470 (sourceDoc->dict == destDoc->dict)) | 8805 (sourceDoc->dict == destDoc->dict)) |
8471 adoptStr = 0; | 8806 adoptStr = 0; |
8472 else | 8807 else |
8473 adoptStr = 1; | 8808 adoptStr = 1; |
8474 | 8809 |
8475 /* | 8810 /* |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8509 if ((cur->type == XML_XINCLUDE_END) || | 8844 if ((cur->type == XML_XINCLUDE_END) || |
8510 (cur->doc == node->doc)) | 8845 (cur->doc == node->doc)) |
8511 break; | 8846 break; |
8512 } while (cur->next != NULL); | 8847 } while (cur->next != NULL); |
8513 | 8848 |
8514 if (cur->doc != node->doc) | 8849 if (cur->doc != node->doc) |
8515 goto leave_node; | 8850 goto leave_node; |
8516 } | 8851 } |
8517 cur->doc = destDoc; | 8852 cur->doc = destDoc; |
8518 switch (cur->type) { | 8853 switch (cur->type) { |
8519 » case XML_XINCLUDE_START:» » | 8854 » case XML_XINCLUDE_START: |
8520 case XML_XINCLUDE_END: | 8855 case XML_XINCLUDE_END: |
8521 /* | 8856 /* |
8522 * TODO | 8857 * TODO |
8523 */ | 8858 */ |
8524 return (-1); | 8859 return (-1); |
8525 » case XML_ELEMENT_NODE: » | 8860 » case XML_ELEMENT_NODE: |
8526 curElem = cur; | 8861 curElem = cur; |
8527 depth++; | 8862 depth++; |
8528 /* | 8863 /* |
8529 » » * Namespace declarations.» » | 8864 » » * Namespace declarations. |
8530 * - ns->href and ns->prefix are never in the dict, so | 8865 * - ns->href and ns->prefix are never in the dict, so |
8531 * we need not move the values over to the destination dict. | 8866 * we need not move the values over to the destination dict. |
8532 * - Note that for custom handling of ns-references, | 8867 * - Note that for custom handling of ns-references, |
8533 * the ns-decls need not be stored in the ns-map, | 8868 * the ns-decls need not be stored in the ns-map, |
8534 * since they won't be referenced by node->ns. | 8869 * since they won't be referenced by node->ns. |
8535 */ | 8870 */ |
8536 if ((cur->nsDef) && | 8871 if ((cur->nsDef) && |
8537 ((ctxt == NULL) || (ctxt->getNsForNodeFunc == NULL))) | 8872 ((ctxt == NULL) || (ctxt->getNsForNodeFunc == NULL))) |
8538 { | 8873 { |
8539 if (! parnsdone) { | 8874 if (! parnsdone) { |
8540 /* | 8875 /* |
8541 * Gather @parent's in-scope ns-decls. | 8876 * Gather @parent's in-scope ns-decls. |
8542 */ | 8877 */ |
8543 if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, | 8878 if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, |
8544 destParent) == -1) | 8879 destParent) == -1) |
8545 goto internal_error; | 8880 goto internal_error; |
8546 parnsdone = 1; | 8881 parnsdone = 1; |
8547 } | 8882 } |
8548 for (ns = cur->nsDef; ns != NULL; ns = ns->next) { | 8883 for (ns = cur->nsDef; ns != NULL; ns = ns->next) { |
8549 /* | 8884 /* |
8550 * NOTE: ns->prefix and ns->href are never in the dict. | 8885 * NOTE: ns->prefix and ns->href are never in the dict. |
8551 * XML_TREE_ADOPT_STR(ns->prefix) | 8886 * XML_TREE_ADOPT_STR(ns->prefix) |
8552 * XML_TREE_ADOPT_STR(ns->href) | 8887 * XML_TREE_ADOPT_STR(ns->href) |
8553 » » » */» » » | 8888 » » » */ |
8554 /* | 8889 /* |
8555 * Does it shadow any ns-decl? | 8890 * Does it shadow any ns-decl? |
8556 » » » */» » » | 8891 » » » */ |
8557 if (XML_NSMAP_NOTEMPTY(nsMap)) { | 8892 if (XML_NSMAP_NOTEMPTY(nsMap)) { |
8558 XML_NSMAP_FOREACH(nsMap, mi) { | 8893 XML_NSMAP_FOREACH(nsMap, mi) { |
8559 if ((mi->depth >= XML_TREE_NSMAP_PARENT) && | 8894 if ((mi->depth >= XML_TREE_NSMAP_PARENT) && |
8560 (mi->shadowDepth == -1) && | 8895 (mi->shadowDepth == -1) && |
8561 ((ns->prefix == mi->newNs->prefix) || | 8896 ((ns->prefix == mi->newNs->prefix) || |
8562 xmlStrEqual(ns->prefix, | 8897 xmlStrEqual(ns->prefix, |
8563 mi->newNs->prefix))) { | 8898 mi->newNs->prefix))) { |
8564 » » » » | 8899 |
8565 mi->shadowDepth = depth; | 8900 mi->shadowDepth = depth; |
8566 } | 8901 } |
8567 } | 8902 } |
8568 } | 8903 } |
8569 /* | 8904 /* |
8570 * Push mapping. | 8905 * Push mapping. |
8571 */ | 8906 */ |
8572 if (xmlDOMWrapNsMapAddItem(&nsMap, -1, | 8907 if (xmlDOMWrapNsMapAddItem(&nsMap, -1, |
8573 ns, ns, depth) == NULL) | 8908 ns, ns, depth) == NULL) |
8574 goto internal_error; | 8909 goto internal_error; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8617 */ | 8952 */ |
8618 if (xmlDOMWrapNsMapAddItem(&nsMap, -1, | 8953 if (xmlDOMWrapNsMapAddItem(&nsMap, -1, |
8619 cur->ns, ns, XML_TREE_NSMAP_CUSTOM) == NULL) | 8954 cur->ns, ns, XML_TREE_NSMAP_CUSTOM) == NULL) |
8620 goto internal_error; | 8955 goto internal_error; |
8621 cur->ns = ns; | 8956 cur->ns = ns; |
8622 } else { | 8957 } else { |
8623 /* | 8958 /* |
8624 * Aquire a normalized ns-decl and add it to the map. | 8959 * Aquire a normalized ns-decl and add it to the map. |
8625 */ | 8960 */ |
8626 if (xmlDOMWrapNSNormAquireNormalizedNs(destDoc, | 8961 if (xmlDOMWrapNSNormAquireNormalizedNs(destDoc, |
8627 » » » /* ns-decls on curElem or on destDoc->oldNs */» »
» | 8962 » » » /* ns-decls on curElem or on destDoc->oldNs */ |
8628 destParent ? curElem : NULL, | 8963 destParent ? curElem : NULL, |
8629 cur->ns, &ns, | 8964 cur->ns, &ns, |
8630 &nsMap, depth, | 8965 &nsMap, depth, |
8631 ancestorsOnly, | 8966 ancestorsOnly, |
8632 /* ns-decls must be prefixed for attributes. */ | 8967 /* ns-decls must be prefixed for attributes. */ |
8633 (cur->type == XML_ATTRIBUTE_NODE) ? 1 : 0) == -1) | 8968 (cur->type == XML_ATTRIBUTE_NODE) ? 1 : 0) == -1) |
8634 goto internal_error; | 8969 goto internal_error; |
8635 cur->ns = ns; | 8970 cur->ns = ns; |
8636 } | 8971 } |
8637 ns_end: | 8972 ns_end: |
(...skipping 15 matching lines...) Expand all Loading... |
8653 */ | 8988 */ |
8654 cur = (xmlNodePtr) cur->properties; | 8989 cur = (xmlNodePtr) cur->properties; |
8655 continue; | 8990 continue; |
8656 } | 8991 } |
8657 } else { | 8992 } else { |
8658 /* | 8993 /* |
8659 * Attributes. | 8994 * Attributes. |
8660 */ | 8995 */ |
8661 if ((sourceDoc != NULL) && | 8996 if ((sourceDoc != NULL) && |
8662 (((xmlAttrPtr) cur)->atype == XML_ATTRIBUTE_ID)) | 8997 (((xmlAttrPtr) cur)->atype == XML_ATTRIBUTE_ID)) |
8663 » » {» » » | 8998 » » { |
8664 xmlRemoveID(sourceDoc, (xmlAttrPtr) cur); | 8999 xmlRemoveID(sourceDoc, (xmlAttrPtr) cur); |
8665 } | 9000 } |
8666 ((xmlAttrPtr) cur)->atype = 0; | 9001 ((xmlAttrPtr) cur)->atype = 0; |
8667 ((xmlAttrPtr) cur)->psvi = NULL; | 9002 ((xmlAttrPtr) cur)->psvi = NULL; |
8668 } | 9003 } |
8669 break; | 9004 break; |
8670 case XML_TEXT_NODE: | 9005 case XML_TEXT_NODE: |
8671 » case XML_CDATA_SECTION_NODE:» » | 9006 » case XML_CDATA_SECTION_NODE: |
8672 /* | 9007 /* |
8673 * This puts the content in the dest dict, only if | 9008 * This puts the content in the dest dict, only if |
8674 * it was previously in the source dict. | 9009 * it was previously in the source dict. |
8675 */ | 9010 */ |
8676 » » XML_TREE_ADOPT_STR_2(cur->content)» » | 9011 » » XML_TREE_ADOPT_STR_2(cur->content) |
8677 » » goto leave_node;» | 9012 » » goto leave_node; |
8678 case XML_ENTITY_REF_NODE: | 9013 case XML_ENTITY_REF_NODE: |
8679 /* | 9014 /* |
8680 * Remove reference to the entitity-node. | 9015 * Remove reference to the entitity-node. |
8681 */ | 9016 */ |
8682 cur->content = NULL; | 9017 cur->content = NULL; |
8683 cur->children = NULL; | 9018 cur->children = NULL; |
8684 cur->last = NULL; | 9019 cur->last = NULL; |
8685 if ((destDoc->intSubset) || (destDoc->extSubset)) { | 9020 if ((destDoc->intSubset) || (destDoc->extSubset)) { |
8686 xmlEntityPtr ent; | 9021 xmlEntityPtr ent; |
8687 /* | 9022 /* |
8688 * Assign new entity-node if available. | 9023 * Assign new entity-node if available. |
8689 */ | 9024 */ |
8690 ent = xmlGetDocEntity(destDoc, cur->name); | 9025 ent = xmlGetDocEntity(destDoc, cur->name); |
8691 if (ent != NULL) { | 9026 if (ent != NULL) { |
8692 cur->content = ent->content; | 9027 cur->content = ent->content; |
8693 cur->children = (xmlNodePtr) ent; | 9028 cur->children = (xmlNodePtr) ent; |
8694 cur->last = (xmlNodePtr) ent; | 9029 cur->last = (xmlNodePtr) ent; |
8695 } | 9030 } |
8696 } | 9031 } |
8697 goto leave_node; | 9032 goto leave_node; |
8698 case XML_PI_NODE: | 9033 case XML_PI_NODE: |
8699 XML_TREE_ADOPT_STR(cur->name) | 9034 XML_TREE_ADOPT_STR(cur->name) |
8700 XML_TREE_ADOPT_STR_2(cur->content) | 9035 XML_TREE_ADOPT_STR_2(cur->content) |
8701 break; | 9036 break; |
8702 » case XML_COMMENT_NODE:» | 9037 » case XML_COMMENT_NODE: |
8703 break; | 9038 break; |
8704 default: | 9039 default: |
8705 goto internal_error; | 9040 goto internal_error; |
8706 } | 9041 } |
8707 /* | 9042 /* |
8708 * Walk the tree. | 9043 * Walk the tree. |
8709 */ | 9044 */ |
8710 if (cur->children != NULL) { | 9045 if (cur->children != NULL) { |
8711 cur = cur->children; | 9046 cur = cur->children; |
8712 continue; | 9047 continue; |
8713 } | 9048 } |
8714 | 9049 |
8715 leave_node: | 9050 leave_node: |
8716 if (cur == node) | 9051 if (cur == node) |
8717 break; | 9052 break; |
8718 if ((cur->type == XML_ELEMENT_NODE) || | 9053 if ((cur->type == XML_ELEMENT_NODE) || |
8719 (cur->type == XML_XINCLUDE_START) || | 9054 (cur->type == XML_XINCLUDE_START) || |
8720 (cur->type == XML_XINCLUDE_END)) | 9055 (cur->type == XML_XINCLUDE_END)) |
8721 { | 9056 { |
8722 /* | 9057 /* |
8723 * TODO: Do we expect nsDefs on XML_XINCLUDE_START? | 9058 * TODO: Do we expect nsDefs on XML_XINCLUDE_START? |
8724 */ | 9059 */ |
8725 » if (XML_NSMAP_NOTEMPTY(nsMap)) {» | 9060 » if (XML_NSMAP_NOTEMPTY(nsMap)) { |
8726 /* | 9061 /* |
8727 * Pop mappings. | 9062 * Pop mappings. |
8728 */ | 9063 */ |
8729 while ((nsMap->last != NULL) && | 9064 while ((nsMap->last != NULL) && |
8730 (nsMap->last->depth >= depth)) | 9065 (nsMap->last->depth >= depth)) |
8731 { | 9066 { |
8732 » » XML_NSMAP_POP(nsMap, mi)» » | 9067 » » XML_NSMAP_POP(nsMap, mi) |
8733 » » }» » | 9068 » » } |
8734 /* | 9069 /* |
8735 * Unshadow. | 9070 * Unshadow. |
8736 */ | 9071 */ |
8737 XML_NSMAP_FOREACH(nsMap, mi) { | 9072 XML_NSMAP_FOREACH(nsMap, mi) { |
8738 if (mi->shadowDepth >= depth) | 9073 if (mi->shadowDepth >= depth) |
8739 mi->shadowDepth = -1; | 9074 mi->shadowDepth = -1; |
8740 } | 9075 } |
8741 } | 9076 } |
8742 depth--; | 9077 depth--; |
8743 } | 9078 } |
8744 if (cur->next != NULL) | 9079 if (cur->next != NULL) |
8745 cur = cur->next; | 9080 cur = cur->next; |
8746 else if ((cur->type == XML_ATTRIBUTE_NODE) && | 9081 else if ((cur->type == XML_ATTRIBUTE_NODE) && |
8747 (cur->parent->children != NULL)) | 9082 (cur->parent->children != NULL)) |
8748 { | 9083 { |
8749 cur = cur->parent->children; | 9084 cur = cur->parent->children; |
8750 } else { | 9085 } else { |
8751 cur = cur->parent; | 9086 cur = cur->parent; |
8752 goto leave_node; | 9087 goto leave_node; |
8753 } | 9088 } |
8754 } | 9089 } |
8755 | 9090 |
8756 goto exit; | 9091 goto exit; |
8757 | 9092 |
8758 internal_error: | 9093 internal_error: |
8759 ret = -1; | 9094 ret = -1; |
8760 | 9095 |
8761 exit: | 9096 exit: |
8762 /* | 9097 /* |
8763 * Cleanup. | 9098 * Cleanup. |
8764 */ | 9099 */ |
8765 if (nsMap != NULL) { | 9100 if (nsMap != NULL) { |
8766 if ((ctxt) && (ctxt->namespaceMap == nsMap)) { | 9101 if ((ctxt) && (ctxt->namespaceMap == nsMap)) { |
8767 /* | 9102 /* |
8768 * Just cleanup the map but don't free. | 9103 * Just cleanup the map but don't free. |
8769 */ | 9104 */ |
8770 if (nsMap->first) { | 9105 if (nsMap->first) { |
8771 if (nsMap->pool) | 9106 if (nsMap->pool) |
8772 nsMap->last->next = nsMap->pool; | 9107 nsMap->last->next = nsMap->pool; |
8773 nsMap->pool = nsMap->first; | 9108 nsMap->pool = nsMap->first; |
8774 nsMap->first = NULL; | 9109 nsMap->first = NULL; |
8775 } | 9110 } |
8776 » } else | 9111 » } else |
8777 xmlDOMWrapNsMapFree(nsMap); | 9112 xmlDOMWrapNsMapFree(nsMap); |
8778 } | 9113 } |
8779 return(ret); | 9114 return(ret); |
8780 } | 9115 } |
8781 | 9116 |
8782 /* | 9117 /* |
8783 * xmlDOMWrapCloneNode: | 9118 * xmlDOMWrapCloneNode: |
8784 * @ctxt: the optional context for custom processing | 9119 * @ctxt: the optional context for custom processing |
8785 * @sourceDoc: the optional sourceDoc | 9120 * @sourceDoc: the optional sourceDoc |
8786 * @node: the node to start with | 9121 * @node: the node to start with |
8787 * @resNode: the clone of the given @node | 9122 * @resNode: the clone of the given @node |
8788 * @destDoc: the destination doc | 9123 * @destDoc: the destination doc |
8789 * @destParent: the optional new parent of @node in @destDoc | 9124 * @destParent: the optional new parent of @node in @destDoc |
8790 * @deep: descend into child if set | 9125 * @deep: descend into child if set |
8791 * @options: option flags | 9126 * @options: option flags |
8792 * | 9127 * |
8793 * References of out-of scope ns-decls are remapped to point to @destDoc: | 9128 * References of out-of scope ns-decls are remapped to point to @destDoc: |
8794 * 1) If @destParent is given, then nsDef entries on element-nodes are used | 9129 * 1) If @destParent is given, then nsDef entries on element-nodes are used |
8795 * 2) If *no* @destParent is given, then @destDoc->oldNs entries are used. | 9130 * 2) If *no* @destParent is given, then @destDoc->oldNs entries are used. |
8796 * This is the case when you don't know already where the cloned branch | 9131 * This is the case when you don't know already where the cloned branch |
8797 * will be added to. | 9132 * will be added to. |
8798 * | 9133 * |
8799 * If @destParent is given, it ensures that the tree is namespace | 9134 * If @destParent is given, it ensures that the tree is namespace |
8800 * wellformed by creating additional ns-decls where needed. | 9135 * wellformed by creating additional ns-decls where needed. |
8801 * Note that, since prefixes of already existent ns-decls can be | 9136 * Note that, since prefixes of already existent ns-decls can be |
8802 * shadowed by this process, it could break QNames in attribute | 9137 * shadowed by this process, it could break QNames in attribute |
8803 * values or element content. | 9138 * values or element content. |
8804 * TODO: | 9139 * TODO: |
8805 * 1) What to do with XInclude? Currently this returns an error for XInclude. | 9140 * 1) What to do with XInclude? Currently this returns an error for XInclude. |
8806 * | 9141 * |
8807 * Returns 0 if the operation succeeded, | 9142 * Returns 0 if the operation succeeded, |
8808 * 1 if a node of unsupported (or not yet supported) type was given, | 9143 * 1 if a node of unsupported (or not yet supported) type was given, |
(...skipping 13 matching lines...) Expand all Loading... |
8822 int ret = 0; | 9157 int ret = 0; |
8823 xmlNodePtr cur, curElem = NULL; | 9158 xmlNodePtr cur, curElem = NULL; |
8824 xmlNsMapPtr nsMap = NULL; | 9159 xmlNsMapPtr nsMap = NULL; |
8825 xmlNsMapItemPtr mi; | 9160 xmlNsMapItemPtr mi; |
8826 xmlNsPtr ns; | 9161 xmlNsPtr ns; |
8827 int depth = -1; | 9162 int depth = -1; |
8828 /* int adoptStr = 1; */ | 9163 /* int adoptStr = 1; */ |
8829 /* gather @parent's ns-decls. */ | 9164 /* gather @parent's ns-decls. */ |
8830 int parnsdone = 0; | 9165 int parnsdone = 0; |
8831 /* | 9166 /* |
8832 * @ancestorsOnly: | 9167 * @ancestorsOnly: |
8833 * TODO: @ancestorsOnly should be set per option. | 9168 * TODO: @ancestorsOnly should be set per option. |
8834 * | 9169 * |
8835 */ | 9170 */ |
8836 int ancestorsOnly = 0; | 9171 int ancestorsOnly = 0; |
8837 xmlNodePtr resultClone = NULL, clone = NULL, parentClone = NULL, prevClone =
NULL; | 9172 xmlNodePtr resultClone = NULL, clone = NULL, parentClone = NULL, prevClone =
NULL; |
8838 xmlNsPtr cloneNs = NULL, *cloneNsDefSlot = NULL; | 9173 xmlNsPtr cloneNs = NULL, *cloneNsDefSlot = NULL; |
8839 xmlDictPtr dict; /* The destination dict */ | 9174 xmlDictPtr dict; /* The destination dict */ |
8840 | 9175 |
8841 if ((node == NULL) || (resNode == NULL) || (destDoc == NULL)) | 9176 if ((node == NULL) || (resNode == NULL) || (destDoc == NULL)) |
8842 return(-1); | 9177 return(-1); |
8843 /* | 9178 /* |
8844 * TODO: Initially we support only element-nodes. | 9179 * TODO: Initially we support only element-nodes. |
8845 */ | 9180 */ |
8846 if (node->type != XML_ELEMENT_NODE) | 9181 if (node->type != XML_ELEMENT_NODE) |
8847 return(1); | 9182 return(1); |
8848 /* | 9183 /* |
8849 * Check node->doc sanity. | 9184 * Check node->doc sanity. |
8850 */ | 9185 */ |
8851 if ((node->doc != NULL) && (sourceDoc != NULL) && | 9186 if ((node->doc != NULL) && (sourceDoc != NULL) && |
8852 (node->doc != sourceDoc)) { | 9187 (node->doc != sourceDoc)) { |
8853 /* | 9188 /* |
8854 * Might be an XIncluded node. | 9189 * Might be an XIncluded node. |
8855 */ | 9190 */ |
8856 return (-1); | 9191 return (-1); |
8857 } | 9192 } |
8858 if (sourceDoc == NULL) | 9193 if (sourceDoc == NULL) |
8859 » sourceDoc = node->doc; | 9194 » sourceDoc = node->doc; |
8860 if (sourceDoc == NULL) | 9195 if (sourceDoc == NULL) |
8861 return (-1); | 9196 return (-1); |
8862 | 9197 |
8863 dict = destDoc->dict; | 9198 dict = destDoc->dict; |
8864 /* | 9199 /* |
8865 * Reuse the namespace map of the context. | 9200 * Reuse the namespace map of the context. |
8866 */ | 9201 */ |
8867 if (ctxt) | 9202 if (ctxt) |
8868 nsMap = (xmlNsMapPtr) ctxt->namespaceMap; | 9203 nsMap = (xmlNsMapPtr) ctxt->namespaceMap; |
8869 | 9204 |
8870 *resNode = NULL; | 9205 *resNode = NULL; |
8871 | 9206 |
8872 cur = node; | 9207 cur = node; |
8873 while (cur != NULL) { | 9208 while (cur != NULL) { |
8874 if (cur->doc != sourceDoc) { | 9209 if (cur->doc != sourceDoc) { |
8875 /* | 9210 /* |
8876 * We'll assume XIncluded nodes if the doc differs. | 9211 * We'll assume XIncluded nodes if the doc differs. |
8877 * TODO: Do we need to reconciliate XIncluded nodes? | 9212 * TODO: Do we need to reconciliate XIncluded nodes? |
8878 * TODO: This here returns -1 in this case. | 9213 * TODO: This here returns -1 in this case. |
8879 */ | 9214 */ |
8880 » goto internal_error;» | 9215 » goto internal_error; |
8881 } | 9216 } |
8882 /* | 9217 /* |
8883 * Create a new node. | 9218 * Create a new node. |
8884 */ | 9219 */ |
8885 switch (cur->type) { | 9220 switch (cur->type) { |
8886 case XML_XINCLUDE_START: | 9221 case XML_XINCLUDE_START: |
8887 case XML_XINCLUDE_END: | 9222 case XML_XINCLUDE_END: |
8888 /* | 9223 /* |
8889 * TODO: What to do with XInclude? | 9224 * TODO: What to do with XInclude? |
8890 */ | 9225 */ |
8891 goto internal_error; | 9226 goto internal_error; |
8892 break; | 9227 break; |
8893 case XML_ELEMENT_NODE: | 9228 case XML_ELEMENT_NODE: |
8894 case XML_TEXT_NODE: | 9229 case XML_TEXT_NODE: |
8895 » case XML_CDATA_SECTION_NODE:» | 9230 » case XML_CDATA_SECTION_NODE: |
8896 case XML_COMMENT_NODE: | 9231 case XML_COMMENT_NODE: |
8897 » case XML_PI_NODE:» | 9232 » case XML_PI_NODE: |
8898 case XML_DOCUMENT_FRAG_NODE: | 9233 case XML_DOCUMENT_FRAG_NODE: |
8899 case XML_ENTITY_REF_NODE: | 9234 case XML_ENTITY_REF_NODE: |
8900 case XML_ENTITY_NODE: | 9235 case XML_ENTITY_NODE: |
8901 /* | 9236 /* |
8902 * Nodes of xmlNode structure. | 9237 * Nodes of xmlNode structure. |
8903 */ | 9238 */ |
8904 clone = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); | 9239 clone = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
8905 if (clone == NULL) { | 9240 if (clone == NULL) { |
8906 xmlTreeErrMemory("xmlDOMWrapCloneNode(): allocating a node")
; | 9241 xmlTreeErrMemory("xmlDOMWrapCloneNode(): allocating a node")
; |
8907 goto internal_error; | 9242 goto internal_error; |
8908 } | 9243 } |
8909 » » memset(clone, 0, sizeof(xmlNode));» » | 9244 » » memset(clone, 0, sizeof(xmlNode)); |
8910 /* | 9245 /* |
8911 * Set hierachical links. | 9246 * Set hierachical links. |
8912 */ | 9247 */ |
8913 » » if (resultClone != NULL) {» | 9248 » » if (resultClone != NULL) { |
8914 clone->parent = parentClone; | 9249 clone->parent = parentClone; |
8915 if (prevClone) { | 9250 if (prevClone) { |
8916 prevClone->next = clone; | 9251 prevClone->next = clone; |
8917 clone->prev = prevClone; | 9252 clone->prev = prevClone; |
8918 » » } else | 9253 » » } else |
8919 parentClone->children = clone; | 9254 parentClone->children = clone; |
8920 } else | 9255 } else |
8921 resultClone = clone; | 9256 resultClone = clone; |
8922 » » | 9257 |
8923 break; | 9258 break; |
8924 case XML_ATTRIBUTE_NODE: | 9259 case XML_ATTRIBUTE_NODE: |
8925 /* | 9260 /* |
8926 * Attributes (xmlAttr). | 9261 * Attributes (xmlAttr). |
8927 */ | 9262 */ |
8928 clone = (xmlNodePtr) xmlMalloc(sizeof(xmlAttr)); | 9263 clone = (xmlNodePtr) xmlMalloc(sizeof(xmlAttr)); |
8929 if (clone == NULL) { | 9264 if (clone == NULL) { |
8930 xmlTreeErrMemory("xmlDOMWrapCloneNode(): allocating an attr-
node"); | 9265 xmlTreeErrMemory("xmlDOMWrapCloneNode(): allocating an attr-
node"); |
8931 goto internal_error; | 9266 goto internal_error; |
8932 } | 9267 } |
8933 » » memset(clone, 0, sizeof(xmlAttr));» » | 9268 » » memset(clone, 0, sizeof(xmlAttr)); |
8934 /* | 9269 /* |
8935 * Set hierachical links. | 9270 * Set hierachical links. |
8936 * TODO: Change this to add to the end of attributes. | 9271 * TODO: Change this to add to the end of attributes. |
8937 */ | 9272 */ |
8938 if (resultClone != NULL) { | 9273 if (resultClone != NULL) { |
8939 clone->parent = parentClone; | 9274 clone->parent = parentClone; |
8940 if (prevClone) { | 9275 if (prevClone) { |
8941 prevClone->next = clone; | 9276 prevClone->next = clone; |
8942 clone->prev = prevClone; | 9277 clone->prev = prevClone; |
8943 » » } else | 9278 » » } else |
8944 parentClone->properties = (xmlAttrPtr) clone; | 9279 parentClone->properties = (xmlAttrPtr) clone; |
8945 } else | 9280 } else |
8946 resultClone = clone; | 9281 resultClone = clone; |
8947 break; | 9282 break; |
8948 default: | 9283 default: |
8949 /* | 9284 /* |
8950 * TODO QUESTION: Any other nodes expected? | 9285 * TODO QUESTION: Any other nodes expected? |
8951 */ | 9286 */ |
8952 goto internal_error; | 9287 goto internal_error; |
8953 } | 9288 } |
8954 | 9289 |
8955 clone->type = cur->type; | 9290 clone->type = cur->type; |
8956 » clone->doc = destDoc;» | 9291 » clone->doc = destDoc; |
8957 » » | 9292 |
8958 /* | 9293 /* |
8959 * Clone the name of the node if any. | 9294 * Clone the name of the node if any. |
8960 */ | 9295 */ |
8961 if (cur->name == xmlStringText) | 9296 if (cur->name == xmlStringText) |
8962 clone->name = xmlStringText; | 9297 clone->name = xmlStringText; |
8963 else if (cur->name == xmlStringTextNoenc) | 9298 else if (cur->name == xmlStringTextNoenc) |
8964 /* | 9299 /* |
8965 * NOTE: Although xmlStringTextNoenc is never assigned to a node | 9300 * NOTE: Although xmlStringTextNoenc is never assigned to a node |
8966 * in tree.c, it might be set in Libxslt via | 9301 * in tree.c, it might be set in Libxslt via |
8967 » * "xsl:disable-output-escaping".» | 9302 » * "xsl:disable-output-escaping". |
8968 */ | 9303 */ |
8969 clone->name = xmlStringTextNoenc; | 9304 clone->name = xmlStringTextNoenc; |
8970 else if (cur->name == xmlStringComment) | 9305 else if (cur->name == xmlStringComment) |
8971 clone->name = xmlStringComment; | 9306 clone->name = xmlStringComment; |
8972 else if (cur->name != NULL) { | 9307 else if (cur->name != NULL) { |
8973 DICT_CONST_COPY(cur->name, clone->name); | 9308 DICT_CONST_COPY(cur->name, clone->name); |
8974 » }» » » » | 9309 » } |
8975 | 9310 |
8976 switch (cur->type) { | 9311 switch (cur->type) { |
8977 case XML_XINCLUDE_START: | 9312 case XML_XINCLUDE_START: |
8978 case XML_XINCLUDE_END: | 9313 case XML_XINCLUDE_END: |
8979 /* | 9314 /* |
8980 * TODO | 9315 * TODO |
8981 */ | 9316 */ |
8982 return (-1); | 9317 return (-1); |
8983 case XML_ELEMENT_NODE: | 9318 case XML_ELEMENT_NODE: |
8984 curElem = cur; | 9319 curElem = cur; |
8985 depth++; | 9320 depth++; |
8986 /* | 9321 /* |
8987 * Namespace declarations. | 9322 * Namespace declarations. |
8988 */ | 9323 */ |
8989 if (cur->nsDef != NULL) { | 9324 if (cur->nsDef != NULL) { |
8990 if (! parnsdone) { | 9325 if (! parnsdone) { |
8991 if (destParent && (ctxt == NULL)) { | 9326 if (destParent && (ctxt == NULL)) { |
8992 /* | 9327 /* |
8993 * Gather @parent's in-scope ns-decls. | 9328 * Gather @parent's in-scope ns-decls. |
8994 */ | 9329 */ |
8995 if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, | 9330 if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, |
8996 destParent) == -1) | 9331 destParent) == -1) |
8997 » » » » goto internal_error;» » » | 9332 » » » » goto internal_error; |
8998 } | 9333 } |
8999 parnsdone = 1; | 9334 parnsdone = 1; |
9000 } | 9335 } |
9001 /* | 9336 /* |
9002 * Clone namespace declarations. | 9337 * Clone namespace declarations. |
9003 */ | 9338 */ |
9004 cloneNsDefSlot = &(clone->nsDef); | 9339 cloneNsDefSlot = &(clone->nsDef); |
9005 for (ns = cur->nsDef; ns != NULL; ns = ns->next) { | 9340 for (ns = cur->nsDef; ns != NULL; ns = ns->next) { |
9006 /* | 9341 /* |
9007 * Create a new xmlNs. | 9342 * Create a new xmlNs. |
9008 */ | 9343 */ |
9009 cloneNs = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); | 9344 cloneNs = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); |
9010 if (cloneNs == NULL) { | 9345 if (cloneNs == NULL) { |
9011 xmlTreeErrMemory("xmlDOMWrapCloneNode(): " | 9346 xmlTreeErrMemory("xmlDOMWrapCloneNode(): " |
9012 "allocating namespace"); | 9347 "allocating namespace"); |
9013 return(-1); | 9348 return(-1); |
9014 } | 9349 } |
9015 memset(cloneNs, 0, sizeof(xmlNs)); | 9350 memset(cloneNs, 0, sizeof(xmlNs)); |
9016 cloneNs->type = XML_LOCAL_NAMESPACE; | 9351 cloneNs->type = XML_LOCAL_NAMESPACE; |
9017 » » » | 9352 |
9018 if (ns->href != NULL) | 9353 if (ns->href != NULL) |
9019 cloneNs->href = xmlStrdup(ns->href); | 9354 cloneNs->href = xmlStrdup(ns->href); |
9020 if (ns->prefix != NULL) | 9355 if (ns->prefix != NULL) |
9021 cloneNs->prefix = xmlStrdup(ns->prefix); | 9356 cloneNs->prefix = xmlStrdup(ns->prefix); |
9022 | 9357 |
9023 *cloneNsDefSlot = cloneNs; | 9358 *cloneNsDefSlot = cloneNs; |
9024 cloneNsDefSlot = &(cloneNs->next); | 9359 cloneNsDefSlot = &(cloneNs->next); |
9025 | 9360 |
9026 /* | 9361 /* |
9027 * Note that for custom handling of ns-references, | 9362 * Note that for custom handling of ns-references, |
9028 * the ns-decls need not be stored in the ns-map, | 9363 * the ns-decls need not be stored in the ns-map, |
9029 * since they won't be referenced by node->ns. | 9364 * since they won't be referenced by node->ns. |
9030 */ | 9365 */ |
9031 if ((ctxt == NULL) || | 9366 if ((ctxt == NULL) || |
9032 (ctxt->getNsForNodeFunc == NULL)) | 9367 (ctxt->getNsForNodeFunc == NULL)) |
9033 { | 9368 { |
9034 /* | 9369 /* |
9035 * Does it shadow any ns-decl? | 9370 * Does it shadow any ns-decl? |
9036 */ | 9371 */ |
9037 if (XML_NSMAP_NOTEMPTY(nsMap)) { | 9372 if (XML_NSMAP_NOTEMPTY(nsMap)) { |
9038 » » » » XML_NSMAP_FOREACH(nsMap, mi) {» » »
» | 9373 » » » » XML_NSMAP_FOREACH(nsMap, mi) { |
9039 if ((mi->depth >= XML_TREE_NSMAP_PARENT) && | 9374 if ((mi->depth >= XML_TREE_NSMAP_PARENT) && |
9040 (mi->shadowDepth == -1) && | 9375 (mi->shadowDepth == -1) && |
9041 ((ns->prefix == mi->newNs->prefix) || | 9376 ((ns->prefix == mi->newNs->prefix) || |
9042 xmlStrEqual(ns->prefix, | 9377 xmlStrEqual(ns->prefix, |
9043 mi->newNs->prefix))) { | 9378 mi->newNs->prefix))) { |
9044 /* | 9379 /* |
9045 * Mark as shadowed at the current | 9380 * Mark as shadowed at the current |
9046 * depth. | 9381 * depth. |
9047 */ | 9382 */ |
9048 mi->shadowDepth = depth; | 9383 mi->shadowDepth = depth; |
9049 } | 9384 } |
9050 } | 9385 } |
9051 } | 9386 } |
9052 /* | 9387 /* |
9053 * Push mapping. | 9388 * Push mapping. |
9054 */ | 9389 */ |
9055 if (xmlDOMWrapNsMapAddItem(&nsMap, -1, | 9390 if (xmlDOMWrapNsMapAddItem(&nsMap, -1, |
9056 ns, cloneNs, depth) == NULL) | 9391 ns, cloneNs, depth) == NULL) |
9057 goto internal_error; | 9392 goto internal_error; |
9058 } | 9393 } |
9059 } | 9394 } |
9060 } | 9395 } |
9061 /* cur->ns will be processed further down. */ | 9396 /* cur->ns will be processed further down. */ |
9062 break; | 9397 break; |
9063 » case XML_ATTRIBUTE_NODE:» » » » | 9398 » case XML_ATTRIBUTE_NODE: |
9064 /* IDs will be processed further down. */ | 9399 /* IDs will be processed further down. */ |
9065 /* cur->ns will be processed further down. */ | 9400 /* cur->ns will be processed further down. */ |
9066 break; | 9401 break; |
9067 case XML_TEXT_NODE: | 9402 case XML_TEXT_NODE: |
9068 case XML_CDATA_SECTION_NODE: | 9403 case XML_CDATA_SECTION_NODE: |
9069 /* | 9404 /* |
9070 * Note that this will also cover the values of attributes. | 9405 * Note that this will also cover the values of attributes. |
9071 */ | 9406 */ |
9072 » » DICT_COPY(cur->content, clone->content);» » | 9407 » » DICT_COPY(cur->content, clone->content); |
9073 goto leave_node; | 9408 goto leave_node; |
9074 case XML_ENTITY_NODE: | 9409 case XML_ENTITY_NODE: |
9075 /* TODO: What to do here? */ | 9410 /* TODO: What to do here? */ |
9076 goto leave_node; | 9411 goto leave_node; |
9077 » case XML_ENTITY_REF_NODE:» » | 9412 » case XML_ENTITY_REF_NODE: |
9078 if (sourceDoc != destDoc) { | 9413 if (sourceDoc != destDoc) { |
9079 if ((destDoc->intSubset) || (destDoc->extSubset)) { | 9414 if ((destDoc->intSubset) || (destDoc->extSubset)) { |
9080 xmlEntityPtr ent; | 9415 xmlEntityPtr ent; |
9081 /* | 9416 /* |
9082 * Different doc: Assign new entity-node if available. | 9417 * Different doc: Assign new entity-node if available. |
9083 */ | 9418 */ |
9084 ent = xmlGetDocEntity(destDoc, cur->name); | 9419 ent = xmlGetDocEntity(destDoc, cur->name); |
9085 if (ent != NULL) { | 9420 if (ent != NULL) { |
9086 clone->content = ent->content; | 9421 clone->content = ent->content; |
9087 clone->children = (xmlNodePtr) ent; | 9422 clone->children = (xmlNodePtr) ent; |
(...skipping 19 matching lines...) Expand all Loading... |
9107 default: | 9442 default: |
9108 goto internal_error; | 9443 goto internal_error; |
9109 } | 9444 } |
9110 | 9445 |
9111 if (cur->ns == NULL) | 9446 if (cur->ns == NULL) |
9112 goto end_ns_reference; | 9447 goto end_ns_reference; |
9113 | 9448 |
9114 /* handle_ns_reference: */ | 9449 /* handle_ns_reference: */ |
9115 /* | 9450 /* |
9116 ** The following will take care of references to ns-decls ******** | 9451 ** The following will take care of references to ns-decls ******** |
9117 » ** and is intended only for element- and attribute-nodes.» | 9452 » ** and is intended only for element- and attribute-nodes. |
9118 ** | 9453 ** |
9119 */ | 9454 */ |
9120 if (! parnsdone) { | 9455 if (! parnsdone) { |
9121 if (destParent && (ctxt == NULL)) { | 9456 if (destParent && (ctxt == NULL)) { |
9122 if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, destParent) == -1) | 9457 if (xmlDOMWrapNSNormGatherInScopeNs(&nsMap, destParent) == -1) |
9123 » » goto internal_error;» » | 9458 » » goto internal_error; |
9124 } | 9459 } |
9125 parnsdone = 1; | 9460 parnsdone = 1; |
9126 } | 9461 } |
9127 /* | 9462 /* |
9128 * Adopt ns-references. | 9463 * Adopt ns-references. |
9129 */ | 9464 */ |
9130 if (XML_NSMAP_NOTEMPTY(nsMap)) { | 9465 if (XML_NSMAP_NOTEMPTY(nsMap)) { |
9131 /* | 9466 /* |
9132 * Search for a mapping. | 9467 * Search for a mapping. |
9133 */ | 9468 */ |
9134 » XML_NSMAP_FOREACH(nsMap, mi) {» | 9469 » XML_NSMAP_FOREACH(nsMap, mi) { |
9135 if ((mi->shadowDepth == -1) && | 9470 if ((mi->shadowDepth == -1) && |
9136 (cur->ns == mi->oldNs)) { | 9471 (cur->ns == mi->oldNs)) { |
9137 /* | 9472 /* |
9138 * This is the nice case: a mapping was found. | 9473 * This is the nice case: a mapping was found. |
9139 */ | 9474 */ |
9140 clone->ns = mi->newNs; | 9475 clone->ns = mi->newNs; |
9141 goto end_ns_reference; | 9476 goto end_ns_reference; |
9142 } | 9477 } |
9143 } | 9478 } |
9144 } | 9479 } |
(...skipping 11 matching lines...) Expand all Loading... |
9156 */ | 9491 */ |
9157 if (xmlDOMWrapNsMapAddItem(&nsMap, -1, | 9492 if (xmlDOMWrapNsMapAddItem(&nsMap, -1, |
9158 cur->ns, ns, XML_TREE_NSMAP_CUSTOM) == NULL) | 9493 cur->ns, ns, XML_TREE_NSMAP_CUSTOM) == NULL) |
9159 goto internal_error; | 9494 goto internal_error; |
9160 clone->ns = ns; | 9495 clone->ns = ns; |
9161 } else { | 9496 } else { |
9162 /* | 9497 /* |
9163 * Aquire a normalized ns-decl and add it to the map. | 9498 * Aquire a normalized ns-decl and add it to the map. |
9164 */ | 9499 */ |
9165 if (xmlDOMWrapNSNormAquireNormalizedNs(destDoc, | 9500 if (xmlDOMWrapNSNormAquireNormalizedNs(destDoc, |
9166 » » /* ns-decls on curElem or on destDoc->oldNs */» » » | 9501 » » /* ns-decls on curElem or on destDoc->oldNs */ |
9167 destParent ? curElem : NULL, | 9502 destParent ? curElem : NULL, |
9168 cur->ns, &ns, | 9503 cur->ns, &ns, |
9169 &nsMap, depth, | 9504 &nsMap, depth, |
9170 /* if we need to search only in the ancestor-axis */ | 9505 /* if we need to search only in the ancestor-axis */ |
9171 ancestorsOnly, | 9506 ancestorsOnly, |
9172 /* ns-decls must be prefixed for attributes. */ | 9507 /* ns-decls must be prefixed for attributes. */ |
9173 (cur->type == XML_ATTRIBUTE_NODE) ? 1 : 0) == -1) | 9508 (cur->type == XML_ATTRIBUTE_NODE) ? 1 : 0) == -1) |
9174 goto internal_error; | 9509 goto internal_error; |
9175 clone->ns = ns; | 9510 clone->ns = ns; |
9176 } | 9511 } |
9177 | 9512 |
9178 end_ns_reference: | 9513 end_ns_reference: |
9179 | 9514 |
9180 /* | 9515 /* |
9181 * Some post-processing. | 9516 * Some post-processing. |
9182 * | 9517 * |
9183 * Handle ID attributes. | 9518 * Handle ID attributes. |
9184 */ | 9519 */ |
9185 if ((clone->type == XML_ATTRIBUTE_NODE) && | 9520 if ((clone->type == XML_ATTRIBUTE_NODE) && |
9186 (clone->parent != NULL)) | 9521 (clone->parent != NULL)) |
9187 { | 9522 { |
9188 if (xmlIsID(destDoc, clone->parent, (xmlAttrPtr) clone)) { | 9523 if (xmlIsID(destDoc, clone->parent, (xmlAttrPtr) clone)) { |
9189 » | 9524 |
9190 xmlChar *idVal; | 9525 xmlChar *idVal; |
9191 » » | 9526 |
9192 idVal = xmlNodeListGetString(cur->doc, cur->children, 1); | 9527 idVal = xmlNodeListGetString(cur->doc, cur->children, 1); |
9193 if (idVal != NULL) { | 9528 if (idVal != NULL) { |
9194 if (xmlAddID(NULL, destDoc, idVal, (xmlAttrPtr) cur) == NULL
) { | 9529 if (xmlAddID(NULL, destDoc, idVal, (xmlAttrPtr) cur) == NULL
) { |
9195 /* TODO: error message. */ | 9530 /* TODO: error message. */ |
9196 xmlFree(idVal); | 9531 xmlFree(idVal); |
9197 goto internal_error; | 9532 goto internal_error; |
9198 } | 9533 } |
9199 xmlFree(idVal); | 9534 xmlFree(idVal); |
9200 } | 9535 } |
9201 } | 9536 } |
9202 } | 9537 } |
9203 /* | 9538 /* |
9204 ** | 9539 ** |
9205 ** The following will traverse the tree ************************** | 9540 ** The following will traverse the tree ************************** |
9206 ** | 9541 ** |
9207 » *» | 9542 » * |
9208 * Walk the element's attributes before descending into child-nodes. | 9543 * Walk the element's attributes before descending into child-nodes. |
9209 */ | 9544 */ |
9210 if ((cur->type == XML_ELEMENT_NODE) && (cur->properties != NULL)) { | 9545 if ((cur->type == XML_ELEMENT_NODE) && (cur->properties != NULL)) { |
9211 prevClone = NULL; | 9546 prevClone = NULL; |
9212 » parentClone = clone;» | 9547 » parentClone = clone; |
9213 cur = (xmlNodePtr) cur->properties; | 9548 cur = (xmlNodePtr) cur->properties; |
9214 continue; | 9549 continue; |
9215 } | 9550 } |
9216 into_content: | 9551 into_content: |
9217 /* | 9552 /* |
9218 * Descend into child-nodes. | 9553 * Descend into child-nodes. |
9219 */ | 9554 */ |
9220 if (cur->children != NULL) { | 9555 if (cur->children != NULL) { |
9221 if (deep || (cur->type == XML_ATTRIBUTE_NODE)) { | 9556 if (deep || (cur->type == XML_ATTRIBUTE_NODE)) { |
9222 prevClone = NULL; | 9557 prevClone = NULL; |
9223 parentClone = clone; | 9558 parentClone = clone; |
9224 cur = cur->children; | 9559 cur = cur->children; |
9225 continue; | 9560 continue; |
9226 } | 9561 } |
9227 } | 9562 } |
9228 | 9563 |
9229 leave_node: | 9564 leave_node: |
9230 /* | 9565 /* |
9231 * At this point we are done with the node, its content | 9566 * At this point we are done with the node, its content |
9232 * and an element-nodes's attribute-nodes. | 9567 * and an element-nodes's attribute-nodes. |
9233 */ | 9568 */ |
9234 if (cur == node) | 9569 if (cur == node) |
9235 break; | 9570 break; |
9236 if ((cur->type == XML_ELEMENT_NODE) || | 9571 if ((cur->type == XML_ELEMENT_NODE) || |
9237 (cur->type == XML_XINCLUDE_START) || | 9572 (cur->type == XML_XINCLUDE_START) || |
9238 (cur->type == XML_XINCLUDE_END)) { | 9573 (cur->type == XML_XINCLUDE_END)) { |
9239 /* | 9574 /* |
9240 * TODO: Do we expect nsDefs on XML_XINCLUDE_START? | 9575 * TODO: Do we expect nsDefs on XML_XINCLUDE_START? |
9241 */ | 9576 */ |
9242 » if (XML_NSMAP_NOTEMPTY(nsMap)) {» | 9577 » if (XML_NSMAP_NOTEMPTY(nsMap)) { |
9243 /* | 9578 /* |
9244 * Pop mappings. | 9579 * Pop mappings. |
9245 */ | 9580 */ |
9246 while ((nsMap->last != NULL) && | 9581 while ((nsMap->last != NULL) && |
9247 (nsMap->last->depth >= depth)) | 9582 (nsMap->last->depth >= depth)) |
9248 { | 9583 { |
9249 » » XML_NSMAP_POP(nsMap, mi)» » | 9584 » » XML_NSMAP_POP(nsMap, mi) |
9250 } | 9585 } |
9251 /* | 9586 /* |
9252 * Unshadow. | 9587 * Unshadow. |
9253 */ | 9588 */ |
9254 XML_NSMAP_FOREACH(nsMap, mi) { | 9589 XML_NSMAP_FOREACH(nsMap, mi) { |
9255 if (mi->shadowDepth >= depth) | 9590 if (mi->shadowDepth >= depth) |
9256 mi->shadowDepth = -1; | 9591 mi->shadowDepth = -1; |
9257 } | 9592 } |
9258 » }» | 9593 » } |
9259 depth--; | 9594 depth--; |
9260 } | 9595 } |
9261 if (cur->next != NULL) { | 9596 if (cur->next != NULL) { |
9262 prevClone = clone; | 9597 prevClone = clone; |
9263 cur = cur->next; | 9598 cur = cur->next; |
9264 } else if (cur->type != XML_ATTRIBUTE_NODE) { | 9599 } else if (cur->type != XML_ATTRIBUTE_NODE) { |
9265 /* | 9600 /* |
9266 * Set clone->last. | 9601 * Set clone->last. |
9267 */ | 9602 */ |
9268 if (clone->parent != NULL) | 9603 if (clone->parent != NULL) |
9269 clone->parent->last = clone; | 9604 clone->parent->last = clone; |
9270 clone = clone->parent; | 9605 clone = clone->parent; |
9271 » parentClone = clone->parent; | 9606 » parentClone = clone->parent; |
9272 /* | 9607 /* |
9273 * Process parent --> next; | 9608 * Process parent --> next; |
9274 */ | 9609 */ |
9275 cur = cur->parent; | 9610 cur = cur->parent; |
9276 goto leave_node; | 9611 goto leave_node; |
9277 } else { | 9612 } else { |
9278 /* This is for attributes only. */ | 9613 /* This is for attributes only. */ |
9279 clone = clone->parent; | 9614 clone = clone->parent; |
9280 » parentClone = clone->parent; | 9615 » parentClone = clone->parent; |
9281 /* | 9616 /* |
9282 * Process parent-element --> children. | 9617 * Process parent-element --> children. |
9283 */ | 9618 */ |
9284 cur = cur->parent; | 9619 cur = cur->parent; |
9285 » goto into_content;» | 9620 » goto into_content; |
9286 } | 9621 } |
9287 } | 9622 } |
9288 goto exit; | 9623 goto exit; |
9289 | 9624 |
9290 internal_error: | 9625 internal_error: |
9291 ret = -1; | 9626 ret = -1; |
9292 | 9627 |
9293 exit: | 9628 exit: |
9294 /* | 9629 /* |
9295 * Cleanup. | 9630 * Cleanup. |
9296 */ | 9631 */ |
9297 if (nsMap != NULL) { | 9632 if (nsMap != NULL) { |
9298 if ((ctxt) && (ctxt->namespaceMap == nsMap)) { | 9633 if ((ctxt) && (ctxt->namespaceMap == nsMap)) { |
9299 /* | 9634 /* |
9300 * Just cleanup the map but don't free. | 9635 * Just cleanup the map but don't free. |
9301 */ | 9636 */ |
9302 if (nsMap->first) { | 9637 if (nsMap->first) { |
9303 if (nsMap->pool) | 9638 if (nsMap->pool) |
9304 nsMap->last->next = nsMap->pool; | 9639 nsMap->last->next = nsMap->pool; |
9305 nsMap->pool = nsMap->first; | 9640 nsMap->pool = nsMap->first; |
9306 nsMap->first = NULL; | 9641 nsMap->first = NULL; |
9307 } | 9642 } |
9308 » } else | 9643 » } else |
9309 xmlDOMWrapNsMapFree(nsMap); | 9644 xmlDOMWrapNsMapFree(nsMap); |
9310 } | 9645 } |
9311 /* | 9646 /* |
9312 * TODO: Should we try a cleanup of the cloned node in case of a | 9647 * TODO: Should we try a cleanup of the cloned node in case of a |
9313 * fatal error? | 9648 * fatal error? |
9314 */ | 9649 */ |
9315 *resNode = resultClone; | 9650 *resNode = resultClone; |
9316 return (ret); | 9651 return (ret); |
9317 } | 9652 } |
9318 | 9653 |
(...skipping 19 matching lines...) Expand all Loading... |
9338 xmlAttrPtr attr, | 9673 xmlAttrPtr attr, |
9339 xmlDocPtr destDoc, | 9674 xmlDocPtr destDoc, |
9340 xmlNodePtr destParent, | 9675 xmlNodePtr destParent, |
9341 int options ATTRIBUTE_UNUSED) | 9676 int options ATTRIBUTE_UNUSED) |
9342 { | 9677 { |
9343 xmlNodePtr cur; | 9678 xmlNodePtr cur; |
9344 int adoptStr = 1; | 9679 int adoptStr = 1; |
9345 | 9680 |
9346 if ((attr == NULL) || (destDoc == NULL)) | 9681 if ((attr == NULL) || (destDoc == NULL)) |
9347 return (-1); | 9682 return (-1); |
9348 | 9683 |
9349 attr->doc = destDoc; | 9684 attr->doc = destDoc; |
9350 if (attr->ns != NULL) { | 9685 if (attr->ns != NULL) { |
9351 xmlNsPtr ns = NULL; | 9686 xmlNsPtr ns = NULL; |
9352 | 9687 |
9353 if (ctxt != NULL) { | 9688 if (ctxt != NULL) { |
9354 /* TODO: User defined. */ | 9689 /* TODO: User defined. */ |
9355 } | 9690 } |
9356 /* XML Namespace. */ | 9691 /* XML Namespace. */ |
9357 if (IS_STR_XML(attr->ns->prefix)) { | 9692 if (IS_STR_XML(attr->ns->prefix)) { |
9358 ns = xmlTreeEnsureXMLDecl(destDoc); | 9693 ns = xmlTreeEnsureXMLDecl(destDoc); |
9359 } else if (destParent == NULL) { | 9694 } else if (destParent == NULL) { |
9360 /* | 9695 /* |
9361 * Store in @destDoc->oldNs. | 9696 * Store in @destDoc->oldNs. |
9362 */ | 9697 */ |
9363 ns = xmlDOMWrapStoreNs(destDoc, attr->ns->href, attr->ns->prefix); | 9698 ns = xmlDOMWrapStoreNs(destDoc, attr->ns->href, attr->ns->prefix); |
9364 } else { | 9699 } else { |
9365 /* | 9700 /* |
9366 * Declare on @destParent. | 9701 * Declare on @destParent. |
9367 */ | 9702 */ |
9368 if (xmlSearchNsByNamespaceStrict(destDoc, destParent, attr->ns->href
, | 9703 if (xmlSearchNsByNamespaceStrict(destDoc, destParent, attr->ns->href
, |
9369 &ns, 1) == -1) | 9704 &ns, 1) == -1) |
9370 goto internal_error; | 9705 goto internal_error; |
9371 if (ns == NULL) { | 9706 if (ns == NULL) { |
9372 ns = xmlDOMWrapNSNormDeclareNsForced(destDoc, destParent, | 9707 ns = xmlDOMWrapNSNormDeclareNsForced(destDoc, destParent, |
9373 attr->ns->href, attr->ns->prefix, 1); | 9708 attr->ns->href, attr->ns->prefix, 1); |
9374 } | 9709 } |
9375 » }» | 9710 » } |
9376 if (ns == NULL) | 9711 if (ns == NULL) |
9377 goto internal_error; | 9712 goto internal_error; |
9378 attr->ns = ns; | 9713 attr->ns = ns; |
9379 } | 9714 } |
9380 | 9715 |
9381 XML_TREE_ADOPT_STR(attr->name); | 9716 XML_TREE_ADOPT_STR(attr->name); |
9382 attr->atype = 0; | 9717 attr->atype = 0; |
9383 attr->psvi = NULL; | 9718 attr->psvi = NULL; |
9384 /* | 9719 /* |
9385 * Walk content. | 9720 * Walk content. |
9386 */ | 9721 */ |
9387 if (attr->children == NULL) | 9722 if (attr->children == NULL) |
9388 return (0); | 9723 return (0); |
9389 cur = attr->children; | 9724 cur = attr->children; |
9390 while (cur != NULL) { | 9725 while (cur != NULL) { |
9391 cur->doc = destDoc; | 9726 cur->doc = destDoc; |
9392 switch (cur->type) { | 9727 switch (cur->type) { |
9393 case XML_TEXT_NODE: | 9728 case XML_TEXT_NODE: |
9394 case XML_CDATA_SECTION_NODE: | 9729 case XML_CDATA_SECTION_NODE: |
9395 XML_TREE_ADOPT_STR_2(cur->content) | 9730 XML_TREE_ADOPT_STR_2(cur->content) |
9396 » » break;» | 9731 » » break; |
9397 case XML_ENTITY_REF_NODE: | 9732 case XML_ENTITY_REF_NODE: |
9398 /* | 9733 /* |
9399 * Remove reference to the entitity-node. | 9734 * Remove reference to the entitity-node. |
9400 */ | 9735 */ |
9401 cur->content = NULL; | 9736 cur->content = NULL; |
9402 cur->children = NULL; | 9737 cur->children = NULL; |
9403 cur->last = NULL; | 9738 cur->last = NULL; |
9404 if ((destDoc->intSubset) || (destDoc->extSubset)) { | 9739 if ((destDoc->intSubset) || (destDoc->extSubset)) { |
9405 xmlEntityPtr ent; | 9740 xmlEntityPtr ent; |
9406 /* | 9741 /* |
9407 * Assign new entity-node if available. | 9742 * Assign new entity-node if available. |
9408 */ | 9743 */ |
9409 ent = xmlGetDocEntity(destDoc, cur->name); | 9744 ent = xmlGetDocEntity(destDoc, cur->name); |
9410 if (ent != NULL) { | 9745 if (ent != NULL) { |
9411 cur->content = ent->content; | 9746 cur->content = ent->content; |
9412 cur->children = (xmlNodePtr) ent; | 9747 cur->children = (xmlNodePtr) ent; |
9413 cur->last = (xmlNodePtr) ent; | 9748 cur->last = (xmlNodePtr) ent; |
9414 » » }» » » » | 9749 » » } |
9415 } | 9750 } |
9416 break; | 9751 break; |
9417 default: | 9752 default: |
9418 break; | 9753 break; |
9419 } | 9754 } |
9420 if (cur->children != NULL) { | 9755 if (cur->children != NULL) { |
9421 cur = cur->children; | 9756 cur = cur->children; |
9422 continue; | 9757 continue; |
9423 } | 9758 } |
9424 next_sibling: | 9759 next_sibling: |
(...skipping 17 matching lines...) Expand all Loading... |
9442 * @sourceDoc: the optional sourceDoc | 9777 * @sourceDoc: the optional sourceDoc |
9443 * @node: the node to start with | 9778 * @node: the node to start with |
9444 * @destDoc: the destination doc | 9779 * @destDoc: the destination doc |
9445 * @destParent: the optional new parent of @node in @destDoc | 9780 * @destParent: the optional new parent of @node in @destDoc |
9446 * @options: option flags | 9781 * @options: option flags |
9447 * | 9782 * |
9448 * References of out-of scope ns-decls are remapped to point to @destDoc: | 9783 * References of out-of scope ns-decls are remapped to point to @destDoc: |
9449 * 1) If @destParent is given, then nsDef entries on element-nodes are used | 9784 * 1) If @destParent is given, then nsDef entries on element-nodes are used |
9450 * 2) If *no* @destParent is given, then @destDoc->oldNs entries are used | 9785 * 2) If *no* @destParent is given, then @destDoc->oldNs entries are used |
9451 * This is the case when you have an unliked node and just want to move it | 9786 * This is the case when you have an unliked node and just want to move it |
9452 * to the context of | 9787 * to the context of |
9453 * | 9788 * |
9454 * If @destParent is given, it ensures that the tree is namespace | 9789 * If @destParent is given, it ensures that the tree is namespace |
9455 * wellformed by creating additional ns-decls where needed. | 9790 * wellformed by creating additional ns-decls where needed. |
9456 * Note that, since prefixes of already existent ns-decls can be | 9791 * Note that, since prefixes of already existent ns-decls can be |
9457 * shadowed by this process, it could break QNames in attribute | 9792 * shadowed by this process, it could break QNames in attribute |
9458 * values or element content. | 9793 * values or element content. |
9459 * NOTE: This function was not intensively tested. | 9794 * NOTE: This function was not intensively tested. |
9460 * | 9795 * |
9461 * Returns 0 if the operation succeeded, | 9796 * Returns 0 if the operation succeeded, |
9462 * 1 if a node of unsupported type was given, | 9797 * 1 if a node of unsupported type was given, |
9463 * 2 if a node of not yet supported type was given and | 9798 * 2 if a node of not yet supported type was given and |
9464 * -1 on API/internal errors. | 9799 * -1 on API/internal errors. |
9465 */ | 9800 */ |
9466 int | 9801 int |
9467 xmlDOMWrapAdoptNode(xmlDOMWrapCtxtPtr ctxt, | 9802 xmlDOMWrapAdoptNode(xmlDOMWrapCtxtPtr ctxt, |
9468 xmlDocPtr sourceDoc, | 9803 xmlDocPtr sourceDoc, |
9469 xmlNodePtr node, | 9804 xmlNodePtr node, |
9470 » » xmlDocPtr destDoc,» » | 9805 » » xmlDocPtr destDoc, |
9471 xmlNodePtr destParent, | 9806 xmlNodePtr destParent, |
9472 int options) | 9807 int options) |
9473 { | 9808 { |
9474 if ((node == NULL) || (destDoc == NULL) || | 9809 if ((node == NULL) || (destDoc == NULL) || |
9475 ((destParent != NULL) && (destParent->doc != destDoc))) | 9810 ((destParent != NULL) && (destParent->doc != destDoc))) |
9476 return(-1); | 9811 return(-1); |
9477 /* | 9812 /* |
9478 * Check node->doc sanity. | 9813 * Check node->doc sanity. |
9479 */ | 9814 */ |
9480 if ((node->doc != NULL) && (sourceDoc != NULL) && | 9815 if ((node->doc != NULL) && (sourceDoc != NULL) && |
9481 (node->doc != sourceDoc)) { | 9816 (node->doc != sourceDoc)) { |
9482 /* | 9817 /* |
9483 * Might be an XIncluded node. | 9818 * Might be an XIncluded node. |
9484 */ | 9819 */ |
9485 return (-1); | 9820 return (-1); |
9486 } | 9821 } |
9487 if (sourceDoc == NULL) | 9822 if (sourceDoc == NULL) |
9488 sourceDoc = node->doc; | 9823 sourceDoc = node->doc; |
9489 if (sourceDoc == destDoc) | 9824 if (sourceDoc == destDoc) |
9490 return (-1); | 9825 return (-1); |
9491 switch (node->type) { | 9826 switch (node->type) { |
9492 » case XML_ELEMENT_NODE:» | 9827 » case XML_ELEMENT_NODE: |
9493 case XML_ATTRIBUTE_NODE: | 9828 case XML_ATTRIBUTE_NODE: |
9494 case XML_TEXT_NODE: | 9829 case XML_TEXT_NODE: |
9495 case XML_CDATA_SECTION_NODE: | 9830 case XML_CDATA_SECTION_NODE: |
9496 case XML_ENTITY_REF_NODE: | 9831 case XML_ENTITY_REF_NODE: |
9497 case XML_PI_NODE: | 9832 case XML_PI_NODE: |
9498 case XML_COMMENT_NODE: | 9833 case XML_COMMENT_NODE: |
9499 break; | 9834 break; |
9500 case XML_DOCUMENT_FRAG_NODE: | 9835 case XML_DOCUMENT_FRAG_NODE: |
9501 /* TODO: Support document-fragment-nodes. */ | 9836 /* TODO: Support document-fragment-nodes. */ |
9502 return (2); | 9837 return (2); |
9503 default: | 9838 default: |
9504 return (1); | 9839 return (1); |
9505 } | 9840 } |
9506 /* | 9841 /* |
9507 * Unlink only if @node was not already added to @destParent. | 9842 * Unlink only if @node was not already added to @destParent. |
9508 */ | 9843 */ |
9509 if ((node->parent != NULL) && (destParent != node->parent)) | 9844 if ((node->parent != NULL) && (destParent != node->parent)) |
9510 xmlUnlinkNode(node); | 9845 xmlUnlinkNode(node); |
9511 | 9846 |
9512 if (node->type == XML_ELEMENT_NODE) { | 9847 if (node->type == XML_ELEMENT_NODE) { |
9513 return (xmlDOMWrapAdoptBranch(ctxt, sourceDoc, node, | 9848 return (xmlDOMWrapAdoptBranch(ctxt, sourceDoc, node, |
9514 destDoc, destParent, options)); | 9849 destDoc, destParent, options)); |
9515 } else if (node->type == XML_ATTRIBUTE_NODE) { | 9850 } else if (node->type == XML_ATTRIBUTE_NODE) { |
9516 return (xmlDOMWrapAdoptAttr(ctxt, sourceDoc, | 9851 return (xmlDOMWrapAdoptAttr(ctxt, sourceDoc, |
9517 (xmlAttrPtr) node, destDoc, destParent, options)); | 9852 (xmlAttrPtr) node, destDoc, destParent, options)); |
9518 } else {» | 9853 } else { |
9519 xmlNodePtr cur = node; | 9854 xmlNodePtr cur = node; |
9520 int adoptStr = 1; | 9855 int adoptStr = 1; |
9521 | 9856 |
9522 cur->doc = destDoc; | 9857 cur->doc = destDoc; |
9523 /* | 9858 /* |
9524 * Optimize string adoption. | 9859 * Optimize string adoption. |
9525 */ | 9860 */ |
9526 if ((sourceDoc != NULL) && | 9861 if ((sourceDoc != NULL) && |
9527 (sourceDoc->dict == destDoc->dict)) | 9862 (sourceDoc->dict == destDoc->dict)) |
9528 adoptStr = 0; | 9863 adoptStr = 0; |
9529 switch (node->type) { | 9864 switch (node->type) { |
9530 » case XML_TEXT_NODE:» | 9865 » case XML_TEXT_NODE: |
9531 case XML_CDATA_SECTION_NODE: | 9866 case XML_CDATA_SECTION_NODE: |
9532 XML_TREE_ADOPT_STR_2(node->content) | 9867 XML_TREE_ADOPT_STR_2(node->content) |
9533 break; | 9868 break; |
9534 case XML_ENTITY_REF_NODE: | 9869 case XML_ENTITY_REF_NODE: |
9535 /* | 9870 /* |
9536 * Remove reference to the entitity-node. | 9871 * Remove reference to the entitity-node. |
9537 */ | 9872 */ |
9538 node->content = NULL; | 9873 node->content = NULL; |
9539 node->children = NULL; | 9874 node->children = NULL; |
9540 node->last = NULL; | 9875 node->last = NULL; |
(...skipping 12 matching lines...) Expand all Loading... |
9553 XML_TREE_ADOPT_STR(node->name) | 9888 XML_TREE_ADOPT_STR(node->name) |
9554 break; | 9889 break; |
9555 case XML_PI_NODE: { | 9890 case XML_PI_NODE: { |
9556 XML_TREE_ADOPT_STR(node->name) | 9891 XML_TREE_ADOPT_STR(node->name) |
9557 XML_TREE_ADOPT_STR_2(node->content) | 9892 XML_TREE_ADOPT_STR_2(node->content) |
9558 break; | 9893 break; |
9559 } | 9894 } |
9560 default: | 9895 default: |
9561 break; | 9896 break; |
9562 } | 9897 } |
9563 }» | 9898 } |
9564 return (0); | 9899 return (0); |
9565 } | 9900 } |
9566 | 9901 |
9567 #define bottom_tree | 9902 #define bottom_tree |
9568 #include "elfgcchack.h" | 9903 #include "elfgcchack.h" |
OLD | NEW |