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 * |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include <libxml/xmlerror.h> | 34 #include <libxml/xmlerror.h> |
35 #include <libxml/parserInternals.h> | 35 #include <libxml/parserInternals.h> |
36 #include <libxml/globals.h> | 36 #include <libxml/globals.h> |
37 #ifdef LIBXML_HTML_ENABLED | 37 #ifdef LIBXML_HTML_ENABLED |
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 #include "buf.h" |
| 45 #include "save.h" |
| 46 |
44 int __xmlRegisterCallbacks = 0; | 47 int __xmlRegisterCallbacks = 0; |
45 | 48 |
46 /************************************************************************ | 49 /************************************************************************ |
47 * * | 50 * * |
48 * Forward declarations * | 51 * Forward declarations * |
49 * * | 52 * * |
50 ************************************************************************/ | 53 ************************************************************************/ |
51 | 54 |
52 static xmlNsPtr | 55 static xmlNsPtr |
53 xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns); | 56 xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns); |
54 | 57 |
55 static xmlChar* xmlGetPropNodeValueInternal(xmlAttrPtr prop); | 58 static xmlChar* xmlGetPropNodeValueInternal(const xmlAttr *prop); |
56 | 59 |
57 /************************************************************************ | 60 /************************************************************************ |
58 * * | 61 * * |
59 * Tree memory error handler * | 62 * Tree memory error handler * |
60 * * | 63 * * |
61 ************************************************************************/ | 64 ************************************************************************/ |
62 /** | 65 /** |
63 * xmlTreeErrMemory: | 66 * xmlTreeErrMemory: |
64 * @extra: extra informations | 67 * @extra: extra informations |
65 * | 68 * |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 * xmlGetEntityFromDtd: | 153 * xmlGetEntityFromDtd: |
151 * @dtd: A pointer to the DTD to search | 154 * @dtd: A pointer to the DTD to search |
152 * @name: The entity name | 155 * @name: The entity name |
153 * | 156 * |
154 * Do an entity lookup in the DTD entity hash table and | 157 * Do an entity lookup in the DTD entity hash table and |
155 * return the corresponding entity, if found. | 158 * return the corresponding entity, if found. |
156 * | 159 * |
157 * Returns A pointer to the entity structure or NULL if not found. | 160 * Returns A pointer to the entity structure or NULL if not found. |
158 */ | 161 */ |
159 static xmlEntityPtr | 162 static xmlEntityPtr |
160 xmlGetEntityFromDtd(xmlDtdPtr dtd, const xmlChar *name) { | 163 xmlGetEntityFromDtd(const xmlDtd *dtd, const xmlChar *name) { |
161 xmlEntitiesTablePtr table; | 164 xmlEntitiesTablePtr table; |
162 | 165 |
163 if((dtd != NULL) && (dtd->entities != NULL)) { | 166 if((dtd != NULL) && (dtd->entities != NULL)) { |
164 table = (xmlEntitiesTablePtr) dtd->entities; | 167 table = (xmlEntitiesTablePtr) dtd->entities; |
165 return((xmlEntityPtr) xmlHashLookup(table, name)); | 168 return((xmlEntityPtr) xmlHashLookup(table, name)); |
166 /* return(xmlGetEntityFromTable(table, name)); */ | 169 /* return(xmlGetEntityFromTable(table, name)); */ |
167 } | 170 } |
168 return(NULL); | 171 return(NULL); |
169 } | 172 } |
170 /** | 173 /** |
171 * xmlGetParameterEntityFromDtd: | 174 * xmlGetParameterEntityFromDtd: |
172 * @dtd: A pointer to the DTD to search | 175 * @dtd: A pointer to the DTD to search |
173 * @name: The entity name | 176 * @name: The entity name |
174 * | 177 * |
175 * Do an entity lookup in the DTD pararmeter entity hash table and | 178 * Do an entity lookup in the DTD pararmeter entity hash table and |
176 * return the corresponding entity, if found. | 179 * return the corresponding entity, if found. |
177 * | 180 * |
178 * Returns A pointer to the entity structure or NULL if not found. | 181 * Returns A pointer to the entity structure or NULL if not found. |
179 */ | 182 */ |
180 static xmlEntityPtr | 183 static xmlEntityPtr |
181 xmlGetParameterEntityFromDtd(xmlDtdPtr dtd, const xmlChar *name) { | 184 xmlGetParameterEntityFromDtd(const xmlDtd *dtd, const xmlChar *name) { |
182 xmlEntitiesTablePtr table; | 185 xmlEntitiesTablePtr table; |
183 | 186 |
184 if ((dtd != NULL) && (dtd->pentities != NULL)) { | 187 if ((dtd != NULL) && (dtd->pentities != NULL)) { |
185 table = (xmlEntitiesTablePtr) dtd->pentities; | 188 table = (xmlEntitiesTablePtr) dtd->pentities; |
186 return((xmlEntityPtr) xmlHashLookup(table, name)); | 189 return((xmlEntityPtr) xmlHashLookup(table, name)); |
187 /* return(xmlGetEntityFromTable(table, name)); */ | 190 /* return(xmlGetEntityFromTable(table, name)); */ |
188 } | 191 } |
189 return(NULL); | 192 return(NULL); |
190 } | 193 } |
191 #endif /* LIBXML_TREE_ENABLED */ | 194 #endif /* LIBXML_TREE_ENABLED */ |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 } | 307 } |
305 | 308 |
306 /** | 309 /** |
307 * xmlSplitQName3: | 310 * xmlSplitQName3: |
308 * @name: the full QName | 311 * @name: the full QName |
309 * @len: an int * | 312 * @len: an int * |
310 * | 313 * |
311 * parse an XML qualified name string,i | 314 * parse an XML qualified name string,i |
312 * | 315 * |
313 * returns NULL if it is not a Qualified Name, otherwise, update len | 316 * returns NULL if it is not a Qualified Name, otherwise, update len |
314 * with the lenght in byte of the prefix and return a pointer | 317 * with the length in byte of the prefix and return a pointer |
315 * to the start of the name without the prefix | 318 * to the start of the name without the prefix |
316 */ | 319 */ |
317 | 320 |
318 const xmlChar * | 321 const xmlChar * |
319 xmlSplitQName3(const xmlChar *name, int *len) { | 322 xmlSplitQName3(const xmlChar *name, int *len) { |
320 int l = 0; | 323 int l = 0; |
321 | 324 |
322 if (name == NULL) return(NULL); | 325 if (name == NULL) return(NULL); |
323 if (len == NULL) return(NULL); | 326 if (len == NULL) return(NULL); |
324 | 327 |
(...skipping 17 matching lines...) Expand all Loading... |
342 } | 345 } |
343 | 346 |
344 /************************************************************************ | 347 /************************************************************************ |
345 * * | 348 * * |
346 * Check Name, NCName and QName strings * | 349 * Check Name, NCName and QName strings * |
347 * * | 350 * * |
348 ************************************************************************/ | 351 ************************************************************************/ |
349 | 352 |
350 #define CUR_SCHAR(s, l) xmlStringCurrentChar(NULL, s, &l) | 353 #define CUR_SCHAR(s, l) xmlStringCurrentChar(NULL, s, &l) |
351 | 354 |
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) | 355 #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) || defined(LIBXML_LEGAC
Y_ENABLED) |
353 /** | 356 /** |
354 * xmlValidateNCName: | 357 * xmlValidateNCName: |
355 * @value: the value to check | 358 * @value: the value to check |
356 * @space: allow spaces in front and end of the string | 359 * @space: allow spaces in front and end of the string |
357 * | 360 * |
358 * Check that a value conforms to the lexical space of NCName | 361 * Check that a value conforms to the lexical space of NCName |
359 * | 362 * |
360 * Returns 0 if this validates, a positive error code number otherwise | 363 * Returns 0 if this validates, a positive error code number otherwise |
361 * and -1 in case of internal or API error. | 364 * and -1 in case of internal or API error. |
362 */ | 365 */ |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 * @scheme: allocation method to use | 678 * @scheme: allocation method to use |
676 * | 679 * |
677 * Set the buffer allocation method. Types are | 680 * Set the buffer allocation method. Types are |
678 * XML_BUFFER_ALLOC_EXACT - use exact sizes, keeps memory usage down | 681 * XML_BUFFER_ALLOC_EXACT - use exact sizes, keeps memory usage down |
679 * XML_BUFFER_ALLOC_DOUBLEIT - double buffer when extra needed, | 682 * XML_BUFFER_ALLOC_DOUBLEIT - double buffer when extra needed, |
680 * improves performance | 683 * improves performance |
681 */ | 684 */ |
682 void | 685 void |
683 xmlSetBufferAllocationScheme(xmlBufferAllocationScheme scheme) { | 686 xmlSetBufferAllocationScheme(xmlBufferAllocationScheme scheme) { |
684 if ((scheme == XML_BUFFER_ALLOC_EXACT) || | 687 if ((scheme == XML_BUFFER_ALLOC_EXACT) || |
685 (scheme == XML_BUFFER_ALLOC_DOUBLEIT)) | 688 (scheme == XML_BUFFER_ALLOC_DOUBLEIT) || |
| 689 (scheme == XML_BUFFER_ALLOC_HYBRID)) |
686 xmlBufferAllocScheme = scheme; | 690 xmlBufferAllocScheme = scheme; |
687 } | 691 } |
688 | 692 |
689 /** | 693 /** |
690 * xmlGetBufferAllocationScheme: | 694 * xmlGetBufferAllocationScheme: |
691 * | 695 * |
692 * Types are | 696 * Types are |
693 * XML_BUFFER_ALLOC_EXACT - use exact sizes, keeps memory usage down | 697 * XML_BUFFER_ALLOC_EXACT - use exact sizes, keeps memory usage down |
694 * XML_BUFFER_ALLOC_DOUBLEIT - double buffer when extra needed, | 698 * XML_BUFFER_ALLOC_DOUBLEIT - double buffer when extra needed, |
695 * improves performance | 699 * improves performance |
| 700 * XML_BUFFER_ALLOC_HYBRID - use exact sizes on small strings to keep memory usa
ge tight |
| 701 * in normal usage, and doubleit on large strings to
avoid |
| 702 * pathological performance. |
696 * | 703 * |
697 * Returns the current allocation scheme | 704 * Returns the current allocation scheme |
698 */ | 705 */ |
699 xmlBufferAllocationScheme | 706 xmlBufferAllocationScheme |
700 xmlGetBufferAllocationScheme(void) { | 707 xmlGetBufferAllocationScheme(void) { |
701 return(xmlBufferAllocScheme); | 708 return(xmlBufferAllocScheme); |
702 } | 709 } |
703 | 710 |
704 /** | 711 /** |
705 * xmlNewNs: | 712 * xmlNewNs: |
706 * @node: the element carrying the namespace | 713 * @node: the element carrying the namespace |
707 * @href: the URI associated | 714 * @href: the URI associated |
708 * @prefix: the prefix for the namespace | 715 * @prefix: the prefix for the namespace |
709 * | 716 * |
710 * Creation of a new Namespace. This function will refuse to create | 717 * Creation of a new Namespace. This function will refuse to create |
711 * a namespace with a similar prefix than an existing one present on this | 718 * a namespace with a similar prefix than an existing one present on this |
712 * node. | 719 * node. |
| 720 * Note that for a default namespace, @prefix should be NULL. |
| 721 * |
713 * We use href==NULL in the case of an element creation where the namespace | 722 * We use href==NULL in the case of an element creation where the namespace |
714 * was not defined. | 723 * was not defined. |
| 724 * |
715 * Returns a new namespace pointer or NULL | 725 * Returns a new namespace pointer or NULL |
716 */ | 726 */ |
717 xmlNsPtr | 727 xmlNsPtr |
718 xmlNewNs(xmlNodePtr node, const xmlChar *href, const xmlChar *prefix) { | 728 xmlNewNs(xmlNodePtr node, const xmlChar *href, const xmlChar *prefix) { |
719 xmlNsPtr cur; | 729 xmlNsPtr cur; |
720 | 730 |
721 if ((node != NULL) && (node->type != XML_ELEMENT_NODE)) | 731 if ((node != NULL) && (node->type != XML_ELEMENT_NODE)) |
722 return(NULL); | 732 return(NULL); |
723 | 733 |
724 if ((prefix != NULL) && (xmlStrEqual(prefix, BAD_CAST "xml"))) | 734 if ((prefix != NULL) && (xmlStrEqual(prefix, BAD_CAST "xml"))) { |
725 » return(NULL); | 735 /* xml namespace is predefined, no need to add it */ |
| 736 if (xmlStrEqual(href, XML_XML_NAMESPACE)) |
| 737 return(NULL); |
| 738 |
| 739 /* |
| 740 * Problem, this is an attempt to bind xml prefix to a wrong |
| 741 * namespace, which breaks |
| 742 * Namespace constraint: Reserved Prefixes and Namespace Names |
| 743 * from XML namespace. But documents authors may not care in |
| 744 * their context so let's proceed. |
| 745 */ |
| 746 } |
726 | 747 |
727 /* | 748 /* |
728 * Allocate a new Namespace and fill the fields. | 749 * Allocate a new Namespace and fill the fields. |
729 */ | 750 */ |
730 cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); | 751 cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); |
731 if (cur == NULL) { | 752 if (cur == NULL) { |
732 xmlTreeErrMemory("building namespace"); | 753 xmlTreeErrMemory("building namespace"); |
733 return(NULL); | 754 return(NULL); |
734 } | 755 } |
735 memset(cur, 0, sizeof(xmlNs)); | 756 memset(cur, 0, sizeof(xmlNs)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 */ | 799 */ |
779 void | 800 void |
780 xmlSetNs(xmlNodePtr node, xmlNsPtr ns) { | 801 xmlSetNs(xmlNodePtr node, xmlNsPtr ns) { |
781 if (node == NULL) { | 802 if (node == NULL) { |
782 #ifdef DEBUG_TREE | 803 #ifdef DEBUG_TREE |
783 xmlGenericError(xmlGenericErrorContext, | 804 xmlGenericError(xmlGenericErrorContext, |
784 "xmlSetNs: node == NULL\n"); | 805 "xmlSetNs: node == NULL\n"); |
785 #endif | 806 #endif |
786 return; | 807 return; |
787 } | 808 } |
788 node->ns = ns; | 809 if ((node->type == XML_ELEMENT_NODE) || |
| 810 (node->type == XML_ATTRIBUTE_NODE)) |
| 811 » node->ns = ns; |
789 } | 812 } |
790 | 813 |
791 /** | 814 /** |
792 * xmlFreeNs: | 815 * xmlFreeNs: |
793 * @cur: the namespace pointer | 816 * @cur: the namespace pointer |
794 * | 817 * |
795 * Free up the structures associated to a namespace | 818 * Free up the structures associated to a namespace |
796 */ | 819 */ |
797 void | 820 void |
798 xmlFreeNs(xmlNsPtr cur) { | 821 xmlFreeNs(xmlNsPtr cur) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 | 909 |
887 /** | 910 /** |
888 * xmlGetIntSubset: | 911 * xmlGetIntSubset: |
889 * @doc: the document pointer | 912 * @doc: the document pointer |
890 * | 913 * |
891 * Get the internal subset of a document | 914 * Get the internal subset of a document |
892 * Returns a pointer to the DTD structure or NULL if not found | 915 * Returns a pointer to the DTD structure or NULL if not found |
893 */ | 916 */ |
894 | 917 |
895 xmlDtdPtr | 918 xmlDtdPtr |
896 xmlGetIntSubset(xmlDocPtr doc) { | 919 xmlGetIntSubset(const xmlDoc *doc) { |
897 xmlNodePtr cur; | 920 xmlNodePtr cur; |
898 | 921 |
899 if (doc == NULL) | 922 if (doc == NULL) |
900 return(NULL); | 923 return(NULL); |
901 cur = doc->children; | 924 cur = doc->children; |
902 while (cur != NULL) { | 925 while (cur != NULL) { |
903 if (cur->type == XML_DTD_NODE) | 926 if (cur->type == XML_DTD_NODE) |
904 return((xmlDtdPtr) cur); | 927 return((xmlDtdPtr) cur); |
905 cur = cur->next; | 928 cur = cur->next; |
906 } | 929 } |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1236 * xmlStringLenGetNodeList: | 1259 * xmlStringLenGetNodeList: |
1237 * @doc: the document | 1260 * @doc: the document |
1238 * @value: the value of the text | 1261 * @value: the value of the text |
1239 * @len: the length of the string value | 1262 * @len: the length of the string value |
1240 * | 1263 * |
1241 * Parse the value string and build the node list associated. Should | 1264 * Parse the value string and build the node list associated. Should |
1242 * produce a flat tree with only TEXTs and ENTITY_REFs. | 1265 * produce a flat tree with only TEXTs and ENTITY_REFs. |
1243 * Returns a pointer to the first child | 1266 * Returns a pointer to the first child |
1244 */ | 1267 */ |
1245 xmlNodePtr | 1268 xmlNodePtr |
1246 xmlStringLenGetNodeList(xmlDocPtr doc, const xmlChar *value, int len) { | 1269 xmlStringLenGetNodeList(const xmlDoc *doc, const xmlChar *value, int len) { |
1247 xmlNodePtr ret = NULL, last = NULL; | 1270 xmlNodePtr ret = NULL, last = NULL; |
1248 xmlNodePtr node; | 1271 xmlNodePtr node; |
1249 xmlChar *val; | 1272 xmlChar *val; |
1250 const xmlChar *cur = value, *end = cur + len; | 1273 const xmlChar *cur = value, *end = cur + len; |
1251 const xmlChar *q; | 1274 const xmlChar *q; |
1252 xmlEntityPtr ent; | 1275 xmlEntityPtr ent; |
| 1276 xmlBufPtr buf; |
1253 | 1277 |
1254 if (value == NULL) return(NULL); | 1278 if (value == NULL) return(NULL); |
1255 | 1279 |
| 1280 buf = xmlBufCreateSize(0); |
| 1281 if (buf == NULL) return(NULL); |
| 1282 xmlBufSetAllocationScheme(buf, XML_BUFFER_ALLOC_HYBRID); |
| 1283 |
1256 q = cur; | 1284 q = cur; |
1257 while ((cur < end) && (*cur != 0)) { | 1285 while ((cur < end) && (*cur != 0)) { |
1258 if (cur[0] == '&') { | 1286 if (cur[0] == '&') { |
1259 int charval = 0; | 1287 int charval = 0; |
1260 xmlChar tmp; | 1288 xmlChar tmp; |
1261 | 1289 |
1262 /* | 1290 /* |
1263 * Save the current text. | 1291 * Save the current text. |
1264 */ | 1292 */ |
1265 if (cur != q) { | 1293 if (cur != q) { |
1266 » » if ((last != NULL) && (last->type == XML_TEXT_NODE)) { | 1294 » » if (xmlBufAdd(buf, q, cur - q)) |
1267 » » xmlNodeAddContentLen(last, q, cur - q); | 1295 » » goto out; |
1268 » » } else { | |
1269 » » node = xmlNewDocTextLen(doc, q, cur - q); | |
1270 » » if (node == NULL) return(ret); | |
1271 » » if (last == NULL) | |
1272 » » » last = ret = node; | |
1273 » » else { | |
1274 » » » last->next = node; | |
1275 » » » node->prev = last; | |
1276 » » » last = node; | |
1277 » » } | |
1278 » » } | |
1279 } | 1296 } |
1280 q = cur; | 1297 q = cur; |
1281 if ((cur + 2 < end) && (cur[1] == '#') && (cur[2] == 'x')) { | 1298 if ((cur + 2 < end) && (cur[1] == '#') && (cur[2] == 'x')) { |
1282 cur += 3; | 1299 cur += 3; |
1283 if (cur < end) | 1300 if (cur < end) |
1284 tmp = *cur; | 1301 tmp = *cur; |
1285 else | 1302 else |
1286 tmp = 0; | 1303 tmp = 0; |
1287 while (tmp != ';') { /* Non input consuming loop */ | 1304 while (tmp != ';') { /* Non input consuming loop */ |
1288 if ((tmp >= '0') && (tmp <= '9')) | 1305 if ((tmp >= '0') && (tmp <= '9')) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 } else { | 1350 } else { |
1334 /* | 1351 /* |
1335 * Read the entity string | 1352 * Read the entity string |
1336 */ | 1353 */ |
1337 cur++; | 1354 cur++; |
1338 q = cur; | 1355 q = cur; |
1339 while ((cur < end) && (*cur != 0) && (*cur != ';')) cur++; | 1356 while ((cur < end) && (*cur != 0) && (*cur != ';')) cur++; |
1340 if ((cur >= end) || (*cur == 0)) { | 1357 if ((cur >= end) || (*cur == 0)) { |
1341 xmlTreeErr(XML_TREE_UNTERMINATED_ENTITY, (xmlNodePtr) doc, | 1358 xmlTreeErr(XML_TREE_UNTERMINATED_ENTITY, (xmlNodePtr) doc, |
1342 (const char *) q); | 1359 (const char *) q); |
1343 » » return(ret); | 1360 » » goto out; |
1344 } | 1361 } |
1345 if (cur != q) { | 1362 if (cur != q) { |
1346 /* | 1363 /* |
1347 * Predefined entities don't generate nodes | 1364 * Predefined entities don't generate nodes |
1348 */ | 1365 */ |
1349 val = xmlStrndup(q, cur - q); | 1366 val = xmlStrndup(q, cur - q); |
1350 ent = xmlGetDocEntity(doc, val); | 1367 ent = xmlGetDocEntity(doc, val); |
1351 if ((ent != NULL) && | 1368 if ((ent != NULL) && |
1352 (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { | 1369 (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { |
1353 » » » if (last == NULL) { | 1370 |
1354 » » » node = xmlNewDocText(doc, ent->content); | 1371 » » » if (xmlBufCat(buf, ent->content)) |
1355 » » » last = ret = node; | 1372 » » » goto out; |
1356 » » » } else if (last->type != XML_TEXT_NODE) { | |
1357 » » » node = xmlNewDocText(doc, ent->content); | |
1358 » » » last = xmlAddNextSibling(last, node); | |
1359 » » » } else | |
1360 » » » xmlNodeAddContent(last, ent->content); | |
1361 | 1373 |
1362 } else { | 1374 } else { |
1363 /* | 1375 /* |
| 1376 * Flush buffer so far |
| 1377 */ |
| 1378 if (!xmlBufIsEmpty(buf)) { |
| 1379 node = xmlNewDocText(doc, NULL); |
| 1380 if (node == NULL) { |
| 1381 if (val != NULL) xmlFree(val); |
| 1382 goto out; |
| 1383 } |
| 1384 node->content = xmlBufDetach(buf); |
| 1385 |
| 1386 if (last == NULL) { |
| 1387 last = ret = node; |
| 1388 } else { |
| 1389 last = xmlAddNextSibling(last, node); |
| 1390 } |
| 1391 } |
| 1392 |
| 1393 /* |
1364 * Create a new REFERENCE_REF node | 1394 * Create a new REFERENCE_REF node |
1365 */ | 1395 */ |
1366 node = xmlNewReference(doc, val); | 1396 node = xmlNewReference(doc, val); |
1367 if (node == NULL) { | 1397 if (node == NULL) { |
1368 if (val != NULL) xmlFree(val); | 1398 if (val != NULL) xmlFree(val); |
1369 » » » return(ret); | 1399 » » » goto out; |
1370 } | 1400 } |
1371 else if ((ent != NULL) && (ent->children == NULL)) { | 1401 else if ((ent != NULL) && (ent->children == NULL)) { |
1372 xmlNodePtr temp; | 1402 xmlNodePtr temp; |
1373 | 1403 |
1374 ent->children = xmlStringGetNodeList(doc, | 1404 ent->children = xmlStringGetNodeList(doc, |
1375 (const xmlChar*)node->content); | 1405 (const xmlChar*)node->content); |
1376 ent->owner = 1; | 1406 ent->owner = 1; |
1377 temp = ent->children; | 1407 temp = ent->children; |
1378 while (temp) { | 1408 while (temp) { |
1379 temp->parent = (xmlNodePtr)ent; | 1409 temp->parent = (xmlNodePtr)ent; |
1380 ent->last = temp; | 1410 ent->last = temp; |
1381 temp = temp->next; | 1411 temp = temp->next; |
1382 } | 1412 } |
1383 } | 1413 } |
1384 if (last == NULL) { | 1414 if (last == NULL) { |
1385 last = ret = node; | 1415 last = ret = node; |
1386 } else { | 1416 } else { |
1387 last = xmlAddNextSibling(last, node); | 1417 last = xmlAddNextSibling(last, node); |
1388 } | 1418 } |
1389 } | 1419 } |
1390 xmlFree(val); | 1420 xmlFree(val); |
1391 } | 1421 } |
1392 cur++; | 1422 cur++; |
1393 q = cur; | 1423 q = cur; |
1394 } | 1424 } |
1395 if (charval != 0) { | 1425 if (charval != 0) { |
1396 » » xmlChar buf[10]; | 1426 » » xmlChar buffer[10]; |
1397 int l; | 1427 int l; |
1398 | 1428 |
1399 » » l = xmlCopyCharMultiByte(buf, charval); | 1429 » » l = xmlCopyCharMultiByte(buffer, charval); |
1400 » » buf[l] = 0; | 1430 » » buffer[l] = 0; |
1401 » » node = xmlNewDocText(doc, buf); | 1431 |
1402 » » if (node != NULL) { | 1432 » » if (xmlBufCat(buf, buffer)) |
1403 » » if (last == NULL) { | 1433 » » goto out; |
1404 » » » last = ret = node; | |
1405 » » } else { | |
1406 » » » last = xmlAddNextSibling(last, node); | |
1407 » » } | |
1408 » » } | |
1409 charval = 0; | 1434 charval = 0; |
1410 } | 1435 } |
1411 } else | 1436 } else |
1412 cur++; | 1437 cur++; |
1413 } | 1438 } |
1414 if ((cur != q) || (ret == NULL)) { | 1439 |
| 1440 if (cur != q) { |
1415 /* | 1441 /* |
1416 * Handle the last piece of text. | 1442 * Handle the last piece of text. |
1417 */ | 1443 */ |
1418 » if ((last != NULL) && (last->type == XML_TEXT_NODE)) { | 1444 » if (xmlBufAdd(buf, q, cur - q)) |
1419 » xmlNodeAddContentLen(last, q, cur - q); | 1445 » goto out; |
| 1446 } |
| 1447 |
| 1448 if (!xmlBufIsEmpty(buf)) { |
| 1449 » node = xmlNewDocText(doc, NULL); |
| 1450 » if (node == NULL) goto out; |
| 1451 » node->content = xmlBufDetach(buf); |
| 1452 |
| 1453 » if (last == NULL) { |
| 1454 » last = ret = node; |
1420 } else { | 1455 } else { |
1421 » node = xmlNewDocTextLen(doc, q, cur - q); | 1456 » last = xmlAddNextSibling(last, node); |
1422 » if (node == NULL) return(ret); | |
1423 » if (last == NULL) { | |
1424 » » ret = node; | |
1425 » } else { | |
1426 » » xmlAddNextSibling(last, node); | |
1427 » } | |
1428 } | 1457 } |
| 1458 } else if (ret == NULL) { |
| 1459 ret = xmlNewDocText(doc, BAD_CAST ""); |
1429 } | 1460 } |
| 1461 |
| 1462 out: |
| 1463 xmlBufFree(buf); |
1430 return(ret); | 1464 return(ret); |
1431 } | 1465 } |
1432 | 1466 |
1433 /** | 1467 /** |
1434 * xmlStringGetNodeList: | 1468 * xmlStringGetNodeList: |
1435 * @doc: the document | 1469 * @doc: the document |
1436 * @value: the value of the attribute | 1470 * @value: the value of the attribute |
1437 * | 1471 * |
1438 * Parse the value string and build the node list associated. Should | 1472 * Parse the value string and build the node list associated. Should |
1439 * produce a flat tree with only TEXTs and ENTITY_REFs. | 1473 * produce a flat tree with only TEXTs and ENTITY_REFs. |
1440 * Returns a pointer to the first child | 1474 * Returns a pointer to the first child |
1441 */ | 1475 */ |
1442 xmlNodePtr | 1476 xmlNodePtr |
1443 xmlStringGetNodeList(xmlDocPtr doc, const xmlChar *value) { | 1477 xmlStringGetNodeList(const xmlDoc *doc, const xmlChar *value) { |
1444 xmlNodePtr ret = NULL, last = NULL; | 1478 xmlNodePtr ret = NULL, last = NULL; |
1445 xmlNodePtr node; | 1479 xmlNodePtr node; |
1446 xmlChar *val; | 1480 xmlChar *val; |
1447 const xmlChar *cur = value; | 1481 const xmlChar *cur = value; |
1448 const xmlChar *q; | 1482 const xmlChar *q; |
1449 xmlEntityPtr ent; | 1483 xmlEntityPtr ent; |
| 1484 xmlBufPtr buf; |
1450 | 1485 |
1451 if (value == NULL) return(NULL); | 1486 if (value == NULL) return(NULL); |
1452 | 1487 |
| 1488 buf = xmlBufCreateSize(0); |
| 1489 if (buf == NULL) return(NULL); |
| 1490 xmlBufSetAllocationScheme(buf, XML_BUFFER_ALLOC_HYBRID); |
| 1491 |
1453 q = cur; | 1492 q = cur; |
1454 while (*cur != 0) { | 1493 while (*cur != 0) { |
1455 if (cur[0] == '&') { | 1494 if (cur[0] == '&') { |
1456 int charval = 0; | 1495 int charval = 0; |
1457 xmlChar tmp; | 1496 xmlChar tmp; |
1458 | 1497 |
1459 /* | 1498 /* |
1460 * Save the current text. | 1499 * Save the current text. |
1461 */ | 1500 */ |
1462 if (cur != q) { | 1501 if (cur != q) { |
1463 » » if ((last != NULL) && (last->type == XML_TEXT_NODE)) { | 1502 » » if (xmlBufAdd(buf, q, cur - q)) |
1464 » » xmlNodeAddContentLen(last, q, cur - q); | 1503 » » goto out; |
1465 » » } else { | |
1466 » » node = xmlNewDocTextLen(doc, q, cur - q); | |
1467 » » if (node == NULL) return(ret); | |
1468 » » if (last == NULL) | |
1469 » » » last = ret = node; | |
1470 » » else { | |
1471 » » » last->next = node; | |
1472 » » » node->prev = last; | |
1473 » » » last = node; | |
1474 » » } | |
1475 » » } | |
1476 } | 1504 } |
1477 q = cur; | 1505 q = cur; |
1478 if ((cur[1] == '#') && (cur[2] == 'x')) { | 1506 if ((cur[1] == '#') && (cur[2] == 'x')) { |
1479 cur += 3; | 1507 cur += 3; |
1480 tmp = *cur; | 1508 tmp = *cur; |
1481 while (tmp != ';') { /* Non input consuming loop */ | 1509 while (tmp != ';') { /* Non input consuming loop */ |
1482 if ((tmp >= '0') && (tmp <= '9')) | 1510 if ((tmp >= '0') && (tmp <= '9')) |
1483 charval = charval * 16 + (tmp - '0'); | 1511 charval = charval * 16 + (tmp - '0'); |
1484 else if ((tmp >= 'a') && (tmp <= 'f')) | 1512 else if ((tmp >= 'a') && (tmp <= 'f')) |
1485 charval = charval * 16 + (tmp - 'a') + 10; | 1513 charval = charval * 16 + (tmp - 'a') + 10; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1518 } else { | 1546 } else { |
1519 /* | 1547 /* |
1520 * Read the entity string | 1548 * Read the entity string |
1521 */ | 1549 */ |
1522 cur++; | 1550 cur++; |
1523 q = cur; | 1551 q = cur; |
1524 while ((*cur != 0) && (*cur != ';')) cur++; | 1552 while ((*cur != 0) && (*cur != ';')) cur++; |
1525 if (*cur == 0) { | 1553 if (*cur == 0) { |
1526 xmlTreeErr(XML_TREE_UNTERMINATED_ENTITY, | 1554 xmlTreeErr(XML_TREE_UNTERMINATED_ENTITY, |
1527 (xmlNodePtr) doc, (const char *) q); | 1555 (xmlNodePtr) doc, (const char *) q); |
1528 » » return(ret); | 1556 » » goto out; |
1529 } | 1557 } |
1530 if (cur != q) { | 1558 if (cur != q) { |
1531 /* | 1559 /* |
1532 * Predefined entities don't generate nodes | 1560 * Predefined entities don't generate nodes |
1533 */ | 1561 */ |
1534 val = xmlStrndup(q, cur - q); | 1562 val = xmlStrndup(q, cur - q); |
1535 ent = xmlGetDocEntity(doc, val); | 1563 ent = xmlGetDocEntity(doc, val); |
1536 if ((ent != NULL) && | 1564 if ((ent != NULL) && |
1537 (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { | 1565 (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { |
1538 » » » if (last == NULL) { | 1566 |
1539 » » » node = xmlNewDocText(doc, ent->content); | 1567 » » » if (xmlBufCat(buf, ent->content)) |
1540 » » » last = ret = node; | 1568 » » » goto out; |
1541 » » » } else if (last->type != XML_TEXT_NODE) { | |
1542 » » » node = xmlNewDocText(doc, ent->content); | |
1543 » » » last = xmlAddNextSibling(last, node); | |
1544 » » » } else | |
1545 » » » xmlNodeAddContent(last, ent->content); | |
1546 | 1569 |
1547 } else { | 1570 } else { |
1548 /* | 1571 /* |
| 1572 * Flush buffer so far |
| 1573 */ |
| 1574 if (!xmlBufIsEmpty(buf)) { |
| 1575 node = xmlNewDocText(doc, NULL); |
| 1576 node->content = xmlBufDetach(buf); |
| 1577 |
| 1578 if (last == NULL) { |
| 1579 last = ret = node; |
| 1580 } else { |
| 1581 last = xmlAddNextSibling(last, node); |
| 1582 } |
| 1583 } |
| 1584 |
| 1585 /* |
1549 * Create a new REFERENCE_REF node | 1586 * Create a new REFERENCE_REF node |
1550 */ | 1587 */ |
1551 node = xmlNewReference(doc, val); | 1588 node = xmlNewReference(doc, val); |
1552 if (node == NULL) { | 1589 if (node == NULL) { |
1553 if (val != NULL) xmlFree(val); | 1590 if (val != NULL) xmlFree(val); |
1554 » » » return(ret); | 1591 » » » goto out; |
1555 } | 1592 } |
1556 else if ((ent != NULL) && (ent->children == NULL)) { | 1593 else if ((ent != NULL) && (ent->children == NULL)) { |
1557 xmlNodePtr temp; | 1594 xmlNodePtr temp; |
1558 | 1595 |
1559 ent->children = xmlStringGetNodeList(doc, | 1596 ent->children = xmlStringGetNodeList(doc, |
1560 (const xmlChar*)node->content); | 1597 (const xmlChar*)node->content); |
1561 ent->owner = 1; | 1598 ent->owner = 1; |
1562 temp = ent->children; | 1599 temp = ent->children; |
1563 while (temp) { | 1600 while (temp) { |
1564 temp->parent = (xmlNodePtr)ent; | 1601 temp->parent = (xmlNodePtr)ent; |
1565 temp = temp->next; | 1602 temp = temp->next; |
1566 } | 1603 } |
1567 } | 1604 } |
1568 if (last == NULL) { | 1605 if (last == NULL) { |
1569 last = ret = node; | 1606 last = ret = node; |
1570 } else { | 1607 } else { |
1571 last = xmlAddNextSibling(last, node); | 1608 last = xmlAddNextSibling(last, node); |
1572 } | 1609 } |
1573 } | 1610 } |
1574 xmlFree(val); | 1611 xmlFree(val); |
1575 } | 1612 } |
1576 cur++; | 1613 cur++; |
1577 q = cur; | 1614 q = cur; |
1578 } | 1615 } |
1579 if (charval != 0) { | 1616 if (charval != 0) { |
1580 » » xmlChar buf[10]; | 1617 » » xmlChar buffer[10]; |
1581 int len; | 1618 int len; |
1582 | 1619 |
1583 » » len = xmlCopyCharMultiByte(buf, charval); | 1620 » » len = xmlCopyCharMultiByte(buffer, charval); |
1584 » » buf[len] = 0; | 1621 » » buffer[len] = 0; |
1585 » » node = xmlNewDocText(doc, buf); | 1622 |
1586 » » if (node != NULL) { | 1623 » » if (xmlBufCat(buf, buffer)) |
1587 » » if (last == NULL) { | 1624 » » goto out; |
1588 » » » last = ret = node; | 1625 » » charval = 0; |
1589 » » } else { | |
1590 » » » last = xmlAddNextSibling(last, node); | |
1591 » » } | |
1592 » » } | |
1593 } | 1626 } |
1594 } else | 1627 } else |
1595 cur++; | 1628 cur++; |
1596 } | 1629 } |
1597 if ((cur != q) || (ret == NULL)) { | 1630 if ((cur != q) || (ret == NULL)) { |
1598 /* | 1631 /* |
1599 * Handle the last piece of text. | 1632 * Handle the last piece of text. |
1600 */ | 1633 */ |
1601 » if ((last != NULL) && (last->type == XML_TEXT_NODE)) { | 1634 » xmlBufAdd(buf, q, cur - q); |
1602 » xmlNodeAddContentLen(last, q, cur - q); | 1635 } |
| 1636 |
| 1637 if (!xmlBufIsEmpty(buf)) { |
| 1638 » node = xmlNewDocText(doc, NULL); |
| 1639 » node->content = xmlBufDetach(buf); |
| 1640 |
| 1641 » if (last == NULL) { |
| 1642 » last = ret = node; |
1603 } else { | 1643 } else { |
1604 » node = xmlNewDocTextLen(doc, q, cur - q); | 1644 » last = xmlAddNextSibling(last, node); |
1605 » if (node == NULL) return(ret); | |
1606 » if (last == NULL) { | |
1607 » » last = ret = node; | |
1608 » } else { | |
1609 » » last = xmlAddNextSibling(last, node); | |
1610 » } | |
1611 } | 1645 } |
1612 } | 1646 } |
| 1647 |
| 1648 out: |
| 1649 xmlBufFree(buf); |
1613 return(ret); | 1650 return(ret); |
1614 } | 1651 } |
1615 | 1652 |
1616 /** | 1653 /** |
1617 * xmlNodeListGetString: | 1654 * xmlNodeListGetString: |
1618 * @doc: the document | 1655 * @doc: the document |
1619 * @list: a Node list | 1656 * @list: a Node list |
1620 * @inLine: should we replace entity contents or show their external form | 1657 * @inLine: should we replace entity contents or show their external form |
1621 * | 1658 * |
1622 * Build the string equivalent to the text contained in the Node list | 1659 * Build the string equivalent to the text contained in the Node list |
1623 * made of TEXTs and ENTITY_REFs | 1660 * made of TEXTs and ENTITY_REFs |
1624 * | 1661 * |
1625 * Returns a pointer to the string copy, the caller must free it with xmlFree(). | 1662 * Returns a pointer to the string copy, the caller must free it with xmlFree(). |
1626 */ | 1663 */ |
1627 xmlChar * | 1664 xmlChar * |
1628 xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine) | 1665 xmlNodeListGetString(xmlDocPtr doc, const xmlNode *list, int inLine) |
1629 { | 1666 { |
1630 xmlNodePtr node = list; | 1667 const xmlNode *node = list; |
1631 xmlChar *ret = NULL; | 1668 xmlChar *ret = NULL; |
1632 xmlEntityPtr ent; | 1669 xmlEntityPtr ent; |
| 1670 int attr; |
1633 | 1671 |
1634 if (list == NULL) | 1672 if (list == NULL) |
1635 return (NULL); | 1673 return (NULL); |
| 1674 if ((list->parent != NULL) && (list->parent->type == XML_ATTRIBUTE_NODE)) |
| 1675 attr = 1; |
| 1676 else |
| 1677 attr = 0; |
1636 | 1678 |
1637 while (node != NULL) { | 1679 while (node != NULL) { |
1638 if ((node->type == XML_TEXT_NODE) || | 1680 if ((node->type == XML_TEXT_NODE) || |
1639 (node->type == XML_CDATA_SECTION_NODE)) { | 1681 (node->type == XML_CDATA_SECTION_NODE)) { |
1640 if (inLine) { | 1682 if (inLine) { |
1641 ret = xmlStrcat(ret, node->content); | 1683 ret = xmlStrcat(ret, node->content); |
1642 } else { | 1684 } else { |
1643 xmlChar *buffer; | 1685 xmlChar *buffer; |
1644 | 1686 |
1645 buffer = xmlEncodeEntitiesReentrant(doc, node->content); | 1687 » » if (attr) |
| 1688 » » buffer = xmlEncodeAttributeEntities(doc, node->content); |
| 1689 » » else |
| 1690 » » buffer = xmlEncodeEntitiesReentrant(doc, node->content); |
1646 if (buffer != NULL) { | 1691 if (buffer != NULL) { |
1647 ret = xmlStrcat(ret, buffer); | 1692 ret = xmlStrcat(ret, buffer); |
1648 xmlFree(buffer); | 1693 xmlFree(buffer); |
1649 } | 1694 } |
1650 } | 1695 } |
1651 } else if (node->type == XML_ENTITY_REF_NODE) { | 1696 } else if (node->type == XML_ENTITY_REF_NODE) { |
1652 if (inLine) { | 1697 if (inLine) { |
1653 ent = xmlGetDocEntity(doc, node->name); | 1698 ent = xmlGetDocEntity(doc, node->name); |
1654 if (ent != NULL) { | 1699 if (ent != NULL) { |
1655 xmlChar *buffer; | 1700 xmlChar *buffer; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1700 * @list: a Node list | 1745 * @list: a Node list |
1701 * @inLine: should we replace entity contents or show their external form | 1746 * @inLine: should we replace entity contents or show their external form |
1702 * | 1747 * |
1703 * Builds the string equivalent to the text contained in the Node list | 1748 * Builds the string equivalent to the text contained in the Node list |
1704 * made of TEXTs and ENTITY_REFs, contrary to xmlNodeListGetString() | 1749 * made of TEXTs and ENTITY_REFs, contrary to xmlNodeListGetString() |
1705 * this function doesn't do any character encoding handling. | 1750 * this function doesn't do any character encoding handling. |
1706 * | 1751 * |
1707 * Returns a pointer to the string copy, the caller must free it with xmlFree(). | 1752 * Returns a pointer to the string copy, the caller must free it with xmlFree(). |
1708 */ | 1753 */ |
1709 xmlChar * | 1754 xmlChar * |
1710 xmlNodeListGetRawString(xmlDocPtr doc, xmlNodePtr list, int inLine) | 1755 xmlNodeListGetRawString(const xmlDoc *doc, const xmlNode *list, int inLine) |
1711 { | 1756 { |
1712 xmlNodePtr node = list; | 1757 const xmlNode *node = list; |
1713 xmlChar *ret = NULL; | 1758 xmlChar *ret = NULL; |
1714 xmlEntityPtr ent; | 1759 xmlEntityPtr ent; |
1715 | 1760 |
1716 if (list == NULL) | 1761 if (list == NULL) |
1717 return (NULL); | 1762 return (NULL); |
1718 | 1763 |
1719 while (node != NULL) { | 1764 while (node != NULL) { |
1720 if ((node->type == XML_TEXT_NODE) || | 1765 if ((node->type == XML_TEXT_NODE) || |
1721 (node->type == XML_CDATA_SECTION_NODE)) { | 1766 (node->type == XML_CDATA_SECTION_NODE)) { |
1722 if (inLine) { | 1767 if (inLine) { |
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2531 | 2576 |
2532 /** | 2577 /** |
2533 * xmlNewReference: | 2578 * xmlNewReference: |
2534 * @doc: the document | 2579 * @doc: the document |
2535 * @name: the reference name, or the reference string with & and ; | 2580 * @name: the reference name, or the reference string with & and ; |
2536 * | 2581 * |
2537 * Creation of a new reference node. | 2582 * Creation of a new reference node. |
2538 * Returns a pointer to the new node object. | 2583 * Returns a pointer to the new node object. |
2539 */ | 2584 */ |
2540 xmlNodePtr | 2585 xmlNodePtr |
2541 xmlNewReference(xmlDocPtr doc, const xmlChar *name) { | 2586 xmlNewReference(const xmlDoc *doc, const xmlChar *name) { |
2542 xmlNodePtr cur; | 2587 xmlNodePtr cur; |
2543 xmlEntityPtr ent; | 2588 xmlEntityPtr ent; |
2544 | 2589 |
2545 if (name == NULL) | 2590 if (name == NULL) |
2546 return(NULL); | 2591 return(NULL); |
2547 | 2592 |
2548 /* | 2593 /* |
2549 * Allocate a new node and fill the fields. | 2594 * Allocate a new node and fill the fields. |
2550 */ | 2595 */ |
2551 cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); | 2596 cur = (xmlNodePtr) xmlMalloc(sizeof(xmlNode)); |
2552 if (cur == NULL) { | 2597 if (cur == NULL) { |
2553 xmlTreeErrMemory("building reference"); | 2598 xmlTreeErrMemory("building reference"); |
2554 return(NULL); | 2599 return(NULL); |
2555 } | 2600 } |
2556 memset(cur, 0, sizeof(xmlNode)); | 2601 memset(cur, 0, sizeof(xmlNode)); |
2557 cur->type = XML_ENTITY_REF_NODE; | 2602 cur->type = XML_ENTITY_REF_NODE; |
2558 | 2603 |
2559 cur->doc = doc; | 2604 cur->doc = (xmlDoc *)doc; |
2560 if (name[0] == '&') { | 2605 if (name[0] == '&') { |
2561 int len; | 2606 int len; |
2562 name++; | 2607 name++; |
2563 len = xmlStrlen(name); | 2608 len = xmlStrlen(name); |
2564 if (name[len - 1] == ';') | 2609 if (name[len - 1] == ';') |
2565 cur->name = xmlStrndup(name, len - 1); | 2610 cur->name = xmlStrndup(name, len - 1); |
2566 else | 2611 else |
2567 cur->name = xmlStrndup(name, len); | 2612 cur->name = xmlStrndup(name, len); |
2568 } else | 2613 } else |
2569 cur->name = xmlStrdup(name); | 2614 cur->name = xmlStrdup(name); |
(...skipping 17 matching lines...) Expand all Loading... |
2587 | 2632 |
2588 /** | 2633 /** |
2589 * xmlNewDocText: | 2634 * xmlNewDocText: |
2590 * @doc: the document | 2635 * @doc: the document |
2591 * @content: the text content | 2636 * @content: the text content |
2592 * | 2637 * |
2593 * Creation of a new text node within a document. | 2638 * Creation of a new text node within a document. |
2594 * Returns a pointer to the new node object. | 2639 * Returns a pointer to the new node object. |
2595 */ | 2640 */ |
2596 xmlNodePtr | 2641 xmlNodePtr |
2597 xmlNewDocText(xmlDocPtr doc, const xmlChar *content) { | 2642 xmlNewDocText(const xmlDoc *doc, const xmlChar *content) { |
2598 xmlNodePtr cur; | 2643 xmlNodePtr cur; |
2599 | 2644 |
2600 cur = xmlNewText(content); | 2645 cur = xmlNewText(content); |
2601 if (cur != NULL) cur->doc = doc; | 2646 if (cur != NULL) cur->doc = (xmlDoc *)doc; |
2602 return(cur); | 2647 return(cur); |
2603 } | 2648 } |
2604 | 2649 |
2605 /** | 2650 /** |
2606 * xmlNewTextLen: | 2651 * xmlNewTextLen: |
2607 * @content: the text content | 2652 * @content: the text content |
2608 * @len: the text len. | 2653 * @len: the text len. |
2609 * | 2654 * |
2610 * Creation of a new text node with an extra parameter for the content's length | 2655 * Creation of a new text node with an extra parameter for the content's length |
2611 * Returns a pointer to the new node object. | 2656 * Returns a pointer to the new node object. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2741 * xmlSetTreeDoc: | 2786 * xmlSetTreeDoc: |
2742 * @tree: the top element | 2787 * @tree: the top element |
2743 * @doc: the document | 2788 * @doc: the document |
2744 * | 2789 * |
2745 * update all nodes under the tree to point to the right document | 2790 * update all nodes under the tree to point to the right document |
2746 */ | 2791 */ |
2747 void | 2792 void |
2748 xmlSetTreeDoc(xmlNodePtr tree, xmlDocPtr doc) { | 2793 xmlSetTreeDoc(xmlNodePtr tree, xmlDocPtr doc) { |
2749 xmlAttrPtr prop; | 2794 xmlAttrPtr prop; |
2750 | 2795 |
2751 if (tree == NULL) | 2796 if ((tree == NULL) || (tree->type == XML_NAMESPACE_DECL)) |
2752 return; | 2797 return; |
2753 if (tree->doc != doc) { | 2798 if (tree->doc != doc) { |
2754 if(tree->type == XML_ELEMENT_NODE) { | 2799 if(tree->type == XML_ELEMENT_NODE) { |
2755 prop = tree->properties; | 2800 prop = tree->properties; |
2756 while (prop != NULL) { | 2801 while (prop != NULL) { |
2757 prop->doc = doc; | 2802 prop->doc = doc; |
2758 xmlSetListDoc(prop->children, doc); | 2803 xmlSetListDoc(prop->children, doc); |
2759 prop = prop->next; | 2804 prop = prop->next; |
2760 } | 2805 } |
2761 } | 2806 } |
2762 if (tree->children != NULL) | 2807 if (tree->children != NULL) |
2763 xmlSetListDoc(tree->children, doc); | 2808 xmlSetListDoc(tree->children, doc); |
2764 tree->doc = doc; | 2809 tree->doc = doc; |
2765 } | 2810 } |
2766 } | 2811 } |
2767 | 2812 |
2768 /** | 2813 /** |
2769 * xmlSetListDoc: | 2814 * xmlSetListDoc: |
2770 * @list: the first element | 2815 * @list: the first element |
2771 * @doc: the document | 2816 * @doc: the document |
2772 * | 2817 * |
2773 * update all nodes in the list to point to the right document | 2818 * update all nodes in the list to point to the right document |
2774 */ | 2819 */ |
2775 void | 2820 void |
2776 xmlSetListDoc(xmlNodePtr list, xmlDocPtr doc) { | 2821 xmlSetListDoc(xmlNodePtr list, xmlDocPtr doc) { |
2777 xmlNodePtr cur; | 2822 xmlNodePtr cur; |
2778 | 2823 |
2779 if (list == NULL) | 2824 if ((list == NULL) || (list->type == XML_NAMESPACE_DECL)) |
2780 return; | 2825 return; |
2781 cur = list; | 2826 cur = list; |
2782 while (cur != NULL) { | 2827 while (cur != NULL) { |
2783 if (cur->doc != doc) | 2828 if (cur->doc != doc) |
2784 xmlSetTreeDoc(cur, doc); | 2829 xmlSetTreeDoc(cur, doc); |
2785 cur = cur->next; | 2830 cur = cur->next; |
2786 } | 2831 } |
2787 } | 2832 } |
2788 | 2833 |
2789 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) | 2834 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2876 * When inserting before @cur, @prev is passed as @cur->prev. | 2921 * When inserting before @cur, @prev is passed as @cur->prev. |
2877 * When inserting after @cur, @prev is passed as @cur. | 2922 * When inserting after @cur, @prev is passed as @cur. |
2878 * If an existing attribute is found it is detroyed prior to adding @prop. | 2923 * If an existing attribute is found it is detroyed prior to adding @prop. |
2879 * | 2924 * |
2880 * Returns the attribute being inserted or NULL in case of error. | 2925 * Returns the attribute being inserted or NULL in case of error. |
2881 */ | 2926 */ |
2882 static xmlNodePtr | 2927 static xmlNodePtr |
2883 xmlAddPropSibling(xmlNodePtr prev, xmlNodePtr cur, xmlNodePtr prop) { | 2928 xmlAddPropSibling(xmlNodePtr prev, xmlNodePtr cur, xmlNodePtr prop) { |
2884 xmlAttrPtr attr; | 2929 xmlAttrPtr attr; |
2885 | 2930 |
2886 » if (cur->type != XML_ATTRIBUTE_NODE) | 2931 » if ((cur == NULL) || (cur->type != XML_ATTRIBUTE_NODE) || |
| 2932 » (prop == NULL) || (prop->type != XML_ATTRIBUTE_NODE) || |
| 2933 » ((prev != NULL) && (prev->type != XML_ATTRIBUTE_NODE))) |
2887 return(NULL); | 2934 return(NULL); |
2888 | 2935 |
2889 /* check if an attribute with the same name exists */ | 2936 /* check if an attribute with the same name exists */ |
2890 if (prop->ns == NULL) | 2937 if (prop->ns == NULL) |
2891 attr = xmlHasNsProp(cur->parent, prop->name, NULL); | 2938 attr = xmlHasNsProp(cur->parent, prop->name, NULL); |
2892 else | 2939 else |
2893 attr = xmlHasNsProp(cur->parent, prop->name, prop->ns->href); | 2940 attr = xmlHasNsProp(cur->parent, prop->name, prop->ns->href); |
2894 | 2941 |
2895 if (prop->doc != cur->doc) { | 2942 if (prop->doc != cur->doc) { |
2896 xmlSetTreeDoc(prop, cur->doc); | 2943 xmlSetTreeDoc(prop, cur->doc); |
(...skipping 27 matching lines...) Expand all Loading... |
2924 * If the new node was already inserted in a document it is | 2971 * If the new node was already inserted in a document it is |
2925 * first unlinked from its existing context. | 2972 * first unlinked from its existing context. |
2926 * As a result of text merging @elem may be freed. | 2973 * As a result of text merging @elem may be freed. |
2927 * If the new node is ATTRIBUTE, it is added into properties instead of children
. | 2974 * If the new node is ATTRIBUTE, it is added into properties instead of children
. |
2928 * If there is an attribute with equal name, it is first destroyed. | 2975 * If there is an attribute with equal name, it is first destroyed. |
2929 * | 2976 * |
2930 * Returns the new node or NULL in case of error. | 2977 * Returns the new node or NULL in case of error. |
2931 */ | 2978 */ |
2932 xmlNodePtr | 2979 xmlNodePtr |
2933 xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) { | 2980 xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) { |
2934 if (cur == NULL) { | 2981 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { |
2935 #ifdef DEBUG_TREE | 2982 #ifdef DEBUG_TREE |
2936 xmlGenericError(xmlGenericErrorContext, | 2983 xmlGenericError(xmlGenericErrorContext, |
2937 "xmlAddNextSibling : cur == NULL\n"); | 2984 "xmlAddNextSibling : cur == NULL\n"); |
2938 #endif | 2985 #endif |
2939 return(NULL); | 2986 return(NULL); |
2940 } | 2987 } |
2941 if (elem == NULL) { | 2988 if ((elem == NULL) || (elem->type == XML_NAMESPACE_DECL)) { |
2942 #ifdef DEBUG_TREE | 2989 #ifdef DEBUG_TREE |
2943 xmlGenericError(xmlGenericErrorContext, | 2990 xmlGenericError(xmlGenericErrorContext, |
2944 "xmlAddNextSibling : elem == NULL\n"); | 2991 "xmlAddNextSibling : elem == NULL\n"); |
2945 #endif | 2992 #endif |
2946 return(NULL); | 2993 return(NULL); |
2947 } | 2994 } |
2948 | 2995 |
2949 if (cur == elem) { | 2996 if (cur == elem) { |
2950 #ifdef DEBUG_TREE | 2997 #ifdef DEBUG_TREE |
2951 xmlGenericError(xmlGenericErrorContext, | 2998 xmlGenericError(xmlGenericErrorContext, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2985 elem->next = cur->next; | 3032 elem->next = cur->next; |
2986 cur->next = elem; | 3033 cur->next = elem; |
2987 if (elem->next != NULL) | 3034 if (elem->next != NULL) |
2988 elem->next->prev = elem; | 3035 elem->next->prev = elem; |
2989 if ((elem->parent != NULL) && (elem->parent->last == cur)) | 3036 if ((elem->parent != NULL) && (elem->parent->last == cur)) |
2990 elem->parent->last = elem; | 3037 elem->parent->last = elem; |
2991 return(elem); | 3038 return(elem); |
2992 } | 3039 } |
2993 | 3040 |
2994 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_HTML_ENABLED) || \ | 3041 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_HTML_ENABLED) || \ |
2995 defined(LIBXML_SCHEMAS_ENABLED) | 3042 defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED) |
2996 /** | 3043 /** |
2997 * xmlAddPrevSibling: | 3044 * xmlAddPrevSibling: |
2998 * @cur: the child node | 3045 * @cur: the child node |
2999 * @elem: the new node | 3046 * @elem: the new node |
3000 * | 3047 * |
3001 * Add a new node @elem as the previous sibling of @cur | 3048 * Add a new node @elem as the previous sibling of @cur |
3002 * merging adjacent TEXT nodes (@elem may be freed) | 3049 * merging adjacent TEXT nodes (@elem may be freed) |
3003 * If the new node was already inserted in a document it is | 3050 * If the new node was already inserted in a document it is |
3004 * first unlinked from its existing context. | 3051 * first unlinked from its existing context. |
3005 * If the new node is ATTRIBUTE, it is added into properties instead of children
. | 3052 * If the new node is ATTRIBUTE, it is added into properties instead of children
. |
3006 * If there is an attribute with equal name, it is first destroyed. | 3053 * If there is an attribute with equal name, it is first destroyed. |
3007 * | 3054 * |
3008 * Returns the new node or NULL in case of error. | 3055 * Returns the new node or NULL in case of error. |
3009 */ | 3056 */ |
3010 xmlNodePtr | 3057 xmlNodePtr |
3011 xmlAddPrevSibling(xmlNodePtr cur, xmlNodePtr elem) { | 3058 xmlAddPrevSibling(xmlNodePtr cur, xmlNodePtr elem) { |
3012 if (cur == NULL) { | 3059 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { |
3013 #ifdef DEBUG_TREE | 3060 #ifdef DEBUG_TREE |
3014 xmlGenericError(xmlGenericErrorContext, | 3061 xmlGenericError(xmlGenericErrorContext, |
3015 "xmlAddPrevSibling : cur == NULL\n"); | 3062 "xmlAddPrevSibling : cur == NULL\n"); |
3016 #endif | 3063 #endif |
3017 return(NULL); | 3064 return(NULL); |
3018 } | 3065 } |
3019 if (elem == NULL) { | 3066 if ((elem == NULL) || (elem->type == XML_NAMESPACE_DECL)) { |
3020 #ifdef DEBUG_TREE | 3067 #ifdef DEBUG_TREE |
3021 xmlGenericError(xmlGenericErrorContext, | 3068 xmlGenericError(xmlGenericErrorContext, |
3022 "xmlAddPrevSibling : elem == NULL\n"); | 3069 "xmlAddPrevSibling : elem == NULL\n"); |
3023 #endif | 3070 #endif |
3024 return(NULL); | 3071 return(NULL); |
3025 } | 3072 } |
3026 | 3073 |
3027 if (cur == elem) { | 3074 if (cur == elem) { |
3028 #ifdef DEBUG_TREE | 3075 #ifdef DEBUG_TREE |
3029 xmlGenericError(xmlGenericErrorContext, | 3076 xmlGenericError(xmlGenericErrorContext, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3080 * merging adjacent TEXT nodes (@elem may be freed) | 3127 * merging adjacent TEXT nodes (@elem may be freed) |
3081 * If the new element was already inserted in a document it is | 3128 * If the new element was already inserted in a document it is |
3082 * first unlinked from its existing context. | 3129 * first unlinked from its existing context. |
3083 * | 3130 * |
3084 * Returns the new element or NULL in case of error. | 3131 * Returns the new element or NULL in case of error. |
3085 */ | 3132 */ |
3086 xmlNodePtr | 3133 xmlNodePtr |
3087 xmlAddSibling(xmlNodePtr cur, xmlNodePtr elem) { | 3134 xmlAddSibling(xmlNodePtr cur, xmlNodePtr elem) { |
3088 xmlNodePtr parent; | 3135 xmlNodePtr parent; |
3089 | 3136 |
3090 if (cur == NULL) { | 3137 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { |
3091 #ifdef DEBUG_TREE | 3138 #ifdef DEBUG_TREE |
3092 xmlGenericError(xmlGenericErrorContext, | 3139 xmlGenericError(xmlGenericErrorContext, |
3093 "xmlAddSibling : cur == NULL\n"); | 3140 "xmlAddSibling : cur == NULL\n"); |
3094 #endif | 3141 #endif |
3095 return(NULL); | 3142 return(NULL); |
3096 } | 3143 } |
3097 | 3144 |
3098 if (elem == NULL) { | 3145 if ((elem == NULL) || (elem->type == XML_NAMESPACE_DECL)) { |
3099 #ifdef DEBUG_TREE | 3146 #ifdef DEBUG_TREE |
3100 xmlGenericError(xmlGenericErrorContext, | 3147 xmlGenericError(xmlGenericErrorContext, |
3101 "xmlAddSibling : elem == NULL\n"); | 3148 "xmlAddSibling : elem == NULL\n"); |
3102 #endif | 3149 #endif |
3103 return(NULL); | 3150 return(NULL); |
3104 } | 3151 } |
3105 | 3152 |
3106 if (cur == elem) { | 3153 if (cur == elem) { |
3107 #ifdef DEBUG_TREE | 3154 #ifdef DEBUG_TREE |
3108 xmlGenericError(xmlGenericErrorContext, | 3155 xmlGenericError(xmlGenericErrorContext, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3156 * | 3203 * |
3157 * Add a list of node at the end of the child list of the parent | 3204 * Add a list of node at the end of the child list of the parent |
3158 * merging adjacent TEXT nodes (@cur may be freed) | 3205 * merging adjacent TEXT nodes (@cur may be freed) |
3159 * | 3206 * |
3160 * Returns the last child or NULL in case of error. | 3207 * Returns the last child or NULL in case of error. |
3161 */ | 3208 */ |
3162 xmlNodePtr | 3209 xmlNodePtr |
3163 xmlAddChildList(xmlNodePtr parent, xmlNodePtr cur) { | 3210 xmlAddChildList(xmlNodePtr parent, xmlNodePtr cur) { |
3164 xmlNodePtr prev; | 3211 xmlNodePtr prev; |
3165 | 3212 |
3166 if (parent == NULL) { | 3213 if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) { |
3167 #ifdef DEBUG_TREE | 3214 #ifdef DEBUG_TREE |
3168 xmlGenericError(xmlGenericErrorContext, | 3215 xmlGenericError(xmlGenericErrorContext, |
3169 "xmlAddChildList : parent == NULL\n"); | 3216 "xmlAddChildList : parent == NULL\n"); |
3170 #endif | 3217 #endif |
3171 return(NULL); | 3218 return(NULL); |
3172 } | 3219 } |
3173 | 3220 |
3174 if (cur == NULL) { | 3221 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { |
3175 #ifdef DEBUG_TREE | 3222 #ifdef DEBUG_TREE |
3176 xmlGenericError(xmlGenericErrorContext, | 3223 xmlGenericError(xmlGenericErrorContext, |
3177 "xmlAddChildList : child == NULL\n"); | 3224 "xmlAddChildList : child == NULL\n"); |
3178 #endif | 3225 #endif |
3179 return(NULL); | 3226 return(NULL); |
3180 } | 3227 } |
3181 | 3228 |
3182 if ((cur->doc != NULL) && (parent->doc != NULL) && | 3229 if ((cur->doc != NULL) && (parent->doc != NULL) && |
3183 (cur->doc != parent->doc)) { | 3230 (cur->doc != parent->doc)) { |
3184 #ifdef DEBUG_TREE | 3231 #ifdef DEBUG_TREE |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3242 * merging adjacent TEXT nodes (in which case @cur is freed) | 3289 * merging adjacent TEXT nodes (in which case @cur is freed) |
3243 * If the new node is ATTRIBUTE, it is added into properties instead of children
. | 3290 * If the new node is ATTRIBUTE, it is added into properties instead of children
. |
3244 * If there is an attribute with equal name, it is first destroyed. | 3291 * If there is an attribute with equal name, it is first destroyed. |
3245 * | 3292 * |
3246 * Returns the child or NULL in case of error. | 3293 * Returns the child or NULL in case of error. |
3247 */ | 3294 */ |
3248 xmlNodePtr | 3295 xmlNodePtr |
3249 xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { | 3296 xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { |
3250 xmlNodePtr prev; | 3297 xmlNodePtr prev; |
3251 | 3298 |
3252 if (parent == NULL) { | 3299 if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) { |
3253 #ifdef DEBUG_TREE | 3300 #ifdef DEBUG_TREE |
3254 xmlGenericError(xmlGenericErrorContext, | 3301 xmlGenericError(xmlGenericErrorContext, |
3255 "xmlAddChild : parent == NULL\n"); | 3302 "xmlAddChild : parent == NULL\n"); |
3256 #endif | 3303 #endif |
3257 return(NULL); | 3304 return(NULL); |
3258 } | 3305 } |
3259 | 3306 |
3260 if (cur == NULL) { | 3307 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { |
3261 #ifdef DEBUG_TREE | 3308 #ifdef DEBUG_TREE |
3262 xmlGenericError(xmlGenericErrorContext, | 3309 xmlGenericError(xmlGenericErrorContext, |
3263 "xmlAddChild : child == NULL\n"); | 3310 "xmlAddChild : child == NULL\n"); |
3264 #endif | 3311 #endif |
3265 return(NULL); | 3312 return(NULL); |
3266 } | 3313 } |
3267 | 3314 |
3268 if (parent == cur) { | 3315 if (parent == cur) { |
3269 #ifdef DEBUG_TREE | 3316 #ifdef DEBUG_TREE |
3270 xmlGenericError(xmlGenericErrorContext, | 3317 xmlGenericError(xmlGenericErrorContext, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3363 } | 3410 } |
3364 | 3411 |
3365 /** | 3412 /** |
3366 * xmlGetLastChild: | 3413 * xmlGetLastChild: |
3367 * @parent: the parent node | 3414 * @parent: the parent node |
3368 * | 3415 * |
3369 * Search the last child of a node. | 3416 * Search the last child of a node. |
3370 * Returns the last child or NULL if none. | 3417 * Returns the last child or NULL if none. |
3371 */ | 3418 */ |
3372 xmlNodePtr | 3419 xmlNodePtr |
3373 xmlGetLastChild(xmlNodePtr parent) { | 3420 xmlGetLastChild(const xmlNode *parent) { |
3374 if (parent == NULL) { | 3421 if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) { |
3375 #ifdef DEBUG_TREE | 3422 #ifdef DEBUG_TREE |
3376 xmlGenericError(xmlGenericErrorContext, | 3423 xmlGenericError(xmlGenericErrorContext, |
3377 "xmlGetLastChild : parent == NULL\n"); | 3424 "xmlGetLastChild : parent == NULL\n"); |
3378 #endif | 3425 #endif |
3379 return(NULL); | 3426 return(NULL); |
3380 } | 3427 } |
3381 return(parent->last); | 3428 return(parent->last); |
3382 } | 3429 } |
3383 | 3430 |
3384 #ifdef LIBXML_TREE_ENABLED | 3431 #ifdef LIBXML_TREE_ENABLED |
(...skipping 17 matching lines...) Expand all Loading... |
3402 xmlChildElementCount(xmlNodePtr parent) { | 3449 xmlChildElementCount(xmlNodePtr parent) { |
3403 unsigned long ret = 0; | 3450 unsigned long ret = 0; |
3404 xmlNodePtr cur = NULL; | 3451 xmlNodePtr cur = NULL; |
3405 | 3452 |
3406 if (parent == NULL) | 3453 if (parent == NULL) |
3407 return(0); | 3454 return(0); |
3408 switch (parent->type) { | 3455 switch (parent->type) { |
3409 case XML_ELEMENT_NODE: | 3456 case XML_ELEMENT_NODE: |
3410 case XML_ENTITY_NODE: | 3457 case XML_ENTITY_NODE: |
3411 case XML_DOCUMENT_NODE: | 3458 case XML_DOCUMENT_NODE: |
| 3459 case XML_DOCUMENT_FRAG_NODE: |
3412 case XML_HTML_DOCUMENT_NODE: | 3460 case XML_HTML_DOCUMENT_NODE: |
3413 cur = parent->children; | 3461 cur = parent->children; |
3414 break; | 3462 break; |
3415 default: | 3463 default: |
3416 return(0); | 3464 return(0); |
3417 } | 3465 } |
3418 while (cur != NULL) { | 3466 while (cur != NULL) { |
3419 if (cur->type == XML_ELEMENT_NODE) | 3467 if (cur->type == XML_ELEMENT_NODE) |
3420 ret++; | 3468 ret++; |
3421 cur = cur->next; | 3469 cur = cur->next; |
(...skipping 15 matching lines...) Expand all Loading... |
3437 xmlNodePtr | 3485 xmlNodePtr |
3438 xmlFirstElementChild(xmlNodePtr parent) { | 3486 xmlFirstElementChild(xmlNodePtr parent) { |
3439 xmlNodePtr cur = NULL; | 3487 xmlNodePtr cur = NULL; |
3440 | 3488 |
3441 if (parent == NULL) | 3489 if (parent == NULL) |
3442 return(NULL); | 3490 return(NULL); |
3443 switch (parent->type) { | 3491 switch (parent->type) { |
3444 case XML_ELEMENT_NODE: | 3492 case XML_ELEMENT_NODE: |
3445 case XML_ENTITY_NODE: | 3493 case XML_ENTITY_NODE: |
3446 case XML_DOCUMENT_NODE: | 3494 case XML_DOCUMENT_NODE: |
| 3495 case XML_DOCUMENT_FRAG_NODE: |
3447 case XML_HTML_DOCUMENT_NODE: | 3496 case XML_HTML_DOCUMENT_NODE: |
3448 cur = parent->children; | 3497 cur = parent->children; |
3449 break; | 3498 break; |
3450 default: | 3499 default: |
3451 return(NULL); | 3500 return(NULL); |
3452 } | 3501 } |
3453 while (cur != NULL) { | 3502 while (cur != NULL) { |
3454 if (cur->type == XML_ELEMENT_NODE) | 3503 if (cur->type == XML_ELEMENT_NODE) |
3455 return(cur); | 3504 return(cur); |
3456 cur = cur->next; | 3505 cur = cur->next; |
(...skipping 15 matching lines...) Expand all Loading... |
3472 xmlNodePtr | 3521 xmlNodePtr |
3473 xmlLastElementChild(xmlNodePtr parent) { | 3522 xmlLastElementChild(xmlNodePtr parent) { |
3474 xmlNodePtr cur = NULL; | 3523 xmlNodePtr cur = NULL; |
3475 | 3524 |
3476 if (parent == NULL) | 3525 if (parent == NULL) |
3477 return(NULL); | 3526 return(NULL); |
3478 switch (parent->type) { | 3527 switch (parent->type) { |
3479 case XML_ELEMENT_NODE: | 3528 case XML_ELEMENT_NODE: |
3480 case XML_ENTITY_NODE: | 3529 case XML_ENTITY_NODE: |
3481 case XML_DOCUMENT_NODE: | 3530 case XML_DOCUMENT_NODE: |
| 3531 case XML_DOCUMENT_FRAG_NODE: |
3482 case XML_HTML_DOCUMENT_NODE: | 3532 case XML_HTML_DOCUMENT_NODE: |
3483 cur = parent->last; | 3533 cur = parent->last; |
3484 break; | 3534 break; |
3485 default: | 3535 default: |
3486 return(NULL); | 3536 return(NULL); |
3487 } | 3537 } |
3488 while (cur != NULL) { | 3538 while (cur != NULL) { |
3489 if (cur->type == XML_ELEMENT_NODE) | 3539 if (cur->type == XML_ELEMENT_NODE) |
3490 return(cur); | 3540 return(cur); |
3491 cur = cur->prev; | 3541 cur = cur->prev; |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3714 (cur->nsDef != NULL)) | 3764 (cur->nsDef != NULL)) |
3715 xmlFreeNsList(cur->nsDef); | 3765 xmlFreeNsList(cur->nsDef); |
3716 xmlFree(cur); | 3766 xmlFree(cur); |
3717 } | 3767 } |
3718 | 3768 |
3719 /** | 3769 /** |
3720 * xmlUnlinkNode: | 3770 * xmlUnlinkNode: |
3721 * @cur: the node | 3771 * @cur: the node |
3722 * | 3772 * |
3723 * Unlink a node from it's current context, the node is not freed | 3773 * Unlink a node from it's current context, the node is not freed |
| 3774 * If one need to free the node, use xmlFreeNode() routine after the |
| 3775 * unlink to discard it. |
| 3776 * Note that namespace nodes can't be unlinked as they do not have |
| 3777 * pointer to their parent. |
3724 */ | 3778 */ |
3725 void | 3779 void |
3726 xmlUnlinkNode(xmlNodePtr cur) { | 3780 xmlUnlinkNode(xmlNodePtr cur) { |
3727 if (cur == NULL) { | 3781 if (cur == NULL) { |
3728 #ifdef DEBUG_TREE | 3782 #ifdef DEBUG_TREE |
3729 xmlGenericError(xmlGenericErrorContext, | 3783 xmlGenericError(xmlGenericErrorContext, |
3730 "xmlUnlinkNode : node == NULL\n"); | 3784 "xmlUnlinkNode : node == NULL\n"); |
3731 #endif | 3785 #endif |
3732 return; | 3786 return; |
3733 } | 3787 } |
| 3788 if (cur->type == XML_NAMESPACE_DECL) |
| 3789 return; |
3734 if (cur->type == XML_DTD_NODE) { | 3790 if (cur->type == XML_DTD_NODE) { |
3735 xmlDocPtr doc; | 3791 xmlDocPtr doc; |
3736 doc = cur->doc; | 3792 doc = cur->doc; |
3737 if (doc != NULL) { | 3793 if (doc != NULL) { |
3738 if (doc->intSubset == (xmlDtdPtr) cur) | 3794 if (doc->intSubset == (xmlDtdPtr) cur) |
3739 doc->intSubset = NULL; | 3795 doc->intSubset = NULL; |
3740 if (doc->extSubset == (xmlDtdPtr) cur) | 3796 if (doc->extSubset == (xmlDtdPtr) cur) |
3741 doc->extSubset = NULL; | 3797 doc->extSubset = NULL; |
3742 } | 3798 } |
3743 } | 3799 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3792 * | 3848 * |
3793 * Unlink the old node from its current context, prune the new one | 3849 * Unlink the old node from its current context, prune the new one |
3794 * at the same place. If @cur was already inserted in a document it is | 3850 * at the same place. If @cur was already inserted in a document it is |
3795 * first unlinked from its existing context. | 3851 * first unlinked from its existing context. |
3796 * | 3852 * |
3797 * Returns the @old node | 3853 * Returns the @old node |
3798 */ | 3854 */ |
3799 xmlNodePtr | 3855 xmlNodePtr |
3800 xmlReplaceNode(xmlNodePtr old, xmlNodePtr cur) { | 3856 xmlReplaceNode(xmlNodePtr old, xmlNodePtr cur) { |
3801 if (old == cur) return(NULL); | 3857 if (old == cur) return(NULL); |
3802 if ((old == NULL) || (old->parent == NULL)) { | 3858 if ((old == NULL) || (old->type == XML_NAMESPACE_DECL) || |
| 3859 (old->parent == NULL)) { |
3803 #ifdef DEBUG_TREE | 3860 #ifdef DEBUG_TREE |
3804 xmlGenericError(xmlGenericErrorContext, | 3861 xmlGenericError(xmlGenericErrorContext, |
3805 "xmlReplaceNode : old == NULL or without parent\n"); | 3862 "xmlReplaceNode : old == NULL or without parent\n"); |
3806 #endif | 3863 #endif |
3807 return(NULL); | 3864 return(NULL); |
3808 } | 3865 } |
3809 if (cur == NULL) { | 3866 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { |
3810 xmlUnlinkNode(old); | 3867 xmlUnlinkNode(old); |
3811 return(old); | 3868 return(old); |
3812 } | 3869 } |
3813 if (cur == old) { | 3870 if (cur == old) { |
3814 return(old); | 3871 return(old); |
3815 } | 3872 } |
3816 if ((old->type==XML_ATTRIBUTE_NODE) && (cur->type!=XML_ATTRIBUTE_NODE)) { | 3873 if ((old->type==XML_ATTRIBUTE_NODE) && (cur->type!=XML_ATTRIBUTE_NODE)) { |
3817 #ifdef DEBUG_TREE | 3874 #ifdef DEBUG_TREE |
3818 xmlGenericError(xmlGenericErrorContext, | 3875 xmlGenericError(xmlGenericErrorContext, |
3819 "xmlReplaceNode : Trying to replace attribute node with other no
de type\n"); | 3876 "xmlReplaceNode : Trying to replace attribute node with other no
de type\n"); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3913 } | 3970 } |
3914 | 3971 |
3915 static xmlNodePtr | 3972 static xmlNodePtr |
3916 xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent); | 3973 xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent); |
3917 | 3974 |
3918 static xmlAttrPtr | 3975 static xmlAttrPtr |
3919 xmlCopyPropInternal(xmlDocPtr doc, xmlNodePtr target, xmlAttrPtr cur) { | 3976 xmlCopyPropInternal(xmlDocPtr doc, xmlNodePtr target, xmlAttrPtr cur) { |
3920 xmlAttrPtr ret; | 3977 xmlAttrPtr ret; |
3921 | 3978 |
3922 if (cur == NULL) return(NULL); | 3979 if (cur == NULL) return(NULL); |
| 3980 if ((target != NULL) && (target->type != XML_ELEMENT_NODE)) |
| 3981 return(NULL); |
3923 if (target != NULL) | 3982 if (target != NULL) |
3924 ret = xmlNewDocProp(target->doc, cur->name, NULL); | 3983 ret = xmlNewDocProp(target->doc, cur->name, NULL); |
3925 else if (doc != NULL) | 3984 else if (doc != NULL) |
3926 ret = xmlNewDocProp(doc, cur->name, NULL); | 3985 ret = xmlNewDocProp(doc, cur->name, NULL); |
3927 else if (cur->parent != NULL) | 3986 else if (cur->parent != NULL) |
3928 ret = xmlNewDocProp(cur->parent->doc, cur->name, NULL); | 3987 ret = xmlNewDocProp(cur->parent->doc, cur->name, NULL); |
3929 else if (cur->children != NULL) | 3988 else if (cur->children != NULL) |
3930 ret = xmlNewDocProp(cur->children->doc, cur->name, NULL); | 3989 ret = xmlNewDocProp(cur->children->doc, cur->name, NULL); |
3931 else | 3990 else |
3932 ret = xmlNewDocProp(NULL, cur->name, NULL); | 3991 ret = xmlNewDocProp(NULL, cur->name, NULL); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4032 * | 4091 * |
4033 * Do a copy of an attribute list. | 4092 * Do a copy of an attribute list. |
4034 * | 4093 * |
4035 * Returns: a new #xmlAttrPtr, or NULL in case of error. | 4094 * Returns: a new #xmlAttrPtr, or NULL in case of error. |
4036 */ | 4095 */ |
4037 xmlAttrPtr | 4096 xmlAttrPtr |
4038 xmlCopyPropList(xmlNodePtr target, xmlAttrPtr cur) { | 4097 xmlCopyPropList(xmlNodePtr target, xmlAttrPtr cur) { |
4039 xmlAttrPtr ret = NULL; | 4098 xmlAttrPtr ret = NULL; |
4040 xmlAttrPtr p = NULL,q; | 4099 xmlAttrPtr p = NULL,q; |
4041 | 4100 |
| 4101 if ((target != NULL) && (target->type != XML_ELEMENT_NODE)) |
| 4102 return(NULL); |
4042 while (cur != NULL) { | 4103 while (cur != NULL) { |
4043 q = xmlCopyProp(target, cur); | 4104 q = xmlCopyProp(target, cur); |
4044 if (q == NULL) | 4105 if (q == NULL) |
4045 return(NULL); | 4106 return(NULL); |
4046 if (p == NULL) { | 4107 if (p == NULL) { |
4047 ret = p = q; | 4108 ret = p = q; |
4048 } else { | 4109 } else { |
4049 p->next = q; | 4110 p->next = q; |
4050 q->prev = p; | 4111 q->prev = p; |
4051 p = q; | 4112 p = q; |
(...skipping 16 matching lines...) Expand all Loading... |
4068 * a copy of the namespace at the top of the copied tree if | 4129 * a copy of the namespace at the top of the copied tree if |
4069 * not available in the subtree. | 4130 * not available in the subtree. |
4070 * Hence two functions, the public front-end call the inner ones | 4131 * Hence two functions, the public front-end call the inner ones |
4071 * The argument "recursive" normally indicates a recursive copy | 4132 * The argument "recursive" normally indicates a recursive copy |
4072 * of the node with values 0 (no) and 1 (yes). For XInclude, | 4133 * of the node with values 0 (no) and 1 (yes). For XInclude, |
4073 * however, we allow a value of 2 to indicate copy properties and | 4134 * however, we allow a value of 2 to indicate copy properties and |
4074 * namespace info, but don't recurse on children. | 4135 * namespace info, but don't recurse on children. |
4075 */ | 4136 */ |
4076 | 4137 |
4077 static xmlNodePtr | 4138 static xmlNodePtr |
4078 xmlStaticCopyNode(const xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, | 4139 xmlStaticCopyNode(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, |
4079 int extended) { | 4140 int extended) { |
4080 xmlNodePtr ret; | 4141 xmlNodePtr ret; |
4081 | 4142 |
4082 if (node == NULL) return(NULL); | 4143 if (node == NULL) return(NULL); |
4083 switch (node->type) { | 4144 switch (node->type) { |
4084 case XML_TEXT_NODE: | 4145 case XML_TEXT_NODE: |
4085 case XML_CDATA_SECTION_NODE: | 4146 case XML_CDATA_SECTION_NODE: |
4086 case XML_ELEMENT_NODE: | 4147 case XML_ELEMENT_NODE: |
4087 case XML_DOCUMENT_FRAG_NODE: | 4148 case XML_DOCUMENT_FRAG_NODE: |
4088 case XML_ENTITY_REF_NODE: | 4149 case XML_ENTITY_REF_NODE: |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4234 | 4295 |
4235 while (node != NULL) { | 4296 while (node != NULL) { |
4236 #ifdef LIBXML_TREE_ENABLED | 4297 #ifdef LIBXML_TREE_ENABLED |
4237 if (node->type == XML_DTD_NODE ) { | 4298 if (node->type == XML_DTD_NODE ) { |
4238 if (doc == NULL) { | 4299 if (doc == NULL) { |
4239 node = node->next; | 4300 node = node->next; |
4240 continue; | 4301 continue; |
4241 } | 4302 } |
4242 if (doc->intSubset == NULL) { | 4303 if (doc->intSubset == NULL) { |
4243 q = (xmlNodePtr) xmlCopyDtd( (xmlDtdPtr) node ); | 4304 q = (xmlNodePtr) xmlCopyDtd( (xmlDtdPtr) node ); |
| 4305 if (q == NULL) return(NULL); |
4244 q->doc = doc; | 4306 q->doc = doc; |
4245 q->parent = parent; | 4307 q->parent = parent; |
4246 doc->intSubset = (xmlDtdPtr) q; | 4308 doc->intSubset = (xmlDtdPtr) q; |
4247 xmlAddChild(parent, q); | 4309 xmlAddChild(parent, q); |
4248 } else { | 4310 } else { |
4249 q = (xmlNodePtr) doc->intSubset; | 4311 q = (xmlNodePtr) doc->intSubset; |
4250 xmlAddChild(parent, q); | 4312 xmlAddChild(parent, q); |
4251 } | 4313 } |
4252 } else | 4314 } else |
4253 #endif /* LIBXML_TREE_ENABLED */ | 4315 #endif /* LIBXML_TREE_ENABLED */ |
4254 q = xmlStaticCopyNode(node, doc, parent, 1); | 4316 q = xmlStaticCopyNode(node, doc, parent, 1); |
| 4317 if (q == NULL) return(NULL); |
4255 if (ret == NULL) { | 4318 if (ret == NULL) { |
4256 q->prev = NULL; | 4319 q->prev = NULL; |
4257 ret = p = q; | 4320 ret = p = q; |
4258 } else if (p != q) { | 4321 } else if (p != q) { |
4259 /* the test is required if xmlStaticCopyNode coalesced 2 text nodes */ | 4322 /* the test is required if xmlStaticCopyNode coalesced 2 text nodes */ |
4260 p->next = q; | 4323 p->next = q; |
4261 q->prev = p; | 4324 q->prev = p; |
4262 p = q; | 4325 p = q; |
4263 } | 4326 } |
4264 node = node->next; | 4327 node = node->next; |
4265 } | 4328 } |
4266 return(ret); | 4329 return(ret); |
4267 } | 4330 } |
4268 | 4331 |
4269 /** | 4332 /** |
4270 * xmlCopyNode: | 4333 * xmlCopyNode: |
4271 * @node: the node | 4334 * @node: the node |
4272 * @extended: if 1 do a recursive copy (properties, namespaces and children | 4335 * @extended: if 1 do a recursive copy (properties, namespaces and children |
4273 * when applicable) | 4336 * when applicable) |
4274 * if 2 copy properties and namespaces (when applicable) | 4337 * if 2 copy properties and namespaces (when applicable) |
4275 * | 4338 * |
4276 * Do a copy of the node. | 4339 * Do a copy of the node. |
4277 * | 4340 * |
4278 * Returns: a new #xmlNodePtr, or NULL in case of error. | 4341 * Returns: a new #xmlNodePtr, or NULL in case of error. |
4279 */ | 4342 */ |
4280 xmlNodePtr | 4343 xmlNodePtr |
4281 xmlCopyNode(const xmlNodePtr node, int extended) { | 4344 xmlCopyNode(xmlNodePtr node, int extended) { |
4282 xmlNodePtr ret; | 4345 xmlNodePtr ret; |
4283 | 4346 |
4284 ret = xmlStaticCopyNode(node, NULL, NULL, extended); | 4347 ret = xmlStaticCopyNode(node, NULL, NULL, extended); |
4285 return(ret); | 4348 return(ret); |
4286 } | 4349 } |
4287 | 4350 |
4288 /** | 4351 /** |
4289 * xmlDocCopyNode: | 4352 * xmlDocCopyNode: |
4290 * @node: the node | 4353 * @node: the node |
4291 * @doc: the document | 4354 * @doc: the document |
4292 * @extended: if 1 do a recursive copy (properties, namespaces and children | 4355 * @extended: if 1 do a recursive copy (properties, namespaces and children |
4293 * when applicable) | 4356 * when applicable) |
4294 * if 2 copy properties and namespaces (when applicable) | 4357 * if 2 copy properties and namespaces (when applicable) |
4295 * | 4358 * |
4296 * Do a copy of the node to a given document. | 4359 * Do a copy of the node to a given document. |
4297 * | 4360 * |
4298 * Returns: a new #xmlNodePtr, or NULL in case of error. | 4361 * Returns: a new #xmlNodePtr, or NULL in case of error. |
4299 */ | 4362 */ |
4300 xmlNodePtr | 4363 xmlNodePtr |
4301 xmlDocCopyNode(const xmlNodePtr node, xmlDocPtr doc, int extended) { | 4364 xmlDocCopyNode(xmlNodePtr node, xmlDocPtr doc, int extended) { |
4302 xmlNodePtr ret; | 4365 xmlNodePtr ret; |
4303 | 4366 |
4304 ret = xmlStaticCopyNode(node, doc, NULL, extended); | 4367 ret = xmlStaticCopyNode(node, doc, NULL, extended); |
4305 return(ret); | 4368 return(ret); |
4306 } | 4369 } |
4307 | 4370 |
4308 /** | 4371 /** |
4309 * xmlDocCopyNodeList: | 4372 * xmlDocCopyNodeList: |
4310 * @doc: the target document | 4373 * @doc: the target document |
4311 * @node: the first node in the list. | 4374 * @node: the first node in the list. |
4312 * | 4375 * |
4313 * Do a recursive copy of the node list. | 4376 * Do a recursive copy of the node list. |
4314 * | 4377 * |
4315 * Returns: a new #xmlNodePtr, or NULL in case of error. | 4378 * Returns: a new #xmlNodePtr, or NULL in case of error. |
4316 */ | 4379 */ |
4317 xmlNodePtr xmlDocCopyNodeList(xmlDocPtr doc, const xmlNodePtr node) { | 4380 xmlNodePtr xmlDocCopyNodeList(xmlDocPtr doc, xmlNodePtr node) { |
4318 xmlNodePtr ret = xmlStaticCopyNodeList(node, doc, NULL); | 4381 xmlNodePtr ret = xmlStaticCopyNodeList(node, doc, NULL); |
4319 return(ret); | 4382 return(ret); |
4320 } | 4383 } |
4321 | 4384 |
4322 /** | 4385 /** |
4323 * xmlCopyNodeList: | 4386 * xmlCopyNodeList: |
4324 * @node: the first node in the list. | 4387 * @node: the first node in the list. |
4325 * | 4388 * |
4326 * Do a recursive copy of the node list. | 4389 * Do a recursive copy of the node list. |
4327 * Use xmlDocCopyNodeList() if possible to ensure string interning. | 4390 * Use xmlDocCopyNodeList() if possible to ensure string interning. |
4328 * | 4391 * |
4329 * Returns: a new #xmlNodePtr, or NULL in case of error. | 4392 * Returns: a new #xmlNodePtr, or NULL in case of error. |
4330 */ | 4393 */ |
4331 xmlNodePtr xmlCopyNodeList(const xmlNodePtr node) { | 4394 xmlNodePtr xmlCopyNodeList(xmlNodePtr node) { |
4332 xmlNodePtr ret = xmlStaticCopyNodeList(node, NULL, NULL); | 4395 xmlNodePtr ret = xmlStaticCopyNodeList(node, NULL, NULL); |
4333 return(ret); | 4396 return(ret); |
4334 } | 4397 } |
4335 | 4398 |
4336 #if defined(LIBXML_TREE_ENABLED) | 4399 #if defined(LIBXML_TREE_ENABLED) |
4337 /** | 4400 /** |
4338 * xmlCopyDtd: | 4401 * xmlCopyDtd: |
4339 * @dtd: the dtd | 4402 * @dtd: the dtd |
4340 * | 4403 * |
4341 * Do a copy of the dtd. | 4404 * Do a copy of the dtd. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4447 ret->charset = doc->charset; | 4510 ret->charset = doc->charset; |
4448 ret->compression = doc->compression; | 4511 ret->compression = doc->compression; |
4449 ret->standalone = doc->standalone; | 4512 ret->standalone = doc->standalone; |
4450 if (!recursive) return(ret); | 4513 if (!recursive) return(ret); |
4451 | 4514 |
4452 ret->last = NULL; | 4515 ret->last = NULL; |
4453 ret->children = NULL; | 4516 ret->children = NULL; |
4454 #ifdef LIBXML_TREE_ENABLED | 4517 #ifdef LIBXML_TREE_ENABLED |
4455 if (doc->intSubset != NULL) { | 4518 if (doc->intSubset != NULL) { |
4456 ret->intSubset = xmlCopyDtd(doc->intSubset); | 4519 ret->intSubset = xmlCopyDtd(doc->intSubset); |
| 4520 if (ret->intSubset == NULL) { |
| 4521 xmlFreeDoc(ret); |
| 4522 return(NULL); |
| 4523 } |
4457 xmlSetTreeDoc((xmlNodePtr)ret->intSubset, ret); | 4524 xmlSetTreeDoc((xmlNodePtr)ret->intSubset, ret); |
4458 ret->intSubset->parent = ret; | 4525 ret->intSubset->parent = ret; |
4459 } | 4526 } |
4460 #endif | 4527 #endif |
4461 if (doc->oldNs != NULL) | 4528 if (doc->oldNs != NULL) |
4462 ret->oldNs = xmlCopyNamespaceList(doc->oldNs); | 4529 ret->oldNs = xmlCopyNamespaceList(doc->oldNs); |
4463 if (doc->children != NULL) { | 4530 if (doc->children != NULL) { |
4464 xmlNodePtr tmp; | 4531 xmlNodePtr tmp; |
4465 | 4532 |
4466 ret->children = xmlStaticCopyNodeList(doc->children, ret, | 4533 ret->children = xmlStaticCopyNodeList(doc->children, ret, |
(...skipping 10 matching lines...) Expand all Loading... |
4477 } | 4544 } |
4478 #endif /* LIBXML_TREE_ENABLED */ | 4545 #endif /* LIBXML_TREE_ENABLED */ |
4479 | 4546 |
4480 /************************************************************************ | 4547 /************************************************************************ |
4481 * * | 4548 * * |
4482 * Content access functions * | 4549 * Content access functions * |
4483 * * | 4550 * * |
4484 ************************************************************************/ | 4551 ************************************************************************/ |
4485 | 4552 |
4486 /** | 4553 /** |
4487 * xmlGetLineNo: | 4554 * xmlGetLineNoInternal: |
4488 * @node: valid node | 4555 * @node: valid node |
| 4556 * @depth: used to limit any risk of recursion |
4489 * | 4557 * |
4490 * Get line number of @node. This requires activation of this option | 4558 * Get line number of @node. |
4491 * before invoking the parser by calling xmlLineNumbersDefault(1) | 4559 * Try to override the limitation of lines being store in 16 bits ints |
4492 * | 4560 * |
4493 * Returns the line number if successful, -1 otherwise | 4561 * Returns the line number if successful, -1 otherwise |
4494 */ | 4562 */ |
4495 long | 4563 static long |
4496 xmlGetLineNo(xmlNodePtr node) | 4564 xmlGetLineNoInternal(const xmlNode *node, int depth) |
4497 { | 4565 { |
4498 long result = -1; | 4566 long result = -1; |
4499 | 4567 |
| 4568 if (depth >= 5) |
| 4569 return(-1); |
| 4570 |
4500 if (!node) | 4571 if (!node) |
4501 return result; | 4572 return result; |
4502 if ((node->type == XML_ELEMENT_NODE) || | 4573 if ((node->type == XML_ELEMENT_NODE) || |
4503 (node->type == XML_TEXT_NODE) || | 4574 (node->type == XML_TEXT_NODE) || |
4504 (node->type == XML_COMMENT_NODE) || | 4575 (node->type == XML_COMMENT_NODE) || |
4505 » (node->type == XML_PI_NODE)) | 4576 » (node->type == XML_PI_NODE)) { |
4506 result = (long) node->line; | 4577 » if (node->line == 65535) { |
4507 else if ((node->prev != NULL) && | 4578 » if ((node->type == XML_TEXT_NODE) && (node->psvi != NULL)) |
| 4579 » result = (long) node->psvi; |
| 4580 » else if ((node->type == XML_ELEMENT_NODE) && |
| 4581 » (node->children != NULL)) |
| 4582 » result = xmlGetLineNoInternal(node->children, depth + 1); |
| 4583 » else if (node->next != NULL) |
| 4584 » result = xmlGetLineNoInternal(node->next, depth + 1); |
| 4585 » else if (node->prev != NULL) |
| 4586 » result = xmlGetLineNoInternal(node->prev, depth + 1); |
| 4587 » } |
| 4588 » if ((result == -1) || (result == 65535)) |
| 4589 » result = (long) node->line; |
| 4590 } else if ((node->prev != NULL) && |
4508 ((node->prev->type == XML_ELEMENT_NODE) || | 4591 ((node->prev->type == XML_ELEMENT_NODE) || |
4509 (node->prev->type == XML_TEXT_NODE) || | 4592 (node->prev->type == XML_TEXT_NODE) || |
4510 (node->prev->type == XML_COMMENT_NODE) || | 4593 (node->prev->type == XML_COMMENT_NODE) || |
4511 (node->prev->type == XML_PI_NODE))) | 4594 (node->prev->type == XML_PI_NODE))) |
4512 result = xmlGetLineNo(node->prev); | 4595 result = xmlGetLineNoInternal(node->prev, depth + 1); |
4513 else if ((node->parent != NULL) && | 4596 else if ((node->parent != NULL) && |
4514 (node->parent->type == XML_ELEMENT_NODE)) | 4597 (node->parent->type == XML_ELEMENT_NODE)) |
4515 result = xmlGetLineNo(node->parent); | 4598 result = xmlGetLineNoInternal(node->parent, depth + 1); |
4516 | 4599 |
4517 return result; | 4600 return result; |
4518 } | 4601 } |
4519 | 4602 |
| 4603 /** |
| 4604 * xmlGetLineNo: |
| 4605 * @node: valid node |
| 4606 * |
| 4607 * Get line number of @node. |
| 4608 * Try to override the limitation of lines being store in 16 bits ints |
| 4609 * if XML_PARSE_BIG_LINES parser option was used |
| 4610 * |
| 4611 * Returns the line number if successful, -1 otherwise |
| 4612 */ |
| 4613 long |
| 4614 xmlGetLineNo(const xmlNode *node) |
| 4615 { |
| 4616 return(xmlGetLineNoInternal(node, 0)); |
| 4617 } |
| 4618 |
4520 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_DEBUG_ENABLED) | 4619 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_DEBUG_ENABLED) |
4521 /** | 4620 /** |
4522 * xmlGetNodePath: | 4621 * xmlGetNodePath: |
4523 * @node: a node | 4622 * @node: a node |
4524 * | 4623 * |
4525 * Build a structure based Path for the given node | 4624 * Build a structure based Path for the given node |
4526 * | 4625 * |
4527 * Returns the new path or NULL in case of error. The caller must free | 4626 * Returns the new path or NULL in case of error. The caller must free |
4528 * the returned string | 4627 * the returned string |
4529 */ | 4628 */ |
4530 xmlChar * | 4629 xmlChar * |
4531 xmlGetNodePath(xmlNodePtr node) | 4630 xmlGetNodePath(const xmlNode *node) |
4532 { | 4631 { |
4533 xmlNodePtr cur, tmp, next; | 4632 const xmlNode *cur, *tmp, *next; |
4534 xmlChar *buffer = NULL, *temp; | 4633 xmlChar *buffer = NULL, *temp; |
4535 size_t buf_len; | 4634 size_t buf_len; |
4536 xmlChar *buf; | 4635 xmlChar *buf; |
4537 const char *sep; | 4636 const char *sep; |
4538 const char *name; | 4637 const char *name; |
4539 char nametemp[100]; | 4638 char nametemp[100]; |
4540 int occur = 0, generic; | 4639 int occur = 0, generic; |
4541 | 4640 |
4542 if (node == NULL) | 4641 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) |
4543 return (NULL); | 4642 return (NULL); |
4544 | 4643 |
4545 buf_len = 500; | 4644 buf_len = 500; |
4546 buffer = (xmlChar *) xmlMallocAtomic(buf_len * sizeof(xmlChar)); | 4645 buffer = (xmlChar *) xmlMallocAtomic(buf_len * sizeof(xmlChar)); |
4547 if (buffer == NULL) { | 4646 if (buffer == NULL) { |
4548 xmlTreeErrMemory("getting node path"); | 4647 xmlTreeErrMemory("getting node path"); |
4549 return (NULL); | 4648 return (NULL); |
4550 } | 4649 } |
4551 buf = (xmlChar *) xmlMallocAtomic(buf_len * sizeof(xmlChar)); | 4650 buf = (xmlChar *) xmlMallocAtomic(buf_len * sizeof(xmlChar)); |
4552 if (buf == NULL) { | 4651 if (buf == NULL) { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4767 /** | 4866 /** |
4768 * xmlDocGetRootElement: | 4867 * xmlDocGetRootElement: |
4769 * @doc: the document | 4868 * @doc: the document |
4770 * | 4869 * |
4771 * Get the root element of the document (doc->children is a list | 4870 * Get the root element of the document (doc->children is a list |
4772 * containing possibly comments, PIs, etc ...). | 4871 * containing possibly comments, PIs, etc ...). |
4773 * | 4872 * |
4774 * Returns the #xmlNodePtr for the root or NULL | 4873 * Returns the #xmlNodePtr for the root or NULL |
4775 */ | 4874 */ |
4776 xmlNodePtr | 4875 xmlNodePtr |
4777 xmlDocGetRootElement(xmlDocPtr doc) { | 4876 xmlDocGetRootElement(const xmlDoc *doc) { |
4778 xmlNodePtr ret; | 4877 xmlNodePtr ret; |
4779 | 4878 |
4780 if (doc == NULL) return(NULL); | 4879 if (doc == NULL) return(NULL); |
4781 ret = doc->children; | 4880 ret = doc->children; |
4782 while (ret != NULL) { | 4881 while (ret != NULL) { |
4783 if (ret->type == XML_ELEMENT_NODE) | 4882 if (ret->type == XML_ELEMENT_NODE) |
4784 return(ret); | 4883 return(ret); |
4785 ret = ret->next; | 4884 ret = ret->next; |
4786 } | 4885 } |
4787 return(ret); | 4886 return(ret); |
4788 } | 4887 } |
4789 | 4888 |
4790 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_WRITER_ENABLED) | 4889 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_WRITER_ENABLED) |
4791 /** | 4890 /** |
4792 * xmlDocSetRootElement: | 4891 * xmlDocSetRootElement: |
4793 * @doc: the document | 4892 * @doc: the document |
4794 * @root: the new document root element, if root is NULL no action is taken, | 4893 * @root: the new document root element, if root is NULL no action is taken, |
4795 * to remove a node from a document use xmlUnlinkNode(root) instead. | 4894 * to remove a node from a document use xmlUnlinkNode(root) instead. |
4796 * | 4895 * |
4797 * Set the root element of the document (doc->children is a list | 4896 * Set the root element of the document (doc->children is a list |
4798 * containing possibly comments, PIs, etc ...). | 4897 * containing possibly comments, PIs, etc ...). |
4799 * | 4898 * |
4800 * Returns the old root element if any was found, NULL if root was NULL | 4899 * Returns the old root element if any was found, NULL if root was NULL |
4801 */ | 4900 */ |
4802 xmlNodePtr | 4901 xmlNodePtr |
4803 xmlDocSetRootElement(xmlDocPtr doc, xmlNodePtr root) { | 4902 xmlDocSetRootElement(xmlDocPtr doc, xmlNodePtr root) { |
4804 xmlNodePtr old = NULL; | 4903 xmlNodePtr old = NULL; |
4805 | 4904 |
4806 if (doc == NULL) return(NULL); | 4905 if (doc == NULL) return(NULL); |
4807 if (root == NULL) | 4906 if ((root == NULL) || (root->type == XML_NAMESPACE_DECL)) |
4808 return(NULL); | 4907 return(NULL); |
4809 xmlUnlinkNode(root); | 4908 xmlUnlinkNode(root); |
4810 xmlSetTreeDoc(root, doc); | 4909 xmlSetTreeDoc(root, doc); |
4811 root->parent = (xmlNodePtr) doc; | 4910 root->parent = (xmlNodePtr) doc; |
4812 old = doc->children; | 4911 old = doc->children; |
4813 while (old != NULL) { | 4912 while (old != NULL) { |
4814 if (old->type == XML_ELEMENT_NODE) | 4913 if (old->type == XML_ELEMENT_NODE) |
4815 break; | 4914 break; |
4816 old = old->next; | 4915 old = old->next; |
4817 } | 4916 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4881 * xmlNodeGetLang: | 4980 * xmlNodeGetLang: |
4882 * @cur: the node being checked | 4981 * @cur: the node being checked |
4883 * | 4982 * |
4884 * Searches the language of a node, i.e. the values of the xml:lang | 4983 * Searches the language of a node, i.e. the values of the xml:lang |
4885 * attribute or the one carried by the nearest ancestor. | 4984 * attribute or the one carried by the nearest ancestor. |
4886 * | 4985 * |
4887 * Returns a pointer to the lang value, or NULL if not found | 4986 * Returns a pointer to the lang value, or NULL if not found |
4888 * It's up to the caller to free the memory with xmlFree(). | 4987 * It's up to the caller to free the memory with xmlFree(). |
4889 */ | 4988 */ |
4890 xmlChar * | 4989 xmlChar * |
4891 xmlNodeGetLang(xmlNodePtr cur) { | 4990 xmlNodeGetLang(const xmlNode *cur) { |
4892 xmlChar *lang; | 4991 xmlChar *lang; |
4893 | 4992 |
| 4993 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) |
| 4994 return(NULL); |
4894 while (cur != NULL) { | 4995 while (cur != NULL) { |
4895 lang = xmlGetNsProp(cur, BAD_CAST "lang", XML_XML_NAMESPACE); | 4996 lang = xmlGetNsProp(cur, BAD_CAST "lang", XML_XML_NAMESPACE); |
4896 if (lang != NULL) | 4997 if (lang != NULL) |
4897 return(lang); | 4998 return(lang); |
4898 cur = cur->parent; | 4999 cur = cur->parent; |
4899 } | 5000 } |
4900 return(NULL); | 5001 return(NULL); |
4901 } | 5002 } |
4902 | 5003 |
4903 | 5004 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4960 * xmlNodeGetSpacePreserve: | 5061 * xmlNodeGetSpacePreserve: |
4961 * @cur: the node being checked | 5062 * @cur: the node being checked |
4962 * | 5063 * |
4963 * Searches the space preserving behaviour of a node, i.e. the values | 5064 * Searches the space preserving behaviour of a node, i.e. the values |
4964 * of the xml:space attribute or the one carried by the nearest | 5065 * of the xml:space attribute or the one carried by the nearest |
4965 * ancestor. | 5066 * ancestor. |
4966 * | 5067 * |
4967 * Returns -1 if xml:space is not inherited, 0 if "default", 1 if "preserve" | 5068 * Returns -1 if xml:space is not inherited, 0 if "default", 1 if "preserve" |
4968 */ | 5069 */ |
4969 int | 5070 int |
4970 xmlNodeGetSpacePreserve(xmlNodePtr cur) { | 5071 xmlNodeGetSpacePreserve(const xmlNode *cur) { |
4971 xmlChar *space; | 5072 xmlChar *space; |
4972 | 5073 |
| 5074 if ((cur == NULL) || (cur->type != XML_ELEMENT_NODE)) |
| 5075 return(-1); |
4973 while (cur != NULL) { | 5076 while (cur != NULL) { |
4974 space = xmlGetNsProp(cur, BAD_CAST "space", XML_XML_NAMESPACE); | 5077 space = xmlGetNsProp(cur, BAD_CAST "space", XML_XML_NAMESPACE); |
4975 if (space != NULL) { | 5078 if (space != NULL) { |
4976 if (xmlStrEqual(space, BAD_CAST "preserve")) { | 5079 if (xmlStrEqual(space, BAD_CAST "preserve")) { |
4977 xmlFree(space); | 5080 xmlFree(space); |
4978 return(1); | 5081 return(1); |
4979 } | 5082 } |
4980 if (xmlStrEqual(space, BAD_CAST "default")) { | 5083 if (xmlStrEqual(space, BAD_CAST "default")) { |
4981 xmlFree(space); | 5084 xmlFree(space); |
4982 return(0); | 5085 return(0); |
(...skipping 10 matching lines...) Expand all Loading... |
4993 * xmlNodeSetName: | 5096 * xmlNodeSetName: |
4994 * @cur: the node being changed | 5097 * @cur: the node being changed |
4995 * @name: the new tag name | 5098 * @name: the new tag name |
4996 * | 5099 * |
4997 * Set (or reset) the name of a node. | 5100 * Set (or reset) the name of a node. |
4998 */ | 5101 */ |
4999 void | 5102 void |
5000 xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) { | 5103 xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) { |
5001 xmlDocPtr doc; | 5104 xmlDocPtr doc; |
5002 xmlDictPtr dict; | 5105 xmlDictPtr dict; |
| 5106 const xmlChar *freeme = NULL; |
5003 | 5107 |
5004 if (cur == NULL) return; | 5108 if (cur == NULL) return; |
5005 if (name == NULL) return; | 5109 if (name == NULL) return; |
5006 switch(cur->type) { | 5110 switch(cur->type) { |
5007 case XML_TEXT_NODE: | 5111 case XML_TEXT_NODE: |
5008 case XML_CDATA_SECTION_NODE: | 5112 case XML_CDATA_SECTION_NODE: |
5009 case XML_COMMENT_NODE: | 5113 case XML_COMMENT_NODE: |
5010 case XML_DOCUMENT_TYPE_NODE: | 5114 case XML_DOCUMENT_TYPE_NODE: |
5011 case XML_DOCUMENT_FRAG_NODE: | 5115 case XML_DOCUMENT_FRAG_NODE: |
5012 case XML_NOTATION_NODE: | 5116 case XML_NOTATION_NODE: |
(...skipping 17 matching lines...) Expand all Loading... |
5030 case XML_ENTITY_DECL: | 5134 case XML_ENTITY_DECL: |
5031 break; | 5135 break; |
5032 } | 5136 } |
5033 doc = cur->doc; | 5137 doc = cur->doc; |
5034 if (doc != NULL) | 5138 if (doc != NULL) |
5035 dict = doc->dict; | 5139 dict = doc->dict; |
5036 else | 5140 else |
5037 dict = NULL; | 5141 dict = NULL; |
5038 if (dict != NULL) { | 5142 if (dict != NULL) { |
5039 if ((cur->name != NULL) && (!xmlDictOwns(dict, cur->name))) | 5143 if ((cur->name != NULL) && (!xmlDictOwns(dict, cur->name))) |
5040 » xmlFree((xmlChar *) cur->name); | 5144 » freeme = cur->name; |
5041 cur->name = xmlDictLookup(dict, name, -1); | 5145 cur->name = xmlDictLookup(dict, name, -1); |
5042 } else { | 5146 } else { |
5043 » if (cur->name != NULL) xmlFree((xmlChar *) cur->name); | 5147 » if (cur->name != NULL) |
| 5148 » freeme = cur->name; |
5044 cur->name = xmlStrdup(name); | 5149 cur->name = xmlStrdup(name); |
5045 } | 5150 } |
| 5151 |
| 5152 if (freeme) |
| 5153 xmlFree((xmlChar *) freeme); |
5046 } | 5154 } |
5047 #endif | 5155 #endif |
5048 | 5156 |
5049 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED) | 5157 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED) |
5050 /** | 5158 /** |
5051 * xmlNodeSetBase: | 5159 * xmlNodeSetBase: |
5052 * @cur: the node being changed | 5160 * @cur: the node being changed |
5053 * @uri: the new base URI | 5161 * @uri: the new base URI |
5054 * | 5162 * |
5055 * Set (or reset) the base URI of a node, i.e. the value of the | 5163 * Set (or reset) the base URI of a node, i.e. the value of the |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5123 * 5.1.1. Base URI within Document Content | 5231 * 5.1.1. Base URI within Document Content |
5124 * and | 5232 * and |
5125 * 5.1.2. Base URI from the Encapsulating Entity | 5233 * 5.1.2. Base URI from the Encapsulating Entity |
5126 * However it does not return the document base (5.1.3), use | 5234 * However it does not return the document base (5.1.3), use |
5127 * doc->URL in this case | 5235 * doc->URL in this case |
5128 * | 5236 * |
5129 * Returns a pointer to the base URL, or NULL if not found | 5237 * Returns a pointer to the base URL, or NULL if not found |
5130 * It's up to the caller to free the memory with xmlFree(). | 5238 * It's up to the caller to free the memory with xmlFree(). |
5131 */ | 5239 */ |
5132 xmlChar * | 5240 xmlChar * |
5133 xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) { | 5241 xmlNodeGetBase(const xmlDoc *doc, const xmlNode *cur) { |
5134 xmlChar *oldbase = NULL; | 5242 xmlChar *oldbase = NULL; |
5135 xmlChar *base, *newbase; | 5243 xmlChar *base, *newbase; |
5136 | 5244 |
5137 if ((cur == NULL) && (doc == NULL)) | 5245 if ((cur == NULL) && (doc == NULL)) |
5138 return(NULL); | 5246 return(NULL); |
| 5247 if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) |
| 5248 return(NULL); |
5139 if (doc == NULL) doc = cur->doc; | 5249 if (doc == NULL) doc = cur->doc; |
5140 if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) { | 5250 if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) { |
5141 cur = doc->children; | 5251 cur = doc->children; |
5142 while ((cur != NULL) && (cur->name != NULL)) { | 5252 while ((cur != NULL) && (cur->name != NULL)) { |
5143 if (cur->type != XML_ELEMENT_NODE) { | 5253 if (cur->type != XML_ELEMENT_NODE) { |
5144 cur = cur->next; | 5254 cur = cur->next; |
5145 continue; | 5255 continue; |
5146 } | 5256 } |
5147 if (!xmlStrcasecmp(cur->name, BAD_CAST "html")) { | 5257 if (!xmlStrcasecmp(cur->name, BAD_CAST "html")) { |
5148 cur = cur->children; | 5258 cur = cur->children; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5206 * | 5316 * |
5207 * Read the value of a node @cur, this can be either the text carried | 5317 * Read the value of a node @cur, this can be either the text carried |
5208 * directly by this node if it's a TEXT node or the aggregate string | 5318 * directly by this node if it's a TEXT node or the aggregate string |
5209 * of the values carried by this node child's (TEXT and ENTITY_REF). | 5319 * of the values carried by this node child's (TEXT and ENTITY_REF). |
5210 * Entity references are substituted. | 5320 * Entity references are substituted. |
5211 * Fills up the buffer @buffer with this value | 5321 * Fills up the buffer @buffer with this value |
5212 * | 5322 * |
5213 * Returns 0 in case of success and -1 in case of error. | 5323 * Returns 0 in case of success and -1 in case of error. |
5214 */ | 5324 */ |
5215 int | 5325 int |
5216 xmlNodeBufGetContent(xmlBufferPtr buffer, xmlNodePtr cur) | 5326 xmlNodeBufGetContent(xmlBufferPtr buffer, const xmlNode *cur) |
5217 { | 5327 { |
| 5328 xmlBufPtr buf; |
| 5329 int ret; |
| 5330 |
5218 if ((cur == NULL) || (buffer == NULL)) return(-1); | 5331 if ((cur == NULL) || (buffer == NULL)) return(-1); |
| 5332 buf = xmlBufFromBuffer(buffer); |
| 5333 ret = xmlBufGetNodeContent(buf, cur); |
| 5334 buffer = xmlBufBackToBuffer(buf); |
| 5335 if ((ret < 0) || (buffer == NULL)) |
| 5336 return(-1); |
| 5337 return(0); |
| 5338 } |
| 5339 |
| 5340 /** |
| 5341 * xmlBufGetNodeContent: |
| 5342 * @buf: a buffer xmlBufPtr |
| 5343 * @cur: the node being read |
| 5344 * |
| 5345 * Read the value of a node @cur, this can be either the text carried |
| 5346 * directly by this node if it's a TEXT node or the aggregate string |
| 5347 * of the values carried by this node child's (TEXT and ENTITY_REF). |
| 5348 * Entity references are substituted. |
| 5349 * Fills up the buffer @buf with this value |
| 5350 * |
| 5351 * Returns 0 in case of success and -1 in case of error. |
| 5352 */ |
| 5353 int |
| 5354 xmlBufGetNodeContent(xmlBufPtr buf, const xmlNode *cur) |
| 5355 { |
| 5356 if ((cur == NULL) || (buf == NULL)) return(-1); |
5219 switch (cur->type) { | 5357 switch (cur->type) { |
5220 case XML_CDATA_SECTION_NODE: | 5358 case XML_CDATA_SECTION_NODE: |
5221 case XML_TEXT_NODE: | 5359 case XML_TEXT_NODE: |
5222 » xmlBufferCat(buffer, cur->content); | 5360 » xmlBufCat(buf, cur->content); |
5223 break; | 5361 break; |
5224 case XML_DOCUMENT_FRAG_NODE: | 5362 case XML_DOCUMENT_FRAG_NODE: |
5225 case XML_ELEMENT_NODE:{ | 5363 case XML_ELEMENT_NODE:{ |
5226 xmlNodePtr tmp = cur; | 5364 const xmlNode *tmp = cur; |
5227 | 5365 |
5228 while (tmp != NULL) { | 5366 while (tmp != NULL) { |
5229 switch (tmp->type) { | 5367 switch (tmp->type) { |
5230 case XML_CDATA_SECTION_NODE: | 5368 case XML_CDATA_SECTION_NODE: |
5231 case XML_TEXT_NODE: | 5369 case XML_TEXT_NODE: |
5232 if (tmp->content != NULL) | 5370 if (tmp->content != NULL) |
5233 xmlBufferCat(buffer, tmp->content); | 5371 xmlBufCat(buf, tmp->content); |
5234 break; | 5372 break; |
5235 case XML_ENTITY_REF_NODE: | 5373 case XML_ENTITY_REF_NODE: |
5236 xmlNodeBufGetContent(buffer, tmp); | 5374 xmlBufGetNodeContent(buf, tmp); |
5237 break; | 5375 break; |
5238 default: | 5376 default: |
5239 break; | 5377 break; |
5240 } | 5378 } |
5241 /* | 5379 /* |
5242 * Skip to next node | 5380 * Skip to next node |
5243 */ | 5381 */ |
5244 if (tmp->children != NULL) { | 5382 if (tmp->children != NULL) { |
5245 if (tmp->children->type != XML_ENTITY_DECL) { | 5383 if (tmp->children->type != XML_ENTITY_DECL) { |
5246 tmp = tmp->children; | 5384 tmp = tmp->children; |
(...skipping 23 matching lines...) Expand all Loading... |
5270 } while (tmp != NULL); | 5408 } while (tmp != NULL); |
5271 } | 5409 } |
5272 break; | 5410 break; |
5273 } | 5411 } |
5274 case XML_ATTRIBUTE_NODE:{ | 5412 case XML_ATTRIBUTE_NODE:{ |
5275 xmlAttrPtr attr = (xmlAttrPtr) cur; | 5413 xmlAttrPtr attr = (xmlAttrPtr) cur; |
5276 xmlNodePtr tmp = attr->children; | 5414 xmlNodePtr tmp = attr->children; |
5277 | 5415 |
5278 while (tmp != NULL) { | 5416 while (tmp != NULL) { |
5279 if (tmp->type == XML_TEXT_NODE) | 5417 if (tmp->type == XML_TEXT_NODE) |
5280 » » xmlBufferCat(buffer, tmp->content); | 5418 » » xmlBufCat(buf, tmp->content); |
5281 else | 5419 else |
5282 » » xmlNodeBufGetContent(buffer, tmp); | 5420 » » xmlBufGetNodeContent(buf, tmp); |
5283 tmp = tmp->next; | 5421 tmp = tmp->next; |
5284 } | 5422 } |
5285 break; | 5423 break; |
5286 } | 5424 } |
5287 case XML_COMMENT_NODE: | 5425 case XML_COMMENT_NODE: |
5288 case XML_PI_NODE: | 5426 case XML_PI_NODE: |
5289 » xmlBufferCat(buffer, cur->content); | 5427 » xmlBufCat(buf, cur->content); |
5290 break; | 5428 break; |
5291 case XML_ENTITY_REF_NODE:{ | 5429 case XML_ENTITY_REF_NODE:{ |
5292 xmlEntityPtr ent; | 5430 xmlEntityPtr ent; |
5293 xmlNodePtr tmp; | 5431 xmlNodePtr tmp; |
5294 | 5432 |
5295 /* lookup entity declaration */ | 5433 /* lookup entity declaration */ |
5296 ent = xmlGetDocEntity(cur->doc, cur->name); | 5434 ent = xmlGetDocEntity(cur->doc, cur->name); |
5297 if (ent == NULL) | 5435 if (ent == NULL) |
5298 return(-1); | 5436 return(-1); |
5299 | 5437 |
5300 /* an entity content can be any "well balanced chunk", | 5438 /* an entity content can be any "well balanced chunk", |
5301 * i.e. the result of the content [43] production: | 5439 * i.e. the result of the content [43] production: |
5302 * http://www.w3.org/TR/REC-xml#NT-content | 5440 * http://www.w3.org/TR/REC-xml#NT-content |
5303 * -> we iterate through child nodes and recursive call | 5441 * -> we iterate through child nodes and recursive call |
5304 * xmlNodeGetContent() which handles all possible node types */ | 5442 * xmlNodeGetContent() which handles all possible node types */ |
5305 tmp = ent->children; | 5443 tmp = ent->children; |
5306 while (tmp) { | 5444 while (tmp) { |
5307 » » xmlNodeBufGetContent(buffer, tmp); | 5445 » » xmlBufGetNodeContent(buf, tmp); |
5308 tmp = tmp->next; | 5446 tmp = tmp->next; |
5309 } | 5447 } |
5310 break; | 5448 break; |
5311 } | 5449 } |
5312 case XML_ENTITY_NODE: | 5450 case XML_ENTITY_NODE: |
5313 case XML_DOCUMENT_TYPE_NODE: | 5451 case XML_DOCUMENT_TYPE_NODE: |
5314 case XML_NOTATION_NODE: | 5452 case XML_NOTATION_NODE: |
5315 case XML_DTD_NODE: | 5453 case XML_DTD_NODE: |
5316 case XML_XINCLUDE_START: | 5454 case XML_XINCLUDE_START: |
5317 case XML_XINCLUDE_END: | 5455 case XML_XINCLUDE_END: |
5318 break; | 5456 break; |
5319 case XML_DOCUMENT_NODE: | 5457 case XML_DOCUMENT_NODE: |
5320 #ifdef LIBXML_DOCB_ENABLED | 5458 #ifdef LIBXML_DOCB_ENABLED |
5321 case XML_DOCB_DOCUMENT_NODE: | 5459 case XML_DOCB_DOCUMENT_NODE: |
5322 #endif | 5460 #endif |
5323 case XML_HTML_DOCUMENT_NODE: | 5461 case XML_HTML_DOCUMENT_NODE: |
5324 cur = cur->children; | 5462 cur = cur->children; |
5325 while (cur!= NULL) { | 5463 while (cur!= NULL) { |
5326 if ((cur->type == XML_ELEMENT_NODE) || | 5464 if ((cur->type == XML_ELEMENT_NODE) || |
5327 (cur->type == XML_TEXT_NODE) || | 5465 (cur->type == XML_TEXT_NODE) || |
5328 (cur->type == XML_CDATA_SECTION_NODE)) { | 5466 (cur->type == XML_CDATA_SECTION_NODE)) { |
5329 » » xmlNodeBufGetContent(buffer, cur); | 5467 » » xmlBufGetNodeContent(buf, cur); |
5330 } | 5468 } |
5331 cur = cur->next; | 5469 cur = cur->next; |
5332 } | 5470 } |
5333 break; | 5471 break; |
5334 case XML_NAMESPACE_DECL: | 5472 case XML_NAMESPACE_DECL: |
5335 » xmlBufferCat(buffer, ((xmlNsPtr) cur)->href); | 5473 » xmlBufCat(buf, ((xmlNsPtr) cur)->href); |
5336 break; | 5474 break; |
5337 case XML_ELEMENT_DECL: | 5475 case XML_ELEMENT_DECL: |
5338 case XML_ATTRIBUTE_DECL: | 5476 case XML_ATTRIBUTE_DECL: |
5339 case XML_ENTITY_DECL: | 5477 case XML_ENTITY_DECL: |
5340 break; | 5478 break; |
5341 } | 5479 } |
5342 return(0); | 5480 return(0); |
5343 } | 5481 } |
| 5482 |
5344 /** | 5483 /** |
5345 * xmlNodeGetContent: | 5484 * xmlNodeGetContent: |
5346 * @cur: the node being read | 5485 * @cur: the node being read |
5347 * | 5486 * |
5348 * Read the value of a node, this can be either the text carried | 5487 * Read the value of a node, this can be either the text carried |
5349 * directly by this node if it's a TEXT node or the aggregate string | 5488 * directly by this node if it's a TEXT node or the aggregate string |
5350 * of the values carried by this node child's (TEXT and ENTITY_REF). | 5489 * of the values carried by this node child's (TEXT and ENTITY_REF). |
5351 * Entity references are substituted. | 5490 * Entity references are substituted. |
5352 * Returns a new #xmlChar * or NULL if no content is available. | 5491 * Returns a new #xmlChar * or NULL if no content is available. |
5353 * It's up to the caller to free the memory with xmlFree(). | 5492 * It's up to the caller to free the memory with xmlFree(). |
5354 */ | 5493 */ |
5355 xmlChar * | 5494 xmlChar * |
5356 xmlNodeGetContent(xmlNodePtr cur) | 5495 xmlNodeGetContent(const xmlNode *cur) |
5357 { | 5496 { |
5358 if (cur == NULL) | 5497 if (cur == NULL) |
5359 return (NULL); | 5498 return (NULL); |
5360 switch (cur->type) { | 5499 switch (cur->type) { |
5361 case XML_DOCUMENT_FRAG_NODE: | 5500 case XML_DOCUMENT_FRAG_NODE: |
5362 case XML_ELEMENT_NODE:{ | 5501 case XML_ELEMENT_NODE:{ |
5363 xmlBufferPtr buffer; | 5502 xmlBufPtr buf; |
5364 xmlChar *ret; | 5503 xmlChar *ret; |
5365 | 5504 |
5366 buffer = xmlBufferCreateSize(64); | 5505 buf = xmlBufCreateSize(64); |
5367 if (buffer == NULL) | 5506 if (buf == NULL) |
5368 return (NULL); | 5507 return (NULL); |
5369 » » xmlNodeBufGetContent(buffer, cur); | 5508 » » xmlBufGetNodeContent(buf, cur); |
5370 ret = buffer->content; | 5509 ret = xmlBufDetach(buf); |
5371 buffer->content = NULL; | 5510 xmlBufFree(buf); |
5372 xmlBufferFree(buffer); | |
5373 return (ret); | 5511 return (ret); |
5374 } | 5512 } |
5375 case XML_ATTRIBUTE_NODE: | 5513 case XML_ATTRIBUTE_NODE: |
5376 return(xmlGetPropNodeValueInternal((xmlAttrPtr) cur)); | 5514 return(xmlGetPropNodeValueInternal((xmlAttrPtr) cur)); |
5377 case XML_COMMENT_NODE: | 5515 case XML_COMMENT_NODE: |
5378 case XML_PI_NODE: | 5516 case XML_PI_NODE: |
5379 if (cur->content != NULL) | 5517 if (cur->content != NULL) |
5380 return (xmlStrdup(cur->content)); | 5518 return (xmlStrdup(cur->content)); |
5381 return (NULL); | 5519 return (NULL); |
5382 case XML_ENTITY_REF_NODE:{ | 5520 case XML_ENTITY_REF_NODE:{ |
5383 xmlEntityPtr ent; | 5521 xmlEntityPtr ent; |
5384 xmlBufferPtr buffer; | 5522 xmlBufPtr buf; |
5385 xmlChar *ret; | 5523 xmlChar *ret; |
5386 | 5524 |
5387 /* lookup entity declaration */ | 5525 /* lookup entity declaration */ |
5388 ent = xmlGetDocEntity(cur->doc, cur->name); | 5526 ent = xmlGetDocEntity(cur->doc, cur->name); |
5389 if (ent == NULL) | 5527 if (ent == NULL) |
5390 return (NULL); | 5528 return (NULL); |
5391 | 5529 |
5392 buffer = xmlBufferCreate(); | 5530 buf = xmlBufCreate(); |
5393 if (buffer == NULL) | 5531 if (buf == NULL) |
5394 return (NULL); | 5532 return (NULL); |
5395 | 5533 |
5396 xmlNodeBufGetContent(buffer, cur); | 5534 xmlBufGetNodeContent(buf, cur); |
5397 | 5535 |
5398 ret = buffer->content; | 5536 ret = xmlBufDetach(buf); |
5399 buffer->content = NULL; | 5537 xmlBufFree(buf); |
5400 xmlBufferFree(buffer); | |
5401 return (ret); | 5538 return (ret); |
5402 } | 5539 } |
5403 case XML_ENTITY_NODE: | 5540 case XML_ENTITY_NODE: |
5404 case XML_DOCUMENT_TYPE_NODE: | 5541 case XML_DOCUMENT_TYPE_NODE: |
5405 case XML_NOTATION_NODE: | 5542 case XML_NOTATION_NODE: |
5406 case XML_DTD_NODE: | 5543 case XML_DTD_NODE: |
5407 case XML_XINCLUDE_START: | 5544 case XML_XINCLUDE_START: |
5408 case XML_XINCLUDE_END: | 5545 case XML_XINCLUDE_END: |
5409 return (NULL); | 5546 return (NULL); |
5410 case XML_DOCUMENT_NODE: | 5547 case XML_DOCUMENT_NODE: |
5411 #ifdef LIBXML_DOCB_ENABLED | 5548 #ifdef LIBXML_DOCB_ENABLED |
5412 case XML_DOCB_DOCUMENT_NODE: | 5549 case XML_DOCB_DOCUMENT_NODE: |
5413 #endif | 5550 #endif |
5414 case XML_HTML_DOCUMENT_NODE: { | 5551 case XML_HTML_DOCUMENT_NODE: { |
5415 » xmlBufferPtr buffer; | 5552 » xmlBufPtr buf; |
5416 xmlChar *ret; | 5553 xmlChar *ret; |
5417 | 5554 |
5418 » buffer = xmlBufferCreate(); | 5555 » buf = xmlBufCreate(); |
5419 » if (buffer == NULL) | 5556 » if (buf == NULL) |
5420 return (NULL); | 5557 return (NULL); |
5421 | 5558 |
5422 » xmlNodeBufGetContent(buffer, (xmlNodePtr) cur); | 5559 » xmlBufGetNodeContent(buf, (xmlNodePtr) cur); |
5423 | 5560 |
5424 » ret = buffer->content; | 5561 » ret = xmlBufDetach(buf); |
5425 » buffer->content = NULL; | 5562 » xmlBufFree(buf); |
5426 » xmlBufferFree(buffer); | |
5427 return (ret); | 5563 return (ret); |
5428 } | 5564 } |
5429 case XML_NAMESPACE_DECL: { | 5565 case XML_NAMESPACE_DECL: { |
5430 xmlChar *tmp; | 5566 xmlChar *tmp; |
5431 | 5567 |
5432 tmp = xmlStrdup(((xmlNsPtr) cur)->href); | 5568 tmp = xmlStrdup(((xmlNsPtr) cur)->href); |
5433 return (tmp); | 5569 return (tmp); |
5434 } | 5570 } |
5435 case XML_ELEMENT_DECL: | 5571 case XML_ELEMENT_DECL: |
5436 /* TODO !!! */ | 5572 /* TODO !!! */ |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5729 * xmlGetNsList: | 5865 * xmlGetNsList: |
5730 * @doc: the document | 5866 * @doc: the document |
5731 * @node: the current node | 5867 * @node: the current node |
5732 * | 5868 * |
5733 * Search all the namespace applying to a given element. | 5869 * Search all the namespace applying to a given element. |
5734 * Returns an NULL terminated array of all the #xmlNsPtr found | 5870 * Returns an NULL terminated array of all the #xmlNsPtr found |
5735 * that need to be freed by the caller or NULL if no | 5871 * that need to be freed by the caller or NULL if no |
5736 * namespace if defined | 5872 * namespace if defined |
5737 */ | 5873 */ |
5738 xmlNsPtr * | 5874 xmlNsPtr * |
5739 xmlGetNsList(xmlDocPtr doc ATTRIBUTE_UNUSED, xmlNodePtr node) | 5875 xmlGetNsList(const xmlDoc *doc ATTRIBUTE_UNUSED, const xmlNode *node) |
5740 { | 5876 { |
5741 xmlNsPtr cur; | 5877 xmlNsPtr cur; |
5742 xmlNsPtr *ret = NULL; | 5878 xmlNsPtr *ret = NULL; |
5743 int nbns = 0; | 5879 int nbns = 0; |
5744 int maxns = 10; | 5880 int maxns = 10; |
5745 int i; | 5881 int i; |
5746 | 5882 |
| 5883 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) |
| 5884 return(NULL); |
| 5885 |
5747 while (node != NULL) { | 5886 while (node != NULL) { |
5748 if (node->type == XML_ELEMENT_NODE) { | 5887 if (node->type == XML_ELEMENT_NODE) { |
5749 cur = node->nsDef; | 5888 cur = node->nsDef; |
5750 while (cur != NULL) { | 5889 while (cur != NULL) { |
5751 if (ret == NULL) { | 5890 if (ret == NULL) { |
5752 ret = | 5891 ret = |
5753 (xmlNsPtr *) xmlMalloc((maxns + 1) * | 5892 (xmlNsPtr *) xmlMalloc((maxns + 1) * |
5754 sizeof(xmlNsPtr)); | 5893 sizeof(xmlNsPtr)); |
5755 if (ret == NULL) { | 5894 if (ret == NULL) { |
5756 xmlTreeErrMemory("getting namespace list"); | 5895 xmlTreeErrMemory("getting namespace list"); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5833 * We don't allow to cross entities boundaries. If you don't declare | 5972 * We don't allow to cross entities boundaries. If you don't declare |
5834 * the namespace within those you will be in troubles !!! A warning | 5973 * the namespace within those you will be in troubles !!! A warning |
5835 * is generated to cover this case. | 5974 * is generated to cover this case. |
5836 * | 5975 * |
5837 * Returns the namespace pointer or NULL. | 5976 * Returns the namespace pointer or NULL. |
5838 */ | 5977 */ |
5839 xmlNsPtr | 5978 xmlNsPtr |
5840 xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace) { | 5979 xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace) { |
5841 | 5980 |
5842 xmlNsPtr cur; | 5981 xmlNsPtr cur; |
5843 xmlNodePtr orig = node; | 5982 const xmlNode *orig = node; |
5844 | 5983 |
5845 if (node == NULL) return(NULL); | 5984 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) return(NULL); |
5846 if ((nameSpace != NULL) && | 5985 if ((nameSpace != NULL) && |
5847 (xmlStrEqual(nameSpace, (const xmlChar *)"xml"))) { | 5986 (xmlStrEqual(nameSpace, (const xmlChar *)"xml"))) { |
5848 if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) { | 5987 if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) { |
5849 /* | 5988 /* |
5850 * The XML-1.0 namespace is normally held on the root | 5989 * The XML-1.0 namespace is normally held on the root |
5851 * element. In this case exceptionally create it on the | 5990 * element. In this case exceptionally create it on the |
5852 * node element. | 5991 * node element. |
5853 */ | 5992 */ |
5854 cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); | 5993 cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); |
5855 if (cur == NULL) { | 5994 if (cur == NULL) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5965 * the defined namespace or return NULL otherwise. | 6104 * the defined namespace or return NULL otherwise. |
5966 * Returns the namespace pointer or NULL. | 6105 * Returns the namespace pointer or NULL. |
5967 */ | 6106 */ |
5968 xmlNsPtr | 6107 xmlNsPtr |
5969 xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const xmlChar * href) | 6108 xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const xmlChar * href) |
5970 { | 6109 { |
5971 xmlNsPtr cur; | 6110 xmlNsPtr cur; |
5972 xmlNodePtr orig = node; | 6111 xmlNodePtr orig = node; |
5973 int is_attr; | 6112 int is_attr; |
5974 | 6113 |
5975 if ((node == NULL) || (href == NULL)) | 6114 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) || (href == NULL)) |
5976 return (NULL); | 6115 return (NULL); |
5977 if (xmlStrEqual(href, XML_XML_NAMESPACE)) { | 6116 if (xmlStrEqual(href, XML_XML_NAMESPACE)) { |
5978 /* | 6117 /* |
5979 * Only the document can hold the XML spec namespace. | 6118 * Only the document can hold the XML spec namespace. |
5980 */ | 6119 */ |
5981 if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) { | 6120 if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) { |
5982 /* | 6121 /* |
5983 * The XML-1.0 namespace is normally held on the root | 6122 * The XML-1.0 namespace is normally held on the root |
5984 * element. In this case exceptionally create it on the | 6123 * element. In this case exceptionally create it on the |
5985 * node element. | 6124 * node element. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6056 * null (default namespace) or reused within the subtree defined by | 6195 * null (default namespace) or reused within the subtree defined by |
6057 * @tree or on one of its ancestors then a new prefix is generated. | 6196 * @tree or on one of its ancestors then a new prefix is generated. |
6058 * Returns the (new) namespace definition or NULL in case of error | 6197 * Returns the (new) namespace definition or NULL in case of error |
6059 */ | 6198 */ |
6060 static xmlNsPtr | 6199 static xmlNsPtr |
6061 xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) { | 6200 xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) { |
6062 xmlNsPtr def; | 6201 xmlNsPtr def; |
6063 xmlChar prefix[50]; | 6202 xmlChar prefix[50]; |
6064 int counter = 1; | 6203 int counter = 1; |
6065 | 6204 |
6066 if (tree == NULL) { | 6205 if ((tree == NULL) || (tree->type != XML_ELEMENT_NODE)) { |
6067 #ifdef DEBUG_TREE | 6206 #ifdef DEBUG_TREE |
6068 xmlGenericError(xmlGenericErrorContext, | 6207 xmlGenericError(xmlGenericErrorContext, |
6069 "xmlNewReconciliedNs : tree == NULL\n"); | 6208 "xmlNewReconciliedNs : tree == NULL\n"); |
6070 #endif | 6209 #endif |
6071 return(NULL); | 6210 return(NULL); |
6072 } | 6211 } |
6073 if ((ns == NULL) || (ns->type != XML_NAMESPACE_DECL)) { | 6212 if ((ns == NULL) || (ns->type != XML_NAMESPACE_DECL)) { |
6074 #ifdef DEBUG_TREE | 6213 #ifdef DEBUG_TREE |
6075 xmlGenericError(xmlGenericErrorContext, | 6214 xmlGenericError(xmlGenericErrorContext, |
6076 "xmlNewReconciliedNs : ns == NULL\n"); | 6215 "xmlNewReconciliedNs : ns == NULL\n"); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6302 } | 6441 } |
6303 if (oldNs != NULL) | 6442 if (oldNs != NULL) |
6304 xmlFree(oldNs); | 6443 xmlFree(oldNs); |
6305 if (newNs != NULL) | 6444 if (newNs != NULL) |
6306 xmlFree(newNs); | 6445 xmlFree(newNs); |
6307 return(ret); | 6446 return(ret); |
6308 } | 6447 } |
6309 #endif /* LIBXML_TREE_ENABLED */ | 6448 #endif /* LIBXML_TREE_ENABLED */ |
6310 | 6449 |
6311 static xmlAttrPtr | 6450 static xmlAttrPtr |
6312 xmlGetPropNodeInternal(xmlNodePtr node, const xmlChar *name, | 6451 xmlGetPropNodeInternal(const xmlNode *node, const xmlChar *name, |
6313 const xmlChar *nsName, int useDTD) | 6452 const xmlChar *nsName, int useDTD) |
6314 { | 6453 { |
6315 xmlAttrPtr prop; | 6454 xmlAttrPtr prop; |
6316 | 6455 |
6317 if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) | 6456 if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) |
6318 return(NULL); | 6457 return(NULL); |
6319 | 6458 |
6320 if (node->properties != NULL) { | 6459 if (node->properties != NULL) { |
6321 prop = node->properties; | 6460 prop = node->properties; |
6322 if (nsName == NULL) { | 6461 if (nsName == NULL) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6416 * Only default/fixed attrs are relevant. | 6555 * Only default/fixed attrs are relevant. |
6417 */ | 6556 */ |
6418 if ((attrDecl != NULL) && (attrDecl->defaultValue != NULL)) | 6557 if ((attrDecl != NULL) && (attrDecl->defaultValue != NULL)) |
6419 return((xmlAttrPtr) attrDecl); | 6558 return((xmlAttrPtr) attrDecl); |
6420 } | 6559 } |
6421 #endif /* LIBXML_TREE_ENABLED */ | 6560 #endif /* LIBXML_TREE_ENABLED */ |
6422 return(NULL); | 6561 return(NULL); |
6423 } | 6562 } |
6424 | 6563 |
6425 static xmlChar* | 6564 static xmlChar* |
6426 xmlGetPropNodeValueInternal(xmlAttrPtr prop) | 6565 xmlGetPropNodeValueInternal(const xmlAttr *prop) |
6427 { | 6566 { |
6428 if (prop == NULL) | 6567 if (prop == NULL) |
6429 return(NULL); | 6568 return(NULL); |
6430 if (prop->type == XML_ATTRIBUTE_NODE) { | 6569 if (prop->type == XML_ATTRIBUTE_NODE) { |
6431 /* | 6570 /* |
6432 * Note that we return at least the empty string. | 6571 * Note that we return at least the empty string. |
6433 * TODO: Do we really always want that? | 6572 * TODO: Do we really always want that? |
6434 */ | 6573 */ |
6435 if (prop->children != NULL) { | 6574 if (prop->children != NULL) { |
6436 if ((prop->children->next == NULL) && | 6575 if ((prop->children->next == NULL) && |
(...skipping 25 matching lines...) Expand all Loading... |
6462 * @name: the attribute name | 6601 * @name: the attribute name |
6463 * | 6602 * |
6464 * Search an attribute associated to a node | 6603 * Search an attribute associated to a node |
6465 * This function also looks in DTD attribute declaration for #FIXED or | 6604 * This function also looks in DTD attribute declaration for #FIXED or |
6466 * default declaration values unless DTD use has been turned off. | 6605 * default declaration values unless DTD use has been turned off. |
6467 * | 6606 * |
6468 * Returns the attribute or the attribute declaration or NULL if | 6607 * Returns the attribute or the attribute declaration or NULL if |
6469 * neither was found. | 6608 * neither was found. |
6470 */ | 6609 */ |
6471 xmlAttrPtr | 6610 xmlAttrPtr |
6472 xmlHasProp(xmlNodePtr node, const xmlChar *name) { | 6611 xmlHasProp(const xmlNode *node, const xmlChar *name) { |
6473 xmlAttrPtr prop; | 6612 xmlAttrPtr prop; |
6474 xmlDocPtr doc; | 6613 xmlDocPtr doc; |
6475 | 6614 |
6476 if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) | 6615 if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) |
6477 return(NULL); | 6616 return(NULL); |
6478 /* | 6617 /* |
6479 * Check on the properties attached to the node | 6618 * Check on the properties attached to the node |
6480 */ | 6619 */ |
6481 prop = node->properties; | 6620 prop = node->properties; |
6482 while (prop != NULL) { | 6621 while (prop != NULL) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6517 * This attribute has to be anchored in the namespace specified. | 6656 * This attribute has to be anchored in the namespace specified. |
6518 * This does the entity substitution. | 6657 * This does the entity substitution. |
6519 * This function looks in DTD attribute declaration for #FIXED or | 6658 * This function looks in DTD attribute declaration for #FIXED or |
6520 * default declaration values unless DTD use has been turned off. | 6659 * default declaration values unless DTD use has been turned off. |
6521 * Note that a namespace of NULL indicates to use the default namespace. | 6660 * Note that a namespace of NULL indicates to use the default namespace. |
6522 * | 6661 * |
6523 * Returns the attribute or the attribute declaration or NULL | 6662 * Returns the attribute or the attribute declaration or NULL |
6524 * if neither was found. | 6663 * if neither was found. |
6525 */ | 6664 */ |
6526 xmlAttrPtr | 6665 xmlAttrPtr |
6527 xmlHasNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) { | 6666 xmlHasNsProp(const xmlNode *node, const xmlChar *name, const xmlChar *nameSpace)
{ |
6528 | 6667 |
6529 return(xmlGetPropNodeInternal(node, name, nameSpace, xmlCheckDTD)); | 6668 return(xmlGetPropNodeInternal(node, name, nameSpace, xmlCheckDTD)); |
6530 } | 6669 } |
6531 | 6670 |
6532 /** | 6671 /** |
6533 * xmlGetProp: | 6672 * xmlGetProp: |
6534 * @node: the node | 6673 * @node: the node |
6535 * @name: the attribute name | 6674 * @name: the attribute name |
6536 * | 6675 * |
6537 * Search and get the value of an attribute associated to a node | 6676 * Search and get the value of an attribute associated to a node |
6538 * This does the entity substitution. | 6677 * This does the entity substitution. |
6539 * This function looks in DTD attribute declaration for #FIXED or | 6678 * This function looks in DTD attribute declaration for #FIXED or |
6540 * default declaration values unless DTD use has been turned off. | 6679 * default declaration values unless DTD use has been turned off. |
6541 * NOTE: this function acts independently of namespaces associated | 6680 * NOTE: this function acts independently of namespaces associated |
6542 * to the attribute. Use xmlGetNsProp() or xmlGetNoNsProp() | 6681 * to the attribute. Use xmlGetNsProp() or xmlGetNoNsProp() |
6543 * for namespace aware processing. | 6682 * for namespace aware processing. |
6544 * | 6683 * |
6545 * Returns the attribute value or NULL if not found. | 6684 * Returns the attribute value or NULL if not found. |
6546 * It's up to the caller to free the memory with xmlFree(). | 6685 * It's up to the caller to free the memory with xmlFree(). |
6547 */ | 6686 */ |
6548 xmlChar * | 6687 xmlChar * |
6549 xmlGetProp(xmlNodePtr node, const xmlChar *name) { | 6688 xmlGetProp(const xmlNode *node, const xmlChar *name) { |
6550 xmlAttrPtr prop; | 6689 xmlAttrPtr prop; |
6551 | 6690 |
6552 prop = xmlHasProp(node, name); | 6691 prop = xmlHasProp(node, name); |
6553 if (prop == NULL) | 6692 if (prop == NULL) |
6554 return(NULL); | 6693 return(NULL); |
6555 return(xmlGetPropNodeValueInternal(prop)); | 6694 return(xmlGetPropNodeValueInternal(prop)); |
6556 } | 6695 } |
6557 | 6696 |
6558 /** | 6697 /** |
6559 * xmlGetNoNsProp: | 6698 * xmlGetNoNsProp: |
6560 * @node: the node | 6699 * @node: the node |
6561 * @name: the attribute name | 6700 * @name: the attribute name |
6562 * | 6701 * |
6563 * Search and get the value of an attribute associated to a node | 6702 * Search and get the value of an attribute associated to a node |
6564 * This does the entity substitution. | 6703 * This does the entity substitution. |
6565 * This function looks in DTD attribute declaration for #FIXED or | 6704 * This function looks in DTD attribute declaration for #FIXED or |
6566 * default declaration values unless DTD use has been turned off. | 6705 * default declaration values unless DTD use has been turned off. |
6567 * This function is similar to xmlGetProp except it will accept only | 6706 * This function is similar to xmlGetProp except it will accept only |
6568 * an attribute in no namespace. | 6707 * an attribute in no namespace. |
6569 * | 6708 * |
6570 * Returns the attribute value or NULL if not found. | 6709 * Returns the attribute value or NULL if not found. |
6571 * It's up to the caller to free the memory with xmlFree(). | 6710 * It's up to the caller to free the memory with xmlFree(). |
6572 */ | 6711 */ |
6573 xmlChar * | 6712 xmlChar * |
6574 xmlGetNoNsProp(xmlNodePtr node, const xmlChar *name) { | 6713 xmlGetNoNsProp(const xmlNode *node, const xmlChar *name) { |
6575 xmlAttrPtr prop; | 6714 xmlAttrPtr prop; |
6576 | 6715 |
6577 prop = xmlGetPropNodeInternal(node, name, NULL, xmlCheckDTD); | 6716 prop = xmlGetPropNodeInternal(node, name, NULL, xmlCheckDTD); |
6578 if (prop == NULL) | 6717 if (prop == NULL) |
6579 return(NULL); | 6718 return(NULL); |
6580 return(xmlGetPropNodeValueInternal(prop)); | 6719 return(xmlGetPropNodeValueInternal(prop)); |
6581 } | 6720 } |
6582 | 6721 |
6583 /** | 6722 /** |
6584 * xmlGetNsProp: | 6723 * xmlGetNsProp: |
6585 * @node: the node | 6724 * @node: the node |
6586 * @name: the attribute name | 6725 * @name: the attribute name |
6587 * @nameSpace: the URI of the namespace | 6726 * @nameSpace: the URI of the namespace |
6588 * | 6727 * |
6589 * Search and get the value of an attribute associated to a node | 6728 * Search and get the value of an attribute associated to a node |
6590 * This attribute has to be anchored in the namespace specified. | 6729 * This attribute has to be anchored in the namespace specified. |
6591 * This does the entity substitution. | 6730 * This does the entity substitution. |
6592 * This function looks in DTD attribute declaration for #FIXED or | 6731 * This function looks in DTD attribute declaration for #FIXED or |
6593 * default declaration values unless DTD use has been turned off. | 6732 * default declaration values unless DTD use has been turned off. |
6594 * | 6733 * |
6595 * Returns the attribute value or NULL if not found. | 6734 * Returns the attribute value or NULL if not found. |
6596 * It's up to the caller to free the memory with xmlFree(). | 6735 * It's up to the caller to free the memory with xmlFree(). |
6597 */ | 6736 */ |
6598 xmlChar * | 6737 xmlChar * |
6599 xmlGetNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) { | 6738 xmlGetNsProp(const xmlNode *node, const xmlChar *name, const xmlChar *nameSpace)
{ |
6600 xmlAttrPtr prop; | 6739 xmlAttrPtr prop; |
6601 | 6740 |
6602 prop = xmlGetPropNodeInternal(node, name, nameSpace, xmlCheckDTD); | 6741 prop = xmlGetPropNodeInternal(node, name, nameSpace, xmlCheckDTD); |
6603 if (prop == NULL) | 6742 if (prop == NULL) |
6604 return(NULL); | 6743 return(NULL); |
6605 return(xmlGetPropNodeValueInternal(prop)); | 6744 return(xmlGetPropNodeValueInternal(prop)); |
6606 } | 6745 } |
6607 | 6746 |
6608 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) | 6747 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) |
6609 /** | 6748 /** |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6754 #endif /* LIBXML_TREE_ENABLED */ | 6893 #endif /* LIBXML_TREE_ENABLED */ |
6755 | 6894 |
6756 /** | 6895 /** |
6757 * xmlNodeIsText: | 6896 * xmlNodeIsText: |
6758 * @node: the node | 6897 * @node: the node |
6759 * | 6898 * |
6760 * Is this node a Text node ? | 6899 * Is this node a Text node ? |
6761 * Returns 1 yes, 0 no | 6900 * Returns 1 yes, 0 no |
6762 */ | 6901 */ |
6763 int | 6902 int |
6764 xmlNodeIsText(xmlNodePtr node) { | 6903 xmlNodeIsText(const xmlNode *node) { |
6765 if (node == NULL) return(0); | 6904 if (node == NULL) return(0); |
6766 | 6905 |
6767 if (node->type == XML_TEXT_NODE) return(1); | 6906 if (node->type == XML_TEXT_NODE) return(1); |
6768 return(0); | 6907 return(0); |
6769 } | 6908 } |
6770 | 6909 |
6771 /** | 6910 /** |
6772 * xmlIsBlankNode: | 6911 * xmlIsBlankNode: |
6773 * @node: the node | 6912 * @node: the node |
6774 * | 6913 * |
6775 * Checks whether this node is an empty or whitespace only | 6914 * Checks whether this node is an empty or whitespace only |
6776 * (and possibly ignorable) text-node. | 6915 * (and possibly ignorable) text-node. |
6777 * | 6916 * |
6778 * Returns 1 yes, 0 no | 6917 * Returns 1 yes, 0 no |
6779 */ | 6918 */ |
6780 int | 6919 int |
6781 xmlIsBlankNode(xmlNodePtr node) { | 6920 xmlIsBlankNode(const xmlNode *node) { |
6782 const xmlChar *cur; | 6921 const xmlChar *cur; |
6783 if (node == NULL) return(0); | 6922 if (node == NULL) return(0); |
6784 | 6923 |
6785 if ((node->type != XML_TEXT_NODE) && | 6924 if ((node->type != XML_TEXT_NODE) && |
6786 (node->type != XML_CDATA_SECTION_NODE)) | 6925 (node->type != XML_CDATA_SECTION_NODE)) |
6787 return(0); | 6926 return(0); |
6788 if (node->content == NULL) return(1); | 6927 if (node->content == NULL) return(1); |
6789 cur = node->content; | 6928 cur = node->content; |
6790 while (*cur != 0) { | 6929 while (*cur != 0) { |
6791 if (!IS_BLANK_CH(*cur)) return(0); | 6930 if (!IS_BLANK_CH(*cur)) return(0); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6896 return(NULL); | 7035 return(NULL); |
6897 } | 7036 } |
6898 ret->content[0] = 0; | 7037 ret->content[0] = 0; |
6899 } else | 7038 } else |
6900 ret->content = NULL; | 7039 ret->content = NULL; |
6901 ret->contentIO = NULL; | 7040 ret->contentIO = NULL; |
6902 return(ret); | 7041 return(ret); |
6903 } | 7042 } |
6904 | 7043 |
6905 /** | 7044 /** |
| 7045 * xmlBufferDetach: |
| 7046 * @buf: the buffer |
| 7047 * |
| 7048 * Remove the string contained in a buffer and gie it back to the |
| 7049 * caller. The buffer is reset to an empty content. |
| 7050 * This doesn't work with immutable buffers as they can't be reset. |
| 7051 * |
| 7052 * Returns the previous string contained by the buffer. |
| 7053 */ |
| 7054 xmlChar * |
| 7055 xmlBufferDetach(xmlBufferPtr buf) { |
| 7056 xmlChar *ret; |
| 7057 |
| 7058 if (buf == NULL) |
| 7059 return(NULL); |
| 7060 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) |
| 7061 return(NULL); |
| 7062 |
| 7063 ret = buf->content; |
| 7064 buf->content = NULL; |
| 7065 buf->size = 0; |
| 7066 buf->use = 0; |
| 7067 |
| 7068 return ret; |
| 7069 } |
| 7070 |
| 7071 |
| 7072 /** |
6906 * xmlBufferCreateStatic: | 7073 * xmlBufferCreateStatic: |
6907 * @mem: the memory area | 7074 * @mem: the memory area |
6908 * @size: the size in byte | 7075 * @size: the size in byte |
6909 * | 7076 * |
6910 * routine to create an XML buffer from an immutable memory area. | 7077 * routine to create an XML buffer from an immutable memory area. |
6911 * The area won't be modified nor copied, and is expected to be | 7078 * The area won't be modified nor copied, and is expected to be |
6912 * present until the end of the buffer lifetime. | 7079 * present until the end of the buffer lifetime. |
6913 * | 7080 * |
6914 * returns the new structure. | 7081 * returns the new structure. |
6915 */ | 7082 */ |
(...skipping 30 matching lines...) Expand all Loading... |
6946 #ifdef DEBUG_BUFFER | 7113 #ifdef DEBUG_BUFFER |
6947 xmlGenericError(xmlGenericErrorContext, | 7114 xmlGenericError(xmlGenericErrorContext, |
6948 "xmlBufferSetAllocationScheme: buf == NULL\n"); | 7115 "xmlBufferSetAllocationScheme: buf == NULL\n"); |
6949 #endif | 7116 #endif |
6950 return; | 7117 return; |
6951 } | 7118 } |
6952 if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) || | 7119 if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) || |
6953 (buf->alloc == XML_BUFFER_ALLOC_IO)) return; | 7120 (buf->alloc == XML_BUFFER_ALLOC_IO)) return; |
6954 if ((scheme == XML_BUFFER_ALLOC_DOUBLEIT) || | 7121 if ((scheme == XML_BUFFER_ALLOC_DOUBLEIT) || |
6955 (scheme == XML_BUFFER_ALLOC_EXACT) || | 7122 (scheme == XML_BUFFER_ALLOC_EXACT) || |
| 7123 (scheme == XML_BUFFER_ALLOC_HYBRID) || |
6956 (scheme == XML_BUFFER_ALLOC_IMMUTABLE)) | 7124 (scheme == XML_BUFFER_ALLOC_IMMUTABLE)) |
6957 buf->alloc = scheme; | 7125 buf->alloc = scheme; |
6958 } | 7126 } |
6959 | 7127 |
6960 /** | 7128 /** |
6961 * xmlBufferFree: | 7129 * xmlBufferFree: |
6962 * @buf: the buffer to free | 7130 * @buf: the buffer to free |
6963 * | 7131 * |
6964 * Frees an XML buffer. It frees both the content and the structure which | 7132 * Frees an XML buffer. It frees both the content and the structure which |
6965 * encapsulate it. | 7133 * encapsulate it. |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7145 /** | 7313 /** |
7146 * xmlBufferContent: | 7314 * xmlBufferContent: |
7147 * @buf: the buffer | 7315 * @buf: the buffer |
7148 * | 7316 * |
7149 * Function to extract the content of a buffer | 7317 * Function to extract the content of a buffer |
7150 * | 7318 * |
7151 * Returns the internal content | 7319 * Returns the internal content |
7152 */ | 7320 */ |
7153 | 7321 |
7154 const xmlChar * | 7322 const xmlChar * |
7155 xmlBufferContent(const xmlBufferPtr buf) | 7323 xmlBufferContent(const xmlBuffer *buf) |
7156 { | 7324 { |
7157 if(!buf) | 7325 if(!buf) |
7158 return NULL; | 7326 return NULL; |
7159 | 7327 |
7160 return buf->content; | 7328 return buf->content; |
7161 } | 7329 } |
7162 | 7330 |
7163 /** | 7331 /** |
7164 * xmlBufferLength: | 7332 * xmlBufferLength: |
7165 * @buf: the buffer | 7333 * @buf: the buffer |
7166 * | 7334 * |
7167 * Function to get the length of a buffer | 7335 * Function to get the length of a buffer |
7168 * | 7336 * |
7169 * Returns the length of data in the internal content | 7337 * Returns the length of data in the internal content |
7170 */ | 7338 */ |
7171 | 7339 |
7172 int | 7340 int |
7173 xmlBufferLength(const xmlBufferPtr buf) | 7341 xmlBufferLength(const xmlBuffer *buf) |
7174 { | 7342 { |
7175 if(!buf) | 7343 if(!buf) |
7176 return 0; | 7344 return 0; |
7177 | 7345 |
7178 return buf->use; | 7346 return buf->use; |
7179 } | 7347 } |
7180 | 7348 |
7181 /** | 7349 /** |
7182 * xmlBufferResize: | 7350 * xmlBufferResize: |
7183 * @buf: the buffer to resize | 7351 * @buf: the buffer to resize |
(...skipping 29 matching lines...) Expand all Loading... |
7213 if (newSize > UINT_MAX / 2) { | 7381 if (newSize > UINT_MAX / 2) { |
7214 xmlTreeErrMemory("growing buffer"); | 7382 xmlTreeErrMemory("growing buffer"); |
7215 return 0; | 7383 return 0; |
7216 } | 7384 } |
7217 newSize *= 2; | 7385 newSize *= 2; |
7218 } | 7386 } |
7219 break; | 7387 break; |
7220 case XML_BUFFER_ALLOC_EXACT: | 7388 case XML_BUFFER_ALLOC_EXACT: |
7221 newSize = size+10; | 7389 newSize = size+10; |
7222 break; | 7390 break; |
| 7391 case XML_BUFFER_ALLOC_HYBRID: |
| 7392 if (buf->use < BASE_BUFFER_SIZE) |
| 7393 newSize = size; |
| 7394 else { |
| 7395 newSize = buf->size * 2; |
| 7396 while (size > newSize) { |
| 7397 if (newSize > UINT_MAX / 2) { |
| 7398 xmlTreeErrMemory("growing buffer"); |
| 7399 return 0; |
| 7400 } |
| 7401 newSize *= 2; |
| 7402 } |
| 7403 } |
| 7404 break; |
| 7405 |
7223 default: | 7406 default: |
7224 newSize = size+10; | 7407 newSize = size+10; |
7225 break; | 7408 break; |
7226 } | 7409 } |
7227 | 7410 |
7228 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { | 7411 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { |
7229 start_buf = buf->content - buf->contentIO; | 7412 start_buf = buf->content - buf->contentIO; |
7230 | 7413 |
7231 if (start_buf > newSize) { | 7414 if (start_buf > newSize) { |
7232 /* move data back to start */ | 7415 /* move data back to start */ |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7532 | 7715 |
7533 | 7716 |
7534 /** | 7717 /** |
7535 * xmlGetDocCompressMode: | 7718 * xmlGetDocCompressMode: |
7536 * @doc: the document | 7719 * @doc: the document |
7537 * | 7720 * |
7538 * get the compression ratio for a document, ZLIB based | 7721 * get the compression ratio for a document, ZLIB based |
7539 * Returns 0 (uncompressed) to 9 (max compression) | 7722 * Returns 0 (uncompressed) to 9 (max compression) |
7540 */ | 7723 */ |
7541 int | 7724 int |
7542 xmlGetDocCompressMode (xmlDocPtr doc) { | 7725 xmlGetDocCompressMode (const xmlDoc *doc) { |
7543 if (doc == NULL) return(-1); | 7726 if (doc == NULL) return(-1); |
7544 return(doc->compression); | 7727 return(doc->compression); |
7545 } | 7728 } |
7546 | 7729 |
7547 /** | 7730 /** |
7548 * xmlSetDocCompressMode: | 7731 * xmlSetDocCompressMode: |
7549 * @doc: the document | 7732 * @doc: the document |
7550 * @mode: the compression ratio | 7733 * @mode: the compression ratio |
7551 * | 7734 * |
7552 * set the compression ratio for a document, ZLIB based | 7735 * set the compression ratio for a document, ZLIB based |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7723 ret->prev = map->last; | 7906 ret->prev = map->last; |
7724 map->last->next = ret; | 7907 map->last->next = ret; |
7725 map->last = ret; | 7908 map->last = ret; |
7726 } else if (position == 0) { | 7909 } else if (position == 0) { |
7727 /* | 7910 /* |
7728 * Set on first position. | 7911 * Set on first position. |
7729 */ | 7912 */ |
7730 map->first->prev = ret; | 7913 map->first->prev = ret; |
7731 ret->next = map->first; | 7914 ret->next = map->first; |
7732 map->first = ret; | 7915 map->first = ret; |
7733 } else | 7916 } |
7734 » return(NULL); | |
7735 | 7917 |
7736 ret->oldNs = oldNs; | 7918 ret->oldNs = oldNs; |
7737 ret->newNs = newNs; | 7919 ret->newNs = newNs; |
7738 ret->shadowDepth = -1; | 7920 ret->shadowDepth = -1; |
7739 ret->depth = depth; | 7921 ret->depth = depth; |
7740 return (ret); | 7922 return (ret); |
7741 } | 7923 } |
7742 | 7924 |
7743 /* | 7925 /* |
7744 * xmlDOMWrapStoreNs: | 7926 * xmlDOMWrapStoreNs: |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7784 return (ns->next); | 7966 return (ns->next); |
7785 } | 7967 } |
7786 return(NULL); | 7968 return(NULL); |
7787 } | 7969 } |
7788 | 7970 |
7789 /* | 7971 /* |
7790 * xmlDOMWrapNewCtxt: | 7972 * xmlDOMWrapNewCtxt: |
7791 * | 7973 * |
7792 * Allocates and initializes a new DOM-wrapper context. | 7974 * Allocates and initializes a new DOM-wrapper context. |
7793 * | 7975 * |
7794 * Returns the xmlDOMWrapCtxtPtr or NULL in case of an internal errror. | 7976 * Returns the xmlDOMWrapCtxtPtr or NULL in case of an internal error. |
7795 */ | 7977 */ |
7796 xmlDOMWrapCtxtPtr | 7978 xmlDOMWrapCtxtPtr |
7797 xmlDOMWrapNewCtxt(void) | 7979 xmlDOMWrapNewCtxt(void) |
7798 { | 7980 { |
7799 xmlDOMWrapCtxtPtr ret; | 7981 xmlDOMWrapCtxtPtr ret; |
7800 | 7982 |
7801 ret = xmlMalloc(sizeof(xmlDOMWrapCtxt)); | 7983 ret = xmlMalloc(sizeof(xmlDOMWrapCtxt)); |
7802 if (ret == NULL) { | 7984 if (ret == NULL) { |
7803 xmlTreeErrMemory("allocating DOM-wrapper context"); | 7985 xmlTreeErrMemory("allocating DOM-wrapper context"); |
7804 return (NULL); | 7986 return (NULL); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7869 xmlDOMWrapNSNormGatherInScopeNs(xmlNsMapPtr *map, | 8051 xmlDOMWrapNSNormGatherInScopeNs(xmlNsMapPtr *map, |
7870 xmlNodePtr node) | 8052 xmlNodePtr node) |
7871 { | 8053 { |
7872 xmlNodePtr cur; | 8054 xmlNodePtr cur; |
7873 xmlNsPtr ns; | 8055 xmlNsPtr ns; |
7874 xmlNsMapItemPtr mi; | 8056 xmlNsMapItemPtr mi; |
7875 int shadowed; | 8057 int shadowed; |
7876 | 8058 |
7877 if ((map == NULL) || (*map != NULL)) | 8059 if ((map == NULL) || (*map != NULL)) |
7878 return (-1); | 8060 return (-1); |
| 8061 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) |
| 8062 return (-1); |
7879 /* | 8063 /* |
7880 * Get in-scope ns-decls of @parent. | 8064 * Get in-scope ns-decls of @parent. |
7881 */ | 8065 */ |
7882 cur = node; | 8066 cur = node; |
7883 while ((cur != NULL) && (cur != (xmlNodePtr) cur->doc)) { | 8067 while ((cur != NULL) && (cur != (xmlNodePtr) cur->doc)) { |
7884 if (cur->type == XML_ELEMENT_NODE) { | 8068 if (cur->type == XML_ELEMENT_NODE) { |
7885 if (cur->nsDef != NULL) { | 8069 if (cur->nsDef != NULL) { |
7886 ns = cur->nsDef; | 8070 ns = cur->nsDef; |
7887 do { | 8071 do { |
7888 shadowed = 0; | 8072 shadowed = 0; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8136 static int | 8320 static int |
8137 xmlSearchNsByNamespaceStrict(xmlDocPtr doc, xmlNodePtr node, | 8321 xmlSearchNsByNamespaceStrict(xmlDocPtr doc, xmlNodePtr node, |
8138 const xmlChar* nsName, | 8322 const xmlChar* nsName, |
8139 xmlNsPtr *retNs, int prefixed) | 8323 xmlNsPtr *retNs, int prefixed) |
8140 { | 8324 { |
8141 xmlNodePtr cur, prev = NULL, out = NULL; | 8325 xmlNodePtr cur, prev = NULL, out = NULL; |
8142 xmlNsPtr ns, prevns; | 8326 xmlNsPtr ns, prevns; |
8143 | 8327 |
8144 if ((doc == NULL) || (nsName == NULL) || (retNs == NULL)) | 8328 if ((doc == NULL) || (nsName == NULL) || (retNs == NULL)) |
8145 return (-1); | 8329 return (-1); |
| 8330 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) |
| 8331 return(-1); |
8146 | 8332 |
8147 *retNs = NULL; | 8333 *retNs = NULL; |
8148 if (xmlStrEqual(nsName, XML_XML_NAMESPACE)) { | 8334 if (xmlStrEqual(nsName, XML_XML_NAMESPACE)) { |
8149 *retNs = xmlTreeEnsureXMLDecl(doc); | 8335 *retNs = xmlTreeEnsureXMLDecl(doc); |
8150 if (*retNs == NULL) | 8336 if (*retNs == NULL) |
8151 return (-1); | 8337 return (-1); |
8152 return (1); | 8338 return (1); |
8153 } | 8339 } |
8154 cur = node; | 8340 cur = node; |
8155 do { | 8341 do { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8234 * and internal errors. | 8420 * and internal errors. |
8235 */ | 8421 */ |
8236 static int | 8422 static int |
8237 xmlSearchNsByPrefixStrict(xmlDocPtr doc, xmlNodePtr node, | 8423 xmlSearchNsByPrefixStrict(xmlDocPtr doc, xmlNodePtr node, |
8238 const xmlChar* prefix, | 8424 const xmlChar* prefix, |
8239 xmlNsPtr *retNs) | 8425 xmlNsPtr *retNs) |
8240 { | 8426 { |
8241 xmlNodePtr cur; | 8427 xmlNodePtr cur; |
8242 xmlNsPtr ns; | 8428 xmlNsPtr ns; |
8243 | 8429 |
8244 if ((doc == NULL) || (node == NULL)) | 8430 if ((doc == NULL) || (node == NULL) || (node->type == XML_NAMESPACE_DECL)) |
8245 » return (-1); | 8431 return(-1); |
8246 | 8432 |
8247 if (retNs) | 8433 if (retNs) |
8248 *retNs = NULL; | 8434 *retNs = NULL; |
8249 if (IS_STR_XML(prefix)) { | 8435 if (IS_STR_XML(prefix)) { |
8250 if (retNs) { | 8436 if (retNs) { |
8251 *retNs = xmlTreeEnsureXMLDecl(doc); | 8437 *retNs = xmlTreeEnsureXMLDecl(doc); |
8252 if (*retNs == NULL) | 8438 if (*retNs == NULL) |
8253 return (-1); | 8439 return (-1); |
8254 } | 8440 } |
8255 return (1); | 8441 return (1); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8303 xmlNodePtr elem, | 8489 xmlNodePtr elem, |
8304 const xmlChar *nsName, | 8490 const xmlChar *nsName, |
8305 const xmlChar *prefix, | 8491 const xmlChar *prefix, |
8306 int checkShadow) | 8492 int checkShadow) |
8307 { | 8493 { |
8308 | 8494 |
8309 xmlNsPtr ret; | 8495 xmlNsPtr ret; |
8310 char buf[50]; | 8496 char buf[50]; |
8311 const xmlChar *pref; | 8497 const xmlChar *pref; |
8312 int counter = 0; | 8498 int counter = 0; |
| 8499 |
| 8500 if ((doc == NULL) || (elem == NULL) || (elem->type != XML_ELEMENT_NODE)) |
| 8501 return(NULL); |
8313 /* | 8502 /* |
8314 * Create a ns-decl on @anchor. | 8503 * Create a ns-decl on @anchor. |
8315 */ | 8504 */ |
8316 pref = prefix; | 8505 pref = prefix; |
8317 while (1) { | 8506 while (1) { |
8318 /* | 8507 /* |
8319 * Lookup whether the prefix is unused in elem's ns-decls. | 8508 * Lookup whether the prefix is unused in elem's ns-decls. |
8320 */ | 8509 */ |
8321 if ((elem->nsDef != NULL) && | 8510 if ((elem->nsDef != NULL) && |
8322 (xmlTreeNSListLookupByPrefix(elem->nsDef, pref) != NULL)) | 8511 (xmlTreeNSListLookupByPrefix(elem->nsDef, pref) != NULL)) |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8819 * 2) custom ns-reference handling is used | 9008 * 2) custom ns-reference handling is used |
8820 */ | 9009 */ |
8821 if ((destParent == NULL) || | 9010 if ((destParent == NULL) || |
8822 (ctxt && ctxt->getNsForNodeFunc)) | 9011 (ctxt && ctxt->getNsForNodeFunc)) |
8823 { | 9012 { |
8824 parnsdone = 1; | 9013 parnsdone = 1; |
8825 } else | 9014 } else |
8826 parnsdone = 0; | 9015 parnsdone = 0; |
8827 | 9016 |
8828 cur = node; | 9017 cur = node; |
| 9018 if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) |
| 9019 goto internal_error; |
| 9020 |
8829 while (cur != NULL) { | 9021 while (cur != NULL) { |
8830 /* | 9022 /* |
8831 * Paranoid source-doc sanity check. | 9023 * Paranoid source-doc sanity check. |
8832 */ | 9024 */ |
8833 if (cur->doc != sourceDoc) { | 9025 if (cur->doc != sourceDoc) { |
8834 /* | 9026 /* |
8835 * We'll assume XIncluded nodes if the doc differs. | 9027 * We'll assume XIncluded nodes if the doc differs. |
8836 * TODO: Do we need to reconciliate XIncluded nodes? | 9028 * TODO: Do we need to reconciliate XIncluded nodes? |
8837 * This here skips XIncluded nodes and tries to handle | 9029 * This here skips XIncluded nodes and tries to handle |
8838 * broken sequences. | 9030 * broken sequences. |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9198 dict = destDoc->dict; | 9390 dict = destDoc->dict; |
9199 /* | 9391 /* |
9200 * Reuse the namespace map of the context. | 9392 * Reuse the namespace map of the context. |
9201 */ | 9393 */ |
9202 if (ctxt) | 9394 if (ctxt) |
9203 nsMap = (xmlNsMapPtr) ctxt->namespaceMap; | 9395 nsMap = (xmlNsMapPtr) ctxt->namespaceMap; |
9204 | 9396 |
9205 *resNode = NULL; | 9397 *resNode = NULL; |
9206 | 9398 |
9207 cur = node; | 9399 cur = node; |
| 9400 if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) |
| 9401 return(-1); |
| 9402 |
9208 while (cur != NULL) { | 9403 while (cur != NULL) { |
9209 if (cur->doc != sourceDoc) { | 9404 if (cur->doc != sourceDoc) { |
9210 /* | 9405 /* |
9211 * We'll assume XIncluded nodes if the doc differs. | 9406 * We'll assume XIncluded nodes if the doc differs. |
9212 * TODO: Do we need to reconciliate XIncluded nodes? | 9407 * TODO: Do we need to reconciliate XIncluded nodes? |
9213 * TODO: This here returns -1 in this case. | 9408 * TODO: This here returns -1 in this case. |
9214 */ | 9409 */ |
9215 goto internal_error; | 9410 goto internal_error; |
9216 } | 9411 } |
9217 /* | 9412 /* |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9596 if (cur->next != NULL) { | 9791 if (cur->next != NULL) { |
9597 prevClone = clone; | 9792 prevClone = clone; |
9598 cur = cur->next; | 9793 cur = cur->next; |
9599 } else if (cur->type != XML_ATTRIBUTE_NODE) { | 9794 } else if (cur->type != XML_ATTRIBUTE_NODE) { |
9600 /* | 9795 /* |
9601 * Set clone->last. | 9796 * Set clone->last. |
9602 */ | 9797 */ |
9603 if (clone->parent != NULL) | 9798 if (clone->parent != NULL) |
9604 clone->parent->last = clone; | 9799 clone->parent->last = clone; |
9605 clone = clone->parent; | 9800 clone = clone->parent; |
9606 » parentClone = clone->parent; | 9801 » if (clone != NULL) |
| 9802 » » parentClone = clone->parent; |
9607 /* | 9803 /* |
9608 * Process parent --> next; | 9804 * Process parent --> next; |
9609 */ | 9805 */ |
9610 cur = cur->parent; | 9806 cur = cur->parent; |
9611 goto leave_node; | 9807 goto leave_node; |
9612 } else { | 9808 } else { |
9613 /* This is for attributes only. */ | 9809 /* This is for attributes only. */ |
9614 clone = clone->parent; | 9810 clone = clone->parent; |
9615 parentClone = clone->parent; | 9811 parentClone = clone->parent; |
9616 /* | 9812 /* |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9715 | 9911 |
9716 XML_TREE_ADOPT_STR(attr->name); | 9912 XML_TREE_ADOPT_STR(attr->name); |
9717 attr->atype = 0; | 9913 attr->atype = 0; |
9718 attr->psvi = NULL; | 9914 attr->psvi = NULL; |
9719 /* | 9915 /* |
9720 * Walk content. | 9916 * Walk content. |
9721 */ | 9917 */ |
9722 if (attr->children == NULL) | 9918 if (attr->children == NULL) |
9723 return (0); | 9919 return (0); |
9724 cur = attr->children; | 9920 cur = attr->children; |
| 9921 if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) |
| 9922 goto internal_error; |
9725 while (cur != NULL) { | 9923 while (cur != NULL) { |
9726 cur->doc = destDoc; | 9924 cur->doc = destDoc; |
9727 switch (cur->type) { | 9925 switch (cur->type) { |
9728 case XML_TEXT_NODE: | 9926 case XML_TEXT_NODE: |
9729 case XML_CDATA_SECTION_NODE: | 9927 case XML_CDATA_SECTION_NODE: |
9730 XML_TREE_ADOPT_STR_2(cur->content) | 9928 XML_TREE_ADOPT_STR_2(cur->content) |
9731 break; | 9929 break; |
9732 case XML_ENTITY_REF_NODE: | 9930 case XML_ENTITY_REF_NODE: |
9733 /* | 9931 /* |
9734 * Remove reference to the entitity-node. | 9932 * Remove reference to the entitity-node. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9776 * @ctxt: the optional context for custom processing | 9974 * @ctxt: the optional context for custom processing |
9777 * @sourceDoc: the optional sourceDoc | 9975 * @sourceDoc: the optional sourceDoc |
9778 * @node: the node to start with | 9976 * @node: the node to start with |
9779 * @destDoc: the destination doc | 9977 * @destDoc: the destination doc |
9780 * @destParent: the optional new parent of @node in @destDoc | 9978 * @destParent: the optional new parent of @node in @destDoc |
9781 * @options: option flags | 9979 * @options: option flags |
9782 * | 9980 * |
9783 * References of out-of scope ns-decls are remapped to point to @destDoc: | 9981 * References of out-of scope ns-decls are remapped to point to @destDoc: |
9784 * 1) If @destParent is given, then nsDef entries on element-nodes are used | 9982 * 1) If @destParent is given, then nsDef entries on element-nodes are used |
9785 * 2) If *no* @destParent is given, then @destDoc->oldNs entries are used | 9983 * 2) If *no* @destParent is given, then @destDoc->oldNs entries are used |
9786 * This is the case when you have an unliked node and just want to move it | 9984 * This is the case when you have an unlinked node and just want to move it |
9787 * to the context of | 9985 * to the context of |
9788 * | 9986 * |
9789 * If @destParent is given, it ensures that the tree is namespace | 9987 * If @destParent is given, it ensures that the tree is namespace |
9790 * wellformed by creating additional ns-decls where needed. | 9988 * wellformed by creating additional ns-decls where needed. |
9791 * Note that, since prefixes of already existent ns-decls can be | 9989 * Note that, since prefixes of already existent ns-decls can be |
9792 * shadowed by this process, it could break QNames in attribute | 9990 * shadowed by this process, it could break QNames in attribute |
9793 * values or element content. | 9991 * values or element content. |
9794 * NOTE: This function was not intensively tested. | 9992 * NOTE: This function was not intensively tested. |
9795 * | 9993 * |
9796 * Returns 0 if the operation succeeded, | 9994 * Returns 0 if the operation succeeded, |
9797 * 1 if a node of unsupported type was given, | 9995 * 1 if a node of unsupported type was given, |
9798 * 2 if a node of not yet supported type was given and | 9996 * 2 if a node of not yet supported type was given and |
9799 * -1 on API/internal errors. | 9997 * -1 on API/internal errors. |
9800 */ | 9998 */ |
9801 int | 9999 int |
9802 xmlDOMWrapAdoptNode(xmlDOMWrapCtxtPtr ctxt, | 10000 xmlDOMWrapAdoptNode(xmlDOMWrapCtxtPtr ctxt, |
9803 xmlDocPtr sourceDoc, | 10001 xmlDocPtr sourceDoc, |
9804 xmlNodePtr node, | 10002 xmlNodePtr node, |
9805 xmlDocPtr destDoc, | 10003 xmlDocPtr destDoc, |
9806 xmlNodePtr destParent, | 10004 xmlNodePtr destParent, |
9807 int options) | 10005 int options) |
9808 { | 10006 { |
9809 if ((node == NULL) || (destDoc == NULL) || | 10007 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) || |
| 10008 (destDoc == NULL) || |
9810 ((destParent != NULL) && (destParent->doc != destDoc))) | 10009 ((destParent != NULL) && (destParent->doc != destDoc))) |
9811 return(-1); | 10010 return(-1); |
9812 /* | 10011 /* |
9813 * Check node->doc sanity. | 10012 * Check node->doc sanity. |
9814 */ | 10013 */ |
9815 if ((node->doc != NULL) && (sourceDoc != NULL) && | 10014 if ((node->doc != NULL) && (sourceDoc != NULL) && |
9816 (node->doc != sourceDoc)) { | 10015 (node->doc != sourceDoc)) { |
9817 /* | 10016 /* |
9818 * Might be an XIncluded node. | 10017 * Might be an XIncluded node. |
9819 */ | 10018 */ |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9894 } | 10093 } |
9895 default: | 10094 default: |
9896 break; | 10095 break; |
9897 } | 10096 } |
9898 } | 10097 } |
9899 return (0); | 10098 return (0); |
9900 } | 10099 } |
9901 | 10100 |
9902 #define bottom_tree | 10101 #define bottom_tree |
9903 #include "elfgcchack.h" | 10102 #include "elfgcchack.h" |
OLD | NEW |