Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: third_party/libxml/src/tree.c

Issue 1193533007: Upgrade to libxml 2.9.2 and libxslt 1.1.28 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove suppressions, have landed in blink now Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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
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
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
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
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
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 » ret = node;
1420 } else { 1455 } else {
1421 » node = xmlNewDocTextLen(doc, q, cur - q); 1456 » 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
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 » ret = node;
1603 } else { 1643 } else {
1604 » node = xmlNewDocTextLen(doc, q, cur - q); 1644 » 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
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
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
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
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) {
2802 if (prop->atype == XML_ATTRIBUTE_ID) {
2803 xmlRemoveID(tree->doc, prop);
2804 }
2805
2757 prop->doc = doc; 2806 prop->doc = doc;
2758 xmlSetListDoc(prop->children, doc); 2807 xmlSetListDoc(prop->children, doc);
2808
2809 /*
2810 * TODO: ID attributes should be also added to the new
2811 * document, but this breaks things like xmlReplaceNode.
2812 * The underlying problem is that xmlRemoveID is only called
2813 * if a node is destroyed, not if it's unlinked.
2814 */
2815 #if 0
2816 if (xmlIsID(doc, tree, prop)) {
2817 xmlChar *idVal = xmlNodeListGetString(doc, prop->children,
2818 1);
2819 xmlAddID(NULL, doc, idVal, prop);
2820 }
2821 #endif
2822
2759 prop = prop->next; 2823 prop = prop->next;
2760 } 2824 }
2761 } 2825 }
2762 if (tree->children != NULL) 2826 if (tree->children != NULL)
2763 xmlSetListDoc(tree->children, doc); 2827 xmlSetListDoc(tree->children, doc);
2764 tree->doc = doc; 2828 tree->doc = doc;
2765 } 2829 }
2766 } 2830 }
2767 2831
2768 /** 2832 /**
2769 * xmlSetListDoc: 2833 * xmlSetListDoc:
2770 * @list: the first element 2834 * @list: the first element
2771 * @doc: the document 2835 * @doc: the document
2772 * 2836 *
2773 * update all nodes in the list to point to the right document 2837 * update all nodes in the list to point to the right document
2774 */ 2838 */
2775 void 2839 void
2776 xmlSetListDoc(xmlNodePtr list, xmlDocPtr doc) { 2840 xmlSetListDoc(xmlNodePtr list, xmlDocPtr doc) {
2777 xmlNodePtr cur; 2841 xmlNodePtr cur;
2778 2842
2779 if (list == NULL) 2843 if ((list == NULL) || (list->type == XML_NAMESPACE_DECL))
2780 return; 2844 return;
2781 cur = list; 2845 cur = list;
2782 while (cur != NULL) { 2846 while (cur != NULL) {
2783 if (cur->doc != doc) 2847 if (cur->doc != doc)
2784 xmlSetTreeDoc(cur, doc); 2848 xmlSetTreeDoc(cur, doc);
2785 cur = cur->next; 2849 cur = cur->next;
2786 } 2850 }
2787 } 2851 }
2788 2852
2789 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) 2853 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2876 * When inserting before @cur, @prev is passed as @cur->prev. 2940 * When inserting before @cur, @prev is passed as @cur->prev.
2877 * When inserting after @cur, @prev is passed as @cur. 2941 * When inserting after @cur, @prev is passed as @cur.
2878 * If an existing attribute is found it is detroyed prior to adding @prop. 2942 * If an existing attribute is found it is detroyed prior to adding @prop.
2879 * 2943 *
2880 * Returns the attribute being inserted or NULL in case of error. 2944 * Returns the attribute being inserted or NULL in case of error.
2881 */ 2945 */
2882 static xmlNodePtr 2946 static xmlNodePtr
2883 xmlAddPropSibling(xmlNodePtr prev, xmlNodePtr cur, xmlNodePtr prop) { 2947 xmlAddPropSibling(xmlNodePtr prev, xmlNodePtr cur, xmlNodePtr prop) {
2884 xmlAttrPtr attr; 2948 xmlAttrPtr attr;
2885 2949
2886 » if (cur->type != XML_ATTRIBUTE_NODE) 2950 » if ((cur == NULL) || (cur->type != XML_ATTRIBUTE_NODE) ||
2951 » (prop == NULL) || (prop->type != XML_ATTRIBUTE_NODE) ||
2952 » ((prev != NULL) && (prev->type != XML_ATTRIBUTE_NODE)))
2887 return(NULL); 2953 return(NULL);
2888 2954
2889 /* check if an attribute with the same name exists */ 2955 /* check if an attribute with the same name exists */
2890 if (prop->ns == NULL) 2956 if (prop->ns == NULL)
2891 attr = xmlHasNsProp(cur->parent, prop->name, NULL); 2957 attr = xmlHasNsProp(cur->parent, prop->name, NULL);
2892 else 2958 else
2893 attr = xmlHasNsProp(cur->parent, prop->name, prop->ns->href); 2959 attr = xmlHasNsProp(cur->parent, prop->name, prop->ns->href);
2894 2960
2895 if (prop->doc != cur->doc) { 2961 if (prop->doc != cur->doc) {
2896 xmlSetTreeDoc(prop, cur->doc); 2962 xmlSetTreeDoc(prop, cur->doc);
(...skipping 27 matching lines...) Expand all
2924 * If the new node was already inserted in a document it is 2990 * If the new node was already inserted in a document it is
2925 * first unlinked from its existing context. 2991 * first unlinked from its existing context.
2926 * As a result of text merging @elem may be freed. 2992 * 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 . 2993 * 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. 2994 * If there is an attribute with equal name, it is first destroyed.
2929 * 2995 *
2930 * Returns the new node or NULL in case of error. 2996 * Returns the new node or NULL in case of error.
2931 */ 2997 */
2932 xmlNodePtr 2998 xmlNodePtr
2933 xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) { 2999 xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) {
2934 if (cur == NULL) { 3000 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) {
2935 #ifdef DEBUG_TREE 3001 #ifdef DEBUG_TREE
2936 xmlGenericError(xmlGenericErrorContext, 3002 xmlGenericError(xmlGenericErrorContext,
2937 "xmlAddNextSibling : cur == NULL\n"); 3003 "xmlAddNextSibling : cur == NULL\n");
2938 #endif 3004 #endif
2939 return(NULL); 3005 return(NULL);
2940 } 3006 }
2941 if (elem == NULL) { 3007 if ((elem == NULL) || (elem->type == XML_NAMESPACE_DECL)) {
2942 #ifdef DEBUG_TREE 3008 #ifdef DEBUG_TREE
2943 xmlGenericError(xmlGenericErrorContext, 3009 xmlGenericError(xmlGenericErrorContext,
2944 "xmlAddNextSibling : elem == NULL\n"); 3010 "xmlAddNextSibling : elem == NULL\n");
2945 #endif 3011 #endif
2946 return(NULL); 3012 return(NULL);
2947 } 3013 }
2948 3014
2949 if (cur == elem) { 3015 if (cur == elem) {
2950 #ifdef DEBUG_TREE 3016 #ifdef DEBUG_TREE
2951 xmlGenericError(xmlGenericErrorContext, 3017 xmlGenericError(xmlGenericErrorContext,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2985 elem->next = cur->next; 3051 elem->next = cur->next;
2986 cur->next = elem; 3052 cur->next = elem;
2987 if (elem->next != NULL) 3053 if (elem->next != NULL)
2988 elem->next->prev = elem; 3054 elem->next->prev = elem;
2989 if ((elem->parent != NULL) && (elem->parent->last == cur)) 3055 if ((elem->parent != NULL) && (elem->parent->last == cur))
2990 elem->parent->last = elem; 3056 elem->parent->last = elem;
2991 return(elem); 3057 return(elem);
2992 } 3058 }
2993 3059
2994 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_HTML_ENABLED) || \ 3060 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_HTML_ENABLED) || \
2995 defined(LIBXML_SCHEMAS_ENABLED) 3061 defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED)
2996 /** 3062 /**
2997 * xmlAddPrevSibling: 3063 * xmlAddPrevSibling:
2998 * @cur: the child node 3064 * @cur: the child node
2999 * @elem: the new node 3065 * @elem: the new node
3000 * 3066 *
3001 * Add a new node @elem as the previous sibling of @cur 3067 * Add a new node @elem as the previous sibling of @cur
3002 * merging adjacent TEXT nodes (@elem may be freed) 3068 * merging adjacent TEXT nodes (@elem may be freed)
3003 * If the new node was already inserted in a document it is 3069 * If the new node was already inserted in a document it is
3004 * first unlinked from its existing context. 3070 * first unlinked from its existing context.
3005 * If the new node is ATTRIBUTE, it is added into properties instead of children . 3071 * 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. 3072 * If there is an attribute with equal name, it is first destroyed.
3007 * 3073 *
3008 * Returns the new node or NULL in case of error. 3074 * Returns the new node or NULL in case of error.
3009 */ 3075 */
3010 xmlNodePtr 3076 xmlNodePtr
3011 xmlAddPrevSibling(xmlNodePtr cur, xmlNodePtr elem) { 3077 xmlAddPrevSibling(xmlNodePtr cur, xmlNodePtr elem) {
3012 if (cur == NULL) { 3078 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) {
3013 #ifdef DEBUG_TREE 3079 #ifdef DEBUG_TREE
3014 xmlGenericError(xmlGenericErrorContext, 3080 xmlGenericError(xmlGenericErrorContext,
3015 "xmlAddPrevSibling : cur == NULL\n"); 3081 "xmlAddPrevSibling : cur == NULL\n");
3016 #endif 3082 #endif
3017 return(NULL); 3083 return(NULL);
3018 } 3084 }
3019 if (elem == NULL) { 3085 if ((elem == NULL) || (elem->type == XML_NAMESPACE_DECL)) {
3020 #ifdef DEBUG_TREE 3086 #ifdef DEBUG_TREE
3021 xmlGenericError(xmlGenericErrorContext, 3087 xmlGenericError(xmlGenericErrorContext,
3022 "xmlAddPrevSibling : elem == NULL\n"); 3088 "xmlAddPrevSibling : elem == NULL\n");
3023 #endif 3089 #endif
3024 return(NULL); 3090 return(NULL);
3025 } 3091 }
3026 3092
3027 if (cur == elem) { 3093 if (cur == elem) {
3028 #ifdef DEBUG_TREE 3094 #ifdef DEBUG_TREE
3029 xmlGenericError(xmlGenericErrorContext, 3095 xmlGenericError(xmlGenericErrorContext,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
3080 * merging adjacent TEXT nodes (@elem may be freed) 3146 * merging adjacent TEXT nodes (@elem may be freed)
3081 * If the new element was already inserted in a document it is 3147 * If the new element was already inserted in a document it is
3082 * first unlinked from its existing context. 3148 * first unlinked from its existing context.
3083 * 3149 *
3084 * Returns the new element or NULL in case of error. 3150 * Returns the new element or NULL in case of error.
3085 */ 3151 */
3086 xmlNodePtr 3152 xmlNodePtr
3087 xmlAddSibling(xmlNodePtr cur, xmlNodePtr elem) { 3153 xmlAddSibling(xmlNodePtr cur, xmlNodePtr elem) {
3088 xmlNodePtr parent; 3154 xmlNodePtr parent;
3089 3155
3090 if (cur == NULL) { 3156 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) {
3091 #ifdef DEBUG_TREE 3157 #ifdef DEBUG_TREE
3092 xmlGenericError(xmlGenericErrorContext, 3158 xmlGenericError(xmlGenericErrorContext,
3093 "xmlAddSibling : cur == NULL\n"); 3159 "xmlAddSibling : cur == NULL\n");
3094 #endif 3160 #endif
3095 return(NULL); 3161 return(NULL);
3096 } 3162 }
3097 3163
3098 if (elem == NULL) { 3164 if ((elem == NULL) || (elem->type == XML_NAMESPACE_DECL)) {
3099 #ifdef DEBUG_TREE 3165 #ifdef DEBUG_TREE
3100 xmlGenericError(xmlGenericErrorContext, 3166 xmlGenericError(xmlGenericErrorContext,
3101 "xmlAddSibling : elem == NULL\n"); 3167 "xmlAddSibling : elem == NULL\n");
3102 #endif 3168 #endif
3103 return(NULL); 3169 return(NULL);
3104 } 3170 }
3105 3171
3106 if (cur == elem) { 3172 if (cur == elem) {
3107 #ifdef DEBUG_TREE 3173 #ifdef DEBUG_TREE
3108 xmlGenericError(xmlGenericErrorContext, 3174 xmlGenericError(xmlGenericErrorContext,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
3156 * 3222 *
3157 * Add a list of node at the end of the child list of the parent 3223 * Add a list of node at the end of the child list of the parent
3158 * merging adjacent TEXT nodes (@cur may be freed) 3224 * merging adjacent TEXT nodes (@cur may be freed)
3159 * 3225 *
3160 * Returns the last child or NULL in case of error. 3226 * Returns the last child or NULL in case of error.
3161 */ 3227 */
3162 xmlNodePtr 3228 xmlNodePtr
3163 xmlAddChildList(xmlNodePtr parent, xmlNodePtr cur) { 3229 xmlAddChildList(xmlNodePtr parent, xmlNodePtr cur) {
3164 xmlNodePtr prev; 3230 xmlNodePtr prev;
3165 3231
3166 if (parent == NULL) { 3232 if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) {
3167 #ifdef DEBUG_TREE 3233 #ifdef DEBUG_TREE
3168 xmlGenericError(xmlGenericErrorContext, 3234 xmlGenericError(xmlGenericErrorContext,
3169 "xmlAddChildList : parent == NULL\n"); 3235 "xmlAddChildList : parent == NULL\n");
3170 #endif 3236 #endif
3171 return(NULL); 3237 return(NULL);
3172 } 3238 }
3173 3239
3174 if (cur == NULL) { 3240 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) {
3175 #ifdef DEBUG_TREE 3241 #ifdef DEBUG_TREE
3176 xmlGenericError(xmlGenericErrorContext, 3242 xmlGenericError(xmlGenericErrorContext,
3177 "xmlAddChildList : child == NULL\n"); 3243 "xmlAddChildList : child == NULL\n");
3178 #endif 3244 #endif
3179 return(NULL); 3245 return(NULL);
3180 } 3246 }
3181 3247
3182 if ((cur->doc != NULL) && (parent->doc != NULL) && 3248 if ((cur->doc != NULL) && (parent->doc != NULL) &&
3183 (cur->doc != parent->doc)) { 3249 (cur->doc != parent->doc)) {
3184 #ifdef DEBUG_TREE 3250 #ifdef DEBUG_TREE
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3242 * merging adjacent TEXT nodes (in which case @cur is freed) 3308 * 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 . 3309 * 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. 3310 * If there is an attribute with equal name, it is first destroyed.
3245 * 3311 *
3246 * Returns the child or NULL in case of error. 3312 * Returns the child or NULL in case of error.
3247 */ 3313 */
3248 xmlNodePtr 3314 xmlNodePtr
3249 xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { 3315 xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) {
3250 xmlNodePtr prev; 3316 xmlNodePtr prev;
3251 3317
3252 if (parent == NULL) { 3318 if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) {
3253 #ifdef DEBUG_TREE 3319 #ifdef DEBUG_TREE
3254 xmlGenericError(xmlGenericErrorContext, 3320 xmlGenericError(xmlGenericErrorContext,
3255 "xmlAddChild : parent == NULL\n"); 3321 "xmlAddChild : parent == NULL\n");
3256 #endif 3322 #endif
3257 return(NULL); 3323 return(NULL);
3258 } 3324 }
3259 3325
3260 if (cur == NULL) { 3326 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) {
3261 #ifdef DEBUG_TREE 3327 #ifdef DEBUG_TREE
3262 xmlGenericError(xmlGenericErrorContext, 3328 xmlGenericError(xmlGenericErrorContext,
3263 "xmlAddChild : child == NULL\n"); 3329 "xmlAddChild : child == NULL\n");
3264 #endif 3330 #endif
3265 return(NULL); 3331 return(NULL);
3266 } 3332 }
3267 3333
3268 if (parent == cur) { 3334 if (parent == cur) {
3269 #ifdef DEBUG_TREE 3335 #ifdef DEBUG_TREE
3270 xmlGenericError(xmlGenericErrorContext, 3336 xmlGenericError(xmlGenericErrorContext,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
3363 } 3429 }
3364 3430
3365 /** 3431 /**
3366 * xmlGetLastChild: 3432 * xmlGetLastChild:
3367 * @parent: the parent node 3433 * @parent: the parent node
3368 * 3434 *
3369 * Search the last child of a node. 3435 * Search the last child of a node.
3370 * Returns the last child or NULL if none. 3436 * Returns the last child or NULL if none.
3371 */ 3437 */
3372 xmlNodePtr 3438 xmlNodePtr
3373 xmlGetLastChild(xmlNodePtr parent) { 3439 xmlGetLastChild(const xmlNode *parent) {
3374 if (parent == NULL) { 3440 if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) {
3375 #ifdef DEBUG_TREE 3441 #ifdef DEBUG_TREE
3376 xmlGenericError(xmlGenericErrorContext, 3442 xmlGenericError(xmlGenericErrorContext,
3377 "xmlGetLastChild : parent == NULL\n"); 3443 "xmlGetLastChild : parent == NULL\n");
3378 #endif 3444 #endif
3379 return(NULL); 3445 return(NULL);
3380 } 3446 }
3381 return(parent->last); 3447 return(parent->last);
3382 } 3448 }
3383 3449
3384 #ifdef LIBXML_TREE_ENABLED 3450 #ifdef LIBXML_TREE_ENABLED
(...skipping 17 matching lines...) Expand all
3402 xmlChildElementCount(xmlNodePtr parent) { 3468 xmlChildElementCount(xmlNodePtr parent) {
3403 unsigned long ret = 0; 3469 unsigned long ret = 0;
3404 xmlNodePtr cur = NULL; 3470 xmlNodePtr cur = NULL;
3405 3471
3406 if (parent == NULL) 3472 if (parent == NULL)
3407 return(0); 3473 return(0);
3408 switch (parent->type) { 3474 switch (parent->type) {
3409 case XML_ELEMENT_NODE: 3475 case XML_ELEMENT_NODE:
3410 case XML_ENTITY_NODE: 3476 case XML_ENTITY_NODE:
3411 case XML_DOCUMENT_NODE: 3477 case XML_DOCUMENT_NODE:
3478 case XML_DOCUMENT_FRAG_NODE:
3412 case XML_HTML_DOCUMENT_NODE: 3479 case XML_HTML_DOCUMENT_NODE:
3413 cur = parent->children; 3480 cur = parent->children;
3414 break; 3481 break;
3415 default: 3482 default:
3416 return(0); 3483 return(0);
3417 } 3484 }
3418 while (cur != NULL) { 3485 while (cur != NULL) {
3419 if (cur->type == XML_ELEMENT_NODE) 3486 if (cur->type == XML_ELEMENT_NODE)
3420 ret++; 3487 ret++;
3421 cur = cur->next; 3488 cur = cur->next;
(...skipping 15 matching lines...) Expand all
3437 xmlNodePtr 3504 xmlNodePtr
3438 xmlFirstElementChild(xmlNodePtr parent) { 3505 xmlFirstElementChild(xmlNodePtr parent) {
3439 xmlNodePtr cur = NULL; 3506 xmlNodePtr cur = NULL;
3440 3507
3441 if (parent == NULL) 3508 if (parent == NULL)
3442 return(NULL); 3509 return(NULL);
3443 switch (parent->type) { 3510 switch (parent->type) {
3444 case XML_ELEMENT_NODE: 3511 case XML_ELEMENT_NODE:
3445 case XML_ENTITY_NODE: 3512 case XML_ENTITY_NODE:
3446 case XML_DOCUMENT_NODE: 3513 case XML_DOCUMENT_NODE:
3514 case XML_DOCUMENT_FRAG_NODE:
3447 case XML_HTML_DOCUMENT_NODE: 3515 case XML_HTML_DOCUMENT_NODE:
3448 cur = parent->children; 3516 cur = parent->children;
3449 break; 3517 break;
3450 default: 3518 default:
3451 return(NULL); 3519 return(NULL);
3452 } 3520 }
3453 while (cur != NULL) { 3521 while (cur != NULL) {
3454 if (cur->type == XML_ELEMENT_NODE) 3522 if (cur->type == XML_ELEMENT_NODE)
3455 return(cur); 3523 return(cur);
3456 cur = cur->next; 3524 cur = cur->next;
(...skipping 15 matching lines...) Expand all
3472 xmlNodePtr 3540 xmlNodePtr
3473 xmlLastElementChild(xmlNodePtr parent) { 3541 xmlLastElementChild(xmlNodePtr parent) {
3474 xmlNodePtr cur = NULL; 3542 xmlNodePtr cur = NULL;
3475 3543
3476 if (parent == NULL) 3544 if (parent == NULL)
3477 return(NULL); 3545 return(NULL);
3478 switch (parent->type) { 3546 switch (parent->type) {
3479 case XML_ELEMENT_NODE: 3547 case XML_ELEMENT_NODE:
3480 case XML_ENTITY_NODE: 3548 case XML_ENTITY_NODE:
3481 case XML_DOCUMENT_NODE: 3549 case XML_DOCUMENT_NODE:
3550 case XML_DOCUMENT_FRAG_NODE:
3482 case XML_HTML_DOCUMENT_NODE: 3551 case XML_HTML_DOCUMENT_NODE:
3483 cur = parent->last; 3552 cur = parent->last;
3484 break; 3553 break;
3485 default: 3554 default:
3486 return(NULL); 3555 return(NULL);
3487 } 3556 }
3488 while (cur != NULL) { 3557 while (cur != NULL) {
3489 if (cur->type == XML_ELEMENT_NODE) 3558 if (cur->type == XML_ELEMENT_NODE)
3490 return(cur); 3559 return(cur);
3491 cur = cur->prev; 3560 cur = cur->prev;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
3714 (cur->nsDef != NULL)) 3783 (cur->nsDef != NULL))
3715 xmlFreeNsList(cur->nsDef); 3784 xmlFreeNsList(cur->nsDef);
3716 xmlFree(cur); 3785 xmlFree(cur);
3717 } 3786 }
3718 3787
3719 /** 3788 /**
3720 * xmlUnlinkNode: 3789 * xmlUnlinkNode:
3721 * @cur: the node 3790 * @cur: the node
3722 * 3791 *
3723 * Unlink a node from it's current context, the node is not freed 3792 * Unlink a node from it's current context, the node is not freed
3793 * If one need to free the node, use xmlFreeNode() routine after the
3794 * unlink to discard it.
3795 * Note that namespace nodes can't be unlinked as they do not have
3796 * pointer to their parent.
3724 */ 3797 */
3725 void 3798 void
3726 xmlUnlinkNode(xmlNodePtr cur) { 3799 xmlUnlinkNode(xmlNodePtr cur) {
3727 if (cur == NULL) { 3800 if (cur == NULL) {
3728 #ifdef DEBUG_TREE 3801 #ifdef DEBUG_TREE
3729 xmlGenericError(xmlGenericErrorContext, 3802 xmlGenericError(xmlGenericErrorContext,
3730 "xmlUnlinkNode : node == NULL\n"); 3803 "xmlUnlinkNode : node == NULL\n");
3731 #endif 3804 #endif
3732 return; 3805 return;
3733 } 3806 }
3807 if (cur->type == XML_NAMESPACE_DECL)
3808 return;
3734 if (cur->type == XML_DTD_NODE) { 3809 if (cur->type == XML_DTD_NODE) {
3735 xmlDocPtr doc; 3810 xmlDocPtr doc;
3736 doc = cur->doc; 3811 doc = cur->doc;
3737 if (doc != NULL) { 3812 if (doc != NULL) {
3738 if (doc->intSubset == (xmlDtdPtr) cur) 3813 if (doc->intSubset == (xmlDtdPtr) cur)
3739 doc->intSubset = NULL; 3814 doc->intSubset = NULL;
3740 if (doc->extSubset == (xmlDtdPtr) cur) 3815 if (doc->extSubset == (xmlDtdPtr) cur)
3741 doc->extSubset = NULL; 3816 doc->extSubset = NULL;
3742 } 3817 }
3743 } 3818 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
3792 * 3867 *
3793 * Unlink the old node from its current context, prune the new one 3868 * 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 3869 * at the same place. If @cur was already inserted in a document it is
3795 * first unlinked from its existing context. 3870 * first unlinked from its existing context.
3796 * 3871 *
3797 * Returns the @old node 3872 * Returns the @old node
3798 */ 3873 */
3799 xmlNodePtr 3874 xmlNodePtr
3800 xmlReplaceNode(xmlNodePtr old, xmlNodePtr cur) { 3875 xmlReplaceNode(xmlNodePtr old, xmlNodePtr cur) {
3801 if (old == cur) return(NULL); 3876 if (old == cur) return(NULL);
3802 if ((old == NULL) || (old->parent == NULL)) { 3877 if ((old == NULL) || (old->type == XML_NAMESPACE_DECL) ||
3878 (old->parent == NULL)) {
3803 #ifdef DEBUG_TREE 3879 #ifdef DEBUG_TREE
3804 xmlGenericError(xmlGenericErrorContext, 3880 xmlGenericError(xmlGenericErrorContext,
3805 "xmlReplaceNode : old == NULL or without parent\n"); 3881 "xmlReplaceNode : old == NULL or without parent\n");
3806 #endif 3882 #endif
3807 return(NULL); 3883 return(NULL);
3808 } 3884 }
3809 if (cur == NULL) { 3885 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) {
3810 xmlUnlinkNode(old); 3886 xmlUnlinkNode(old);
3811 return(old); 3887 return(old);
3812 } 3888 }
3813 if (cur == old) { 3889 if (cur == old) {
3814 return(old); 3890 return(old);
3815 } 3891 }
3816 if ((old->type==XML_ATTRIBUTE_NODE) && (cur->type!=XML_ATTRIBUTE_NODE)) { 3892 if ((old->type==XML_ATTRIBUTE_NODE) && (cur->type!=XML_ATTRIBUTE_NODE)) {
3817 #ifdef DEBUG_TREE 3893 #ifdef DEBUG_TREE
3818 xmlGenericError(xmlGenericErrorContext, 3894 xmlGenericError(xmlGenericErrorContext,
3819 "xmlReplaceNode : Trying to replace attribute node with other no de type\n"); 3895 "xmlReplaceNode : Trying to replace attribute node with other no de type\n");
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
3913 } 3989 }
3914 3990
3915 static xmlNodePtr 3991 static xmlNodePtr
3916 xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent); 3992 xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent);
3917 3993
3918 static xmlAttrPtr 3994 static xmlAttrPtr
3919 xmlCopyPropInternal(xmlDocPtr doc, xmlNodePtr target, xmlAttrPtr cur) { 3995 xmlCopyPropInternal(xmlDocPtr doc, xmlNodePtr target, xmlAttrPtr cur) {
3920 xmlAttrPtr ret; 3996 xmlAttrPtr ret;
3921 3997
3922 if (cur == NULL) return(NULL); 3998 if (cur == NULL) return(NULL);
3999 if ((target != NULL) && (target->type != XML_ELEMENT_NODE))
4000 return(NULL);
3923 if (target != NULL) 4001 if (target != NULL)
3924 ret = xmlNewDocProp(target->doc, cur->name, NULL); 4002 ret = xmlNewDocProp(target->doc, cur->name, NULL);
3925 else if (doc != NULL) 4003 else if (doc != NULL)
3926 ret = xmlNewDocProp(doc, cur->name, NULL); 4004 ret = xmlNewDocProp(doc, cur->name, NULL);
3927 else if (cur->parent != NULL) 4005 else if (cur->parent != NULL)
3928 ret = xmlNewDocProp(cur->parent->doc, cur->name, NULL); 4006 ret = xmlNewDocProp(cur->parent->doc, cur->name, NULL);
3929 else if (cur->children != NULL) 4007 else if (cur->children != NULL)
3930 ret = xmlNewDocProp(cur->children->doc, cur->name, NULL); 4008 ret = xmlNewDocProp(cur->children->doc, cur->name, NULL);
3931 else 4009 else
3932 ret = xmlNewDocProp(NULL, cur->name, NULL); 4010 ret = xmlNewDocProp(NULL, cur->name, NULL);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
4032 * 4110 *
4033 * Do a copy of an attribute list. 4111 * Do a copy of an attribute list.
4034 * 4112 *
4035 * Returns: a new #xmlAttrPtr, or NULL in case of error. 4113 * Returns: a new #xmlAttrPtr, or NULL in case of error.
4036 */ 4114 */
4037 xmlAttrPtr 4115 xmlAttrPtr
4038 xmlCopyPropList(xmlNodePtr target, xmlAttrPtr cur) { 4116 xmlCopyPropList(xmlNodePtr target, xmlAttrPtr cur) {
4039 xmlAttrPtr ret = NULL; 4117 xmlAttrPtr ret = NULL;
4040 xmlAttrPtr p = NULL,q; 4118 xmlAttrPtr p = NULL,q;
4041 4119
4120 if ((target != NULL) && (target->type != XML_ELEMENT_NODE))
4121 return(NULL);
4042 while (cur != NULL) { 4122 while (cur != NULL) {
4043 q = xmlCopyProp(target, cur); 4123 q = xmlCopyProp(target, cur);
4044 if (q == NULL) 4124 if (q == NULL)
4045 return(NULL); 4125 return(NULL);
4046 if (p == NULL) { 4126 if (p == NULL) {
4047 ret = p = q; 4127 ret = p = q;
4048 } else { 4128 } else {
4049 p->next = q; 4129 p->next = q;
4050 q->prev = p; 4130 q->prev = p;
4051 p = q; 4131 p = q;
(...skipping 16 matching lines...) Expand all
4068 * a copy of the namespace at the top of the copied tree if 4148 * a copy of the namespace at the top of the copied tree if
4069 * not available in the subtree. 4149 * not available in the subtree.
4070 * Hence two functions, the public front-end call the inner ones 4150 * Hence two functions, the public front-end call the inner ones
4071 * The argument "recursive" normally indicates a recursive copy 4151 * The argument "recursive" normally indicates a recursive copy
4072 * of the node with values 0 (no) and 1 (yes). For XInclude, 4152 * 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 4153 * however, we allow a value of 2 to indicate copy properties and
4074 * namespace info, but don't recurse on children. 4154 * namespace info, but don't recurse on children.
4075 */ 4155 */
4076 4156
4077 static xmlNodePtr 4157 static xmlNodePtr
4078 xmlStaticCopyNode(const xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, 4158 xmlStaticCopyNode(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent,
4079 int extended) { 4159 int extended) {
4080 xmlNodePtr ret; 4160 xmlNodePtr ret;
4081 4161
4082 if (node == NULL) return(NULL); 4162 if (node == NULL) return(NULL);
4083 switch (node->type) { 4163 switch (node->type) {
4084 case XML_TEXT_NODE: 4164 case XML_TEXT_NODE:
4085 case XML_CDATA_SECTION_NODE: 4165 case XML_CDATA_SECTION_NODE:
4086 case XML_ELEMENT_NODE: 4166 case XML_ELEMENT_NODE:
4087 case XML_DOCUMENT_FRAG_NODE: 4167 case XML_DOCUMENT_FRAG_NODE:
4088 case XML_ENTITY_REF_NODE: 4168 case XML_ENTITY_REF_NODE:
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
4234 4314
4235 while (node != NULL) { 4315 while (node != NULL) {
4236 #ifdef LIBXML_TREE_ENABLED 4316 #ifdef LIBXML_TREE_ENABLED
4237 if (node->type == XML_DTD_NODE ) { 4317 if (node->type == XML_DTD_NODE ) {
4238 if (doc == NULL) { 4318 if (doc == NULL) {
4239 node = node->next; 4319 node = node->next;
4240 continue; 4320 continue;
4241 } 4321 }
4242 if (doc->intSubset == NULL) { 4322 if (doc->intSubset == NULL) {
4243 q = (xmlNodePtr) xmlCopyDtd( (xmlDtdPtr) node ); 4323 q = (xmlNodePtr) xmlCopyDtd( (xmlDtdPtr) node );
4324 if (q == NULL) return(NULL);
4244 q->doc = doc; 4325 q->doc = doc;
4245 q->parent = parent; 4326 q->parent = parent;
4246 doc->intSubset = (xmlDtdPtr) q; 4327 doc->intSubset = (xmlDtdPtr) q;
4247 xmlAddChild(parent, q); 4328 xmlAddChild(parent, q);
4248 } else { 4329 } else {
4249 q = (xmlNodePtr) doc->intSubset; 4330 q = (xmlNodePtr) doc->intSubset;
4250 xmlAddChild(parent, q); 4331 xmlAddChild(parent, q);
4251 } 4332 }
4252 } else 4333 } else
4253 #endif /* LIBXML_TREE_ENABLED */ 4334 #endif /* LIBXML_TREE_ENABLED */
4254 q = xmlStaticCopyNode(node, doc, parent, 1); 4335 q = xmlStaticCopyNode(node, doc, parent, 1);
4336 if (q == NULL) return(NULL);
4255 if (ret == NULL) { 4337 if (ret == NULL) {
4256 q->prev = NULL; 4338 q->prev = NULL;
4257 ret = p = q; 4339 ret = p = q;
4258 } else if (p != q) { 4340 } else if (p != q) {
4259 /* the test is required if xmlStaticCopyNode coalesced 2 text nodes */ 4341 /* the test is required if xmlStaticCopyNode coalesced 2 text nodes */
4260 p->next = q; 4342 p->next = q;
4261 q->prev = p; 4343 q->prev = p;
4262 p = q; 4344 p = q;
4263 } 4345 }
4264 node = node->next; 4346 node = node->next;
4265 } 4347 }
4266 return(ret); 4348 return(ret);
4267 } 4349 }
4268 4350
4269 /** 4351 /**
4270 * xmlCopyNode: 4352 * xmlCopyNode:
4271 * @node: the node 4353 * @node: the node
4272 * @extended: if 1 do a recursive copy (properties, namespaces and children 4354 * @extended: if 1 do a recursive copy (properties, namespaces and children
4273 * when applicable) 4355 * when applicable)
4274 * if 2 copy properties and namespaces (when applicable) 4356 * if 2 copy properties and namespaces (when applicable)
4275 * 4357 *
4276 * Do a copy of the node. 4358 * Do a copy of the node.
4277 * 4359 *
4278 * Returns: a new #xmlNodePtr, or NULL in case of error. 4360 * Returns: a new #xmlNodePtr, or NULL in case of error.
4279 */ 4361 */
4280 xmlNodePtr 4362 xmlNodePtr
4281 xmlCopyNode(const xmlNodePtr node, int extended) { 4363 xmlCopyNode(xmlNodePtr node, int extended) {
4282 xmlNodePtr ret; 4364 xmlNodePtr ret;
4283 4365
4284 ret = xmlStaticCopyNode(node, NULL, NULL, extended); 4366 ret = xmlStaticCopyNode(node, NULL, NULL, extended);
4285 return(ret); 4367 return(ret);
4286 } 4368 }
4287 4369
4288 /** 4370 /**
4289 * xmlDocCopyNode: 4371 * xmlDocCopyNode:
4290 * @node: the node 4372 * @node: the node
4291 * @doc: the document 4373 * @doc: the document
4292 * @extended: if 1 do a recursive copy (properties, namespaces and children 4374 * @extended: if 1 do a recursive copy (properties, namespaces and children
4293 * when applicable) 4375 * when applicable)
4294 * if 2 copy properties and namespaces (when applicable) 4376 * if 2 copy properties and namespaces (when applicable)
4295 * 4377 *
4296 * Do a copy of the node to a given document. 4378 * Do a copy of the node to a given document.
4297 * 4379 *
4298 * Returns: a new #xmlNodePtr, or NULL in case of error. 4380 * Returns: a new #xmlNodePtr, or NULL in case of error.
4299 */ 4381 */
4300 xmlNodePtr 4382 xmlNodePtr
4301 xmlDocCopyNode(const xmlNodePtr node, xmlDocPtr doc, int extended) { 4383 xmlDocCopyNode(xmlNodePtr node, xmlDocPtr doc, int extended) {
4302 xmlNodePtr ret; 4384 xmlNodePtr ret;
4303 4385
4304 ret = xmlStaticCopyNode(node, doc, NULL, extended); 4386 ret = xmlStaticCopyNode(node, doc, NULL, extended);
4305 return(ret); 4387 return(ret);
4306 } 4388 }
4307 4389
4308 /** 4390 /**
4309 * xmlDocCopyNodeList: 4391 * xmlDocCopyNodeList:
4310 * @doc: the target document 4392 * @doc: the target document
4311 * @node: the first node in the list. 4393 * @node: the first node in the list.
4312 * 4394 *
4313 * Do a recursive copy of the node list. 4395 * Do a recursive copy of the node list.
4314 * 4396 *
4315 * Returns: a new #xmlNodePtr, or NULL in case of error. 4397 * Returns: a new #xmlNodePtr, or NULL in case of error.
4316 */ 4398 */
4317 xmlNodePtr xmlDocCopyNodeList(xmlDocPtr doc, const xmlNodePtr node) { 4399 xmlNodePtr xmlDocCopyNodeList(xmlDocPtr doc, xmlNodePtr node) {
4318 xmlNodePtr ret = xmlStaticCopyNodeList(node, doc, NULL); 4400 xmlNodePtr ret = xmlStaticCopyNodeList(node, doc, NULL);
4319 return(ret); 4401 return(ret);
4320 } 4402 }
4321 4403
4322 /** 4404 /**
4323 * xmlCopyNodeList: 4405 * xmlCopyNodeList:
4324 * @node: the first node in the list. 4406 * @node: the first node in the list.
4325 * 4407 *
4326 * Do a recursive copy of the node list. 4408 * Do a recursive copy of the node list.
4327 * Use xmlDocCopyNodeList() if possible to ensure string interning. 4409 * Use xmlDocCopyNodeList() if possible to ensure string interning.
4328 * 4410 *
4329 * Returns: a new #xmlNodePtr, or NULL in case of error. 4411 * Returns: a new #xmlNodePtr, or NULL in case of error.
4330 */ 4412 */
4331 xmlNodePtr xmlCopyNodeList(const xmlNodePtr node) { 4413 xmlNodePtr xmlCopyNodeList(xmlNodePtr node) {
4332 xmlNodePtr ret = xmlStaticCopyNodeList(node, NULL, NULL); 4414 xmlNodePtr ret = xmlStaticCopyNodeList(node, NULL, NULL);
4333 return(ret); 4415 return(ret);
4334 } 4416 }
4335 4417
4336 #if defined(LIBXML_TREE_ENABLED) 4418 #if defined(LIBXML_TREE_ENABLED)
4337 /** 4419 /**
4338 * xmlCopyDtd: 4420 * xmlCopyDtd:
4339 * @dtd: the dtd 4421 * @dtd: the dtd
4340 * 4422 *
4341 * Do a copy of the dtd. 4423 * Do a copy of the dtd.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
4447 ret->charset = doc->charset; 4529 ret->charset = doc->charset;
4448 ret->compression = doc->compression; 4530 ret->compression = doc->compression;
4449 ret->standalone = doc->standalone; 4531 ret->standalone = doc->standalone;
4450 if (!recursive) return(ret); 4532 if (!recursive) return(ret);
4451 4533
4452 ret->last = NULL; 4534 ret->last = NULL;
4453 ret->children = NULL; 4535 ret->children = NULL;
4454 #ifdef LIBXML_TREE_ENABLED 4536 #ifdef LIBXML_TREE_ENABLED
4455 if (doc->intSubset != NULL) { 4537 if (doc->intSubset != NULL) {
4456 ret->intSubset = xmlCopyDtd(doc->intSubset); 4538 ret->intSubset = xmlCopyDtd(doc->intSubset);
4539 if (ret->intSubset == NULL) {
4540 xmlFreeDoc(ret);
4541 return(NULL);
4542 }
4457 xmlSetTreeDoc((xmlNodePtr)ret->intSubset, ret); 4543 xmlSetTreeDoc((xmlNodePtr)ret->intSubset, ret);
4458 ret->intSubset->parent = ret; 4544 ret->intSubset->parent = ret;
4459 } 4545 }
4460 #endif 4546 #endif
4461 if (doc->oldNs != NULL) 4547 if (doc->oldNs != NULL)
4462 ret->oldNs = xmlCopyNamespaceList(doc->oldNs); 4548 ret->oldNs = xmlCopyNamespaceList(doc->oldNs);
4463 if (doc->children != NULL) { 4549 if (doc->children != NULL) {
4464 xmlNodePtr tmp; 4550 xmlNodePtr tmp;
4465 4551
4466 ret->children = xmlStaticCopyNodeList(doc->children, ret, 4552 ret->children = xmlStaticCopyNodeList(doc->children, ret,
(...skipping 10 matching lines...) Expand all
4477 } 4563 }
4478 #endif /* LIBXML_TREE_ENABLED */ 4564 #endif /* LIBXML_TREE_ENABLED */
4479 4565
4480 /************************************************************************ 4566 /************************************************************************
4481 * * 4567 * *
4482 * Content access functions * 4568 * Content access functions *
4483 * * 4569 * *
4484 ************************************************************************/ 4570 ************************************************************************/
4485 4571
4486 /** 4572 /**
4487 * xmlGetLineNo: 4573 * xmlGetLineNoInternal:
4488 * @node: valid node 4574 * @node: valid node
4575 * @depth: used to limit any risk of recursion
4489 * 4576 *
4490 * Get line number of @node. This requires activation of this option 4577 * Get line number of @node.
4491 * before invoking the parser by calling xmlLineNumbersDefault(1) 4578 * Try to override the limitation of lines being store in 16 bits ints
4492 * 4579 *
4493 * Returns the line number if successful, -1 otherwise 4580 * Returns the line number if successful, -1 otherwise
4494 */ 4581 */
4495 long 4582 static long
4496 xmlGetLineNo(xmlNodePtr node) 4583 xmlGetLineNoInternal(const xmlNode *node, int depth)
4497 { 4584 {
4498 long result = -1; 4585 long result = -1;
4499 4586
4587 if (depth >= 5)
4588 return(-1);
4589
4500 if (!node) 4590 if (!node)
4501 return result; 4591 return result;
4502 if ((node->type == XML_ELEMENT_NODE) || 4592 if ((node->type == XML_ELEMENT_NODE) ||
4503 (node->type == XML_TEXT_NODE) || 4593 (node->type == XML_TEXT_NODE) ||
4504 (node->type == XML_COMMENT_NODE) || 4594 (node->type == XML_COMMENT_NODE) ||
4505 » (node->type == XML_PI_NODE)) 4595 » (node->type == XML_PI_NODE)) {
4506 result = (long) node->line; 4596 » if (node->line == 65535) {
4507 else if ((node->prev != NULL) && 4597 » if ((node->type == XML_TEXT_NODE) && (node->psvi != NULL))
4598 » result = (long) node->psvi;
4599 » else if ((node->type == XML_ELEMENT_NODE) &&
4600 » (node->children != NULL))
4601 » result = xmlGetLineNoInternal(node->children, depth + 1);
4602 » else if (node->next != NULL)
4603 » result = xmlGetLineNoInternal(node->next, depth + 1);
4604 » else if (node->prev != NULL)
4605 » result = xmlGetLineNoInternal(node->prev, depth + 1);
4606 » }
4607 » if ((result == -1) || (result == 65535))
4608 » result = (long) node->line;
4609 } else if ((node->prev != NULL) &&
4508 ((node->prev->type == XML_ELEMENT_NODE) || 4610 ((node->prev->type == XML_ELEMENT_NODE) ||
4509 (node->prev->type == XML_TEXT_NODE) || 4611 (node->prev->type == XML_TEXT_NODE) ||
4510 (node->prev->type == XML_COMMENT_NODE) || 4612 (node->prev->type == XML_COMMENT_NODE) ||
4511 (node->prev->type == XML_PI_NODE))) 4613 (node->prev->type == XML_PI_NODE)))
4512 result = xmlGetLineNo(node->prev); 4614 result = xmlGetLineNoInternal(node->prev, depth + 1);
4513 else if ((node->parent != NULL) && 4615 else if ((node->parent != NULL) &&
4514 (node->parent->type == XML_ELEMENT_NODE)) 4616 (node->parent->type == XML_ELEMENT_NODE))
4515 result = xmlGetLineNo(node->parent); 4617 result = xmlGetLineNoInternal(node->parent, depth + 1);
4516 4618
4517 return result; 4619 return result;
4518 } 4620 }
4519 4621
4622 /**
4623 * xmlGetLineNo:
4624 * @node: valid node
4625 *
4626 * Get line number of @node.
4627 * Try to override the limitation of lines being store in 16 bits ints
4628 * if XML_PARSE_BIG_LINES parser option was used
4629 *
4630 * Returns the line number if successful, -1 otherwise
4631 */
4632 long
4633 xmlGetLineNo(const xmlNode *node)
4634 {
4635 return(xmlGetLineNoInternal(node, 0));
4636 }
4637
4520 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_DEBUG_ENABLED) 4638 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_DEBUG_ENABLED)
4521 /** 4639 /**
4522 * xmlGetNodePath: 4640 * xmlGetNodePath:
4523 * @node: a node 4641 * @node: a node
4524 * 4642 *
4525 * Build a structure based Path for the given node 4643 * Build a structure based Path for the given node
4526 * 4644 *
4527 * Returns the new path or NULL in case of error. The caller must free 4645 * Returns the new path or NULL in case of error. The caller must free
4528 * the returned string 4646 * the returned string
4529 */ 4647 */
4530 xmlChar * 4648 xmlChar *
4531 xmlGetNodePath(xmlNodePtr node) 4649 xmlGetNodePath(const xmlNode *node)
4532 { 4650 {
4533 xmlNodePtr cur, tmp, next; 4651 const xmlNode *cur, *tmp, *next;
4534 xmlChar *buffer = NULL, *temp; 4652 xmlChar *buffer = NULL, *temp;
4535 size_t buf_len; 4653 size_t buf_len;
4536 xmlChar *buf; 4654 xmlChar *buf;
4537 const char *sep; 4655 const char *sep;
4538 const char *name; 4656 const char *name;
4539 char nametemp[100]; 4657 char nametemp[100];
4540 int occur = 0, generic; 4658 int occur = 0, generic;
4541 4659
4542 if (node == NULL) 4660 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL))
4543 return (NULL); 4661 return (NULL);
4544 4662
4545 buf_len = 500; 4663 buf_len = 500;
4546 buffer = (xmlChar *) xmlMallocAtomic(buf_len * sizeof(xmlChar)); 4664 buffer = (xmlChar *) xmlMallocAtomic(buf_len * sizeof(xmlChar));
4547 if (buffer == NULL) { 4665 if (buffer == NULL) {
4548 xmlTreeErrMemory("getting node path"); 4666 xmlTreeErrMemory("getting node path");
4549 return (NULL); 4667 return (NULL);
4550 } 4668 }
4551 buf = (xmlChar *) xmlMallocAtomic(buf_len * sizeof(xmlChar)); 4669 buf = (xmlChar *) xmlMallocAtomic(buf_len * sizeof(xmlChar));
4552 if (buf == NULL) { 4670 if (buf == NULL) {
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
4767 /** 4885 /**
4768 * xmlDocGetRootElement: 4886 * xmlDocGetRootElement:
4769 * @doc: the document 4887 * @doc: the document
4770 * 4888 *
4771 * Get the root element of the document (doc->children is a list 4889 * Get the root element of the document (doc->children is a list
4772 * containing possibly comments, PIs, etc ...). 4890 * containing possibly comments, PIs, etc ...).
4773 * 4891 *
4774 * Returns the #xmlNodePtr for the root or NULL 4892 * Returns the #xmlNodePtr for the root or NULL
4775 */ 4893 */
4776 xmlNodePtr 4894 xmlNodePtr
4777 xmlDocGetRootElement(xmlDocPtr doc) { 4895 xmlDocGetRootElement(const xmlDoc *doc) {
4778 xmlNodePtr ret; 4896 xmlNodePtr ret;
4779 4897
4780 if (doc == NULL) return(NULL); 4898 if (doc == NULL) return(NULL);
4781 ret = doc->children; 4899 ret = doc->children;
4782 while (ret != NULL) { 4900 while (ret != NULL) {
4783 if (ret->type == XML_ELEMENT_NODE) 4901 if (ret->type == XML_ELEMENT_NODE)
4784 return(ret); 4902 return(ret);
4785 ret = ret->next; 4903 ret = ret->next;
4786 } 4904 }
4787 return(ret); 4905 return(ret);
4788 } 4906 }
4789 4907
4790 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_WRITER_ENABLED) 4908 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_WRITER_ENABLED)
4791 /** 4909 /**
4792 * xmlDocSetRootElement: 4910 * xmlDocSetRootElement:
4793 * @doc: the document 4911 * @doc: the document
4794 * @root: the new document root element, if root is NULL no action is taken, 4912 * @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. 4913 * to remove a node from a document use xmlUnlinkNode(root) instead.
4796 * 4914 *
4797 * Set the root element of the document (doc->children is a list 4915 * Set the root element of the document (doc->children is a list
4798 * containing possibly comments, PIs, etc ...). 4916 * containing possibly comments, PIs, etc ...).
4799 * 4917 *
4800 * Returns the old root element if any was found, NULL if root was NULL 4918 * Returns the old root element if any was found, NULL if root was NULL
4801 */ 4919 */
4802 xmlNodePtr 4920 xmlNodePtr
4803 xmlDocSetRootElement(xmlDocPtr doc, xmlNodePtr root) { 4921 xmlDocSetRootElement(xmlDocPtr doc, xmlNodePtr root) {
4804 xmlNodePtr old = NULL; 4922 xmlNodePtr old = NULL;
4805 4923
4806 if (doc == NULL) return(NULL); 4924 if (doc == NULL) return(NULL);
4807 if (root == NULL) 4925 if ((root == NULL) || (root->type == XML_NAMESPACE_DECL))
4808 return(NULL); 4926 return(NULL);
4809 xmlUnlinkNode(root); 4927 xmlUnlinkNode(root);
4810 xmlSetTreeDoc(root, doc); 4928 xmlSetTreeDoc(root, doc);
4811 root->parent = (xmlNodePtr) doc; 4929 root->parent = (xmlNodePtr) doc;
4812 old = doc->children; 4930 old = doc->children;
4813 while (old != NULL) { 4931 while (old != NULL) {
4814 if (old->type == XML_ELEMENT_NODE) 4932 if (old->type == XML_ELEMENT_NODE)
4815 break; 4933 break;
4816 old = old->next; 4934 old = old->next;
4817 } 4935 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
4881 * xmlNodeGetLang: 4999 * xmlNodeGetLang:
4882 * @cur: the node being checked 5000 * @cur: the node being checked
4883 * 5001 *
4884 * Searches the language of a node, i.e. the values of the xml:lang 5002 * Searches the language of a node, i.e. the values of the xml:lang
4885 * attribute or the one carried by the nearest ancestor. 5003 * attribute or the one carried by the nearest ancestor.
4886 * 5004 *
4887 * Returns a pointer to the lang value, or NULL if not found 5005 * 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(). 5006 * It's up to the caller to free the memory with xmlFree().
4889 */ 5007 */
4890 xmlChar * 5008 xmlChar *
4891 xmlNodeGetLang(xmlNodePtr cur) { 5009 xmlNodeGetLang(const xmlNode *cur) {
4892 xmlChar *lang; 5010 xmlChar *lang;
4893 5011
5012 if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL))
5013 return(NULL);
4894 while (cur != NULL) { 5014 while (cur != NULL) {
4895 lang = xmlGetNsProp(cur, BAD_CAST "lang", XML_XML_NAMESPACE); 5015 lang = xmlGetNsProp(cur, BAD_CAST "lang", XML_XML_NAMESPACE);
4896 if (lang != NULL) 5016 if (lang != NULL)
4897 return(lang); 5017 return(lang);
4898 cur = cur->parent; 5018 cur = cur->parent;
4899 } 5019 }
4900 return(NULL); 5020 return(NULL);
4901 } 5021 }
4902 5022
4903 5023
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
4960 * xmlNodeGetSpacePreserve: 5080 * xmlNodeGetSpacePreserve:
4961 * @cur: the node being checked 5081 * @cur: the node being checked
4962 * 5082 *
4963 * Searches the space preserving behaviour of a node, i.e. the values 5083 * 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 5084 * of the xml:space attribute or the one carried by the nearest
4965 * ancestor. 5085 * ancestor.
4966 * 5086 *
4967 * Returns -1 if xml:space is not inherited, 0 if "default", 1 if "preserve" 5087 * Returns -1 if xml:space is not inherited, 0 if "default", 1 if "preserve"
4968 */ 5088 */
4969 int 5089 int
4970 xmlNodeGetSpacePreserve(xmlNodePtr cur) { 5090 xmlNodeGetSpacePreserve(const xmlNode *cur) {
4971 xmlChar *space; 5091 xmlChar *space;
4972 5092
5093 if ((cur == NULL) || (cur->type != XML_ELEMENT_NODE))
5094 return(-1);
4973 while (cur != NULL) { 5095 while (cur != NULL) {
4974 space = xmlGetNsProp(cur, BAD_CAST "space", XML_XML_NAMESPACE); 5096 space = xmlGetNsProp(cur, BAD_CAST "space", XML_XML_NAMESPACE);
4975 if (space != NULL) { 5097 if (space != NULL) {
4976 if (xmlStrEqual(space, BAD_CAST "preserve")) { 5098 if (xmlStrEqual(space, BAD_CAST "preserve")) {
4977 xmlFree(space); 5099 xmlFree(space);
4978 return(1); 5100 return(1);
4979 } 5101 }
4980 if (xmlStrEqual(space, BAD_CAST "default")) { 5102 if (xmlStrEqual(space, BAD_CAST "default")) {
4981 xmlFree(space); 5103 xmlFree(space);
4982 return(0); 5104 return(0);
(...skipping 10 matching lines...) Expand all
4993 * xmlNodeSetName: 5115 * xmlNodeSetName:
4994 * @cur: the node being changed 5116 * @cur: the node being changed
4995 * @name: the new tag name 5117 * @name: the new tag name
4996 * 5118 *
4997 * Set (or reset) the name of a node. 5119 * Set (or reset) the name of a node.
4998 */ 5120 */
4999 void 5121 void
5000 xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) { 5122 xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) {
5001 xmlDocPtr doc; 5123 xmlDocPtr doc;
5002 xmlDictPtr dict; 5124 xmlDictPtr dict;
5125 const xmlChar *freeme = NULL;
5003 5126
5004 if (cur == NULL) return; 5127 if (cur == NULL) return;
5005 if (name == NULL) return; 5128 if (name == NULL) return;
5006 switch(cur->type) { 5129 switch(cur->type) {
5007 case XML_TEXT_NODE: 5130 case XML_TEXT_NODE:
5008 case XML_CDATA_SECTION_NODE: 5131 case XML_CDATA_SECTION_NODE:
5009 case XML_COMMENT_NODE: 5132 case XML_COMMENT_NODE:
5010 case XML_DOCUMENT_TYPE_NODE: 5133 case XML_DOCUMENT_TYPE_NODE:
5011 case XML_DOCUMENT_FRAG_NODE: 5134 case XML_DOCUMENT_FRAG_NODE:
5012 case XML_NOTATION_NODE: 5135 case XML_NOTATION_NODE:
(...skipping 17 matching lines...) Expand all
5030 case XML_ENTITY_DECL: 5153 case XML_ENTITY_DECL:
5031 break; 5154 break;
5032 } 5155 }
5033 doc = cur->doc; 5156 doc = cur->doc;
5034 if (doc != NULL) 5157 if (doc != NULL)
5035 dict = doc->dict; 5158 dict = doc->dict;
5036 else 5159 else
5037 dict = NULL; 5160 dict = NULL;
5038 if (dict != NULL) { 5161 if (dict != NULL) {
5039 if ((cur->name != NULL) && (!xmlDictOwns(dict, cur->name))) 5162 if ((cur->name != NULL) && (!xmlDictOwns(dict, cur->name)))
5040 » xmlFree((xmlChar *) cur->name); 5163 » freeme = cur->name;
5041 cur->name = xmlDictLookup(dict, name, -1); 5164 cur->name = xmlDictLookup(dict, name, -1);
5042 } else { 5165 } else {
5043 » if (cur->name != NULL) xmlFree((xmlChar *) cur->name); 5166 » if (cur->name != NULL)
5167 » freeme = cur->name;
5044 cur->name = xmlStrdup(name); 5168 cur->name = xmlStrdup(name);
5045 } 5169 }
5170
5171 if (freeme)
5172 xmlFree((xmlChar *) freeme);
5046 } 5173 }
5047 #endif 5174 #endif
5048 5175
5049 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED) 5176 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED)
5050 /** 5177 /**
5051 * xmlNodeSetBase: 5178 * xmlNodeSetBase:
5052 * @cur: the node being changed 5179 * @cur: the node being changed
5053 * @uri: the new base URI 5180 * @uri: the new base URI
5054 * 5181 *
5055 * Set (or reset) the base URI of a node, i.e. the value of the 5182 * 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
5123 * 5.1.1. Base URI within Document Content 5250 * 5.1.1. Base URI within Document Content
5124 * and 5251 * and
5125 * 5.1.2. Base URI from the Encapsulating Entity 5252 * 5.1.2. Base URI from the Encapsulating Entity
5126 * However it does not return the document base (5.1.3), use 5253 * However it does not return the document base (5.1.3), use
5127 * doc->URL in this case 5254 * doc->URL in this case
5128 * 5255 *
5129 * Returns a pointer to the base URL, or NULL if not found 5256 * 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(). 5257 * It's up to the caller to free the memory with xmlFree().
5131 */ 5258 */
5132 xmlChar * 5259 xmlChar *
5133 xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) { 5260 xmlNodeGetBase(const xmlDoc *doc, const xmlNode *cur) {
5134 xmlChar *oldbase = NULL; 5261 xmlChar *oldbase = NULL;
5135 xmlChar *base, *newbase; 5262 xmlChar *base, *newbase;
5136 5263
5137 if ((cur == NULL) && (doc == NULL)) 5264 if ((cur == NULL) && (doc == NULL))
5138 return(NULL); 5265 return(NULL);
5266 if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL))
5267 return(NULL);
5139 if (doc == NULL) doc = cur->doc; 5268 if (doc == NULL) doc = cur->doc;
5140 if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) { 5269 if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) {
5141 cur = doc->children; 5270 cur = doc->children;
5142 while ((cur != NULL) && (cur->name != NULL)) { 5271 while ((cur != NULL) && (cur->name != NULL)) {
5143 if (cur->type != XML_ELEMENT_NODE) { 5272 if (cur->type != XML_ELEMENT_NODE) {
5144 cur = cur->next; 5273 cur = cur->next;
5145 continue; 5274 continue;
5146 } 5275 }
5147 if (!xmlStrcasecmp(cur->name, BAD_CAST "html")) { 5276 if (!xmlStrcasecmp(cur->name, BAD_CAST "html")) {
5148 cur = cur->children; 5277 cur = cur->children;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
5206 * 5335 *
5207 * Read the value of a node @cur, this can be either the text carried 5336 * 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 5337 * 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). 5338 * of the values carried by this node child's (TEXT and ENTITY_REF).
5210 * Entity references are substituted. 5339 * Entity references are substituted.
5211 * Fills up the buffer @buffer with this value 5340 * Fills up the buffer @buffer with this value
5212 * 5341 *
5213 * Returns 0 in case of success and -1 in case of error. 5342 * Returns 0 in case of success and -1 in case of error.
5214 */ 5343 */
5215 int 5344 int
5216 xmlNodeBufGetContent(xmlBufferPtr buffer, xmlNodePtr cur) 5345 xmlNodeBufGetContent(xmlBufferPtr buffer, const xmlNode *cur)
5217 { 5346 {
5347 xmlBufPtr buf;
5348 int ret;
5349
5218 if ((cur == NULL) || (buffer == NULL)) return(-1); 5350 if ((cur == NULL) || (buffer == NULL)) return(-1);
5351 buf = xmlBufFromBuffer(buffer);
5352 ret = xmlBufGetNodeContent(buf, cur);
5353 buffer = xmlBufBackToBuffer(buf);
5354 if ((ret < 0) || (buffer == NULL))
5355 return(-1);
5356 return(0);
5357 }
5358
5359 /**
5360 * xmlBufGetNodeContent:
5361 * @buf: a buffer xmlBufPtr
5362 * @cur: the node being read
5363 *
5364 * Read the value of a node @cur, this can be either the text carried
5365 * directly by this node if it's a TEXT node or the aggregate string
5366 * of the values carried by this node child's (TEXT and ENTITY_REF).
5367 * Entity references are substituted.
5368 * Fills up the buffer @buf with this value
5369 *
5370 * Returns 0 in case of success and -1 in case of error.
5371 */
5372 int
5373 xmlBufGetNodeContent(xmlBufPtr buf, const xmlNode *cur)
5374 {
5375 if ((cur == NULL) || (buf == NULL)) return(-1);
5219 switch (cur->type) { 5376 switch (cur->type) {
5220 case XML_CDATA_SECTION_NODE: 5377 case XML_CDATA_SECTION_NODE:
5221 case XML_TEXT_NODE: 5378 case XML_TEXT_NODE:
5222 » xmlBufferCat(buffer, cur->content); 5379 » xmlBufCat(buf, cur->content);
5223 break; 5380 break;
5224 case XML_DOCUMENT_FRAG_NODE: 5381 case XML_DOCUMENT_FRAG_NODE:
5225 case XML_ELEMENT_NODE:{ 5382 case XML_ELEMENT_NODE:{
5226 xmlNodePtr tmp = cur; 5383 const xmlNode *tmp = cur;
5227 5384
5228 while (tmp != NULL) { 5385 while (tmp != NULL) {
5229 switch (tmp->type) { 5386 switch (tmp->type) {
5230 case XML_CDATA_SECTION_NODE: 5387 case XML_CDATA_SECTION_NODE:
5231 case XML_TEXT_NODE: 5388 case XML_TEXT_NODE:
5232 if (tmp->content != NULL) 5389 if (tmp->content != NULL)
5233 xmlBufferCat(buffer, tmp->content); 5390 xmlBufCat(buf, tmp->content);
5234 break; 5391 break;
5235 case XML_ENTITY_REF_NODE: 5392 case XML_ENTITY_REF_NODE:
5236 xmlNodeBufGetContent(buffer, tmp); 5393 xmlBufGetNodeContent(buf, tmp);
5237 break; 5394 break;
5238 default: 5395 default:
5239 break; 5396 break;
5240 } 5397 }
5241 /* 5398 /*
5242 * Skip to next node 5399 * Skip to next node
5243 */ 5400 */
5244 if (tmp->children != NULL) { 5401 if (tmp->children != NULL) {
5245 if (tmp->children->type != XML_ENTITY_DECL) { 5402 if (tmp->children->type != XML_ENTITY_DECL) {
5246 tmp = tmp->children; 5403 tmp = tmp->children;
(...skipping 23 matching lines...) Expand all
5270 } while (tmp != NULL); 5427 } while (tmp != NULL);
5271 } 5428 }
5272 break; 5429 break;
5273 } 5430 }
5274 case XML_ATTRIBUTE_NODE:{ 5431 case XML_ATTRIBUTE_NODE:{
5275 xmlAttrPtr attr = (xmlAttrPtr) cur; 5432 xmlAttrPtr attr = (xmlAttrPtr) cur;
5276 xmlNodePtr tmp = attr->children; 5433 xmlNodePtr tmp = attr->children;
5277 5434
5278 while (tmp != NULL) { 5435 while (tmp != NULL) {
5279 if (tmp->type == XML_TEXT_NODE) 5436 if (tmp->type == XML_TEXT_NODE)
5280 » » xmlBufferCat(buffer, tmp->content); 5437 » » xmlBufCat(buf, tmp->content);
5281 else 5438 else
5282 » » xmlNodeBufGetContent(buffer, tmp); 5439 » » xmlBufGetNodeContent(buf, tmp);
5283 tmp = tmp->next; 5440 tmp = tmp->next;
5284 } 5441 }
5285 break; 5442 break;
5286 } 5443 }
5287 case XML_COMMENT_NODE: 5444 case XML_COMMENT_NODE:
5288 case XML_PI_NODE: 5445 case XML_PI_NODE:
5289 » xmlBufferCat(buffer, cur->content); 5446 » xmlBufCat(buf, cur->content);
5290 break; 5447 break;
5291 case XML_ENTITY_REF_NODE:{ 5448 case XML_ENTITY_REF_NODE:{
5292 xmlEntityPtr ent; 5449 xmlEntityPtr ent;
5293 xmlNodePtr tmp; 5450 xmlNodePtr tmp;
5294 5451
5295 /* lookup entity declaration */ 5452 /* lookup entity declaration */
5296 ent = xmlGetDocEntity(cur->doc, cur->name); 5453 ent = xmlGetDocEntity(cur->doc, cur->name);
5297 if (ent == NULL) 5454 if (ent == NULL)
5298 return(-1); 5455 return(-1);
5299 5456
5300 /* an entity content can be any "well balanced chunk", 5457 /* an entity content can be any "well balanced chunk",
5301 * i.e. the result of the content [43] production: 5458 * i.e. the result of the content [43] production:
5302 * http://www.w3.org/TR/REC-xml#NT-content 5459 * http://www.w3.org/TR/REC-xml#NT-content
5303 * -> we iterate through child nodes and recursive call 5460 * -> we iterate through child nodes and recursive call
5304 * xmlNodeGetContent() which handles all possible node types */ 5461 * xmlNodeGetContent() which handles all possible node types */
5305 tmp = ent->children; 5462 tmp = ent->children;
5306 while (tmp) { 5463 while (tmp) {
5307 » » xmlNodeBufGetContent(buffer, tmp); 5464 » » xmlBufGetNodeContent(buf, tmp);
5308 tmp = tmp->next; 5465 tmp = tmp->next;
5309 } 5466 }
5310 break; 5467 break;
5311 } 5468 }
5312 case XML_ENTITY_NODE: 5469 case XML_ENTITY_NODE:
5313 case XML_DOCUMENT_TYPE_NODE: 5470 case XML_DOCUMENT_TYPE_NODE:
5314 case XML_NOTATION_NODE: 5471 case XML_NOTATION_NODE:
5315 case XML_DTD_NODE: 5472 case XML_DTD_NODE:
5316 case XML_XINCLUDE_START: 5473 case XML_XINCLUDE_START:
5317 case XML_XINCLUDE_END: 5474 case XML_XINCLUDE_END:
5318 break; 5475 break;
5319 case XML_DOCUMENT_NODE: 5476 case XML_DOCUMENT_NODE:
5320 #ifdef LIBXML_DOCB_ENABLED 5477 #ifdef LIBXML_DOCB_ENABLED
5321 case XML_DOCB_DOCUMENT_NODE: 5478 case XML_DOCB_DOCUMENT_NODE:
5322 #endif 5479 #endif
5323 case XML_HTML_DOCUMENT_NODE: 5480 case XML_HTML_DOCUMENT_NODE:
5324 cur = cur->children; 5481 cur = cur->children;
5325 while (cur!= NULL) { 5482 while (cur!= NULL) {
5326 if ((cur->type == XML_ELEMENT_NODE) || 5483 if ((cur->type == XML_ELEMENT_NODE) ||
5327 (cur->type == XML_TEXT_NODE) || 5484 (cur->type == XML_TEXT_NODE) ||
5328 (cur->type == XML_CDATA_SECTION_NODE)) { 5485 (cur->type == XML_CDATA_SECTION_NODE)) {
5329 » » xmlNodeBufGetContent(buffer, cur); 5486 » » xmlBufGetNodeContent(buf, cur);
5330 } 5487 }
5331 cur = cur->next; 5488 cur = cur->next;
5332 } 5489 }
5333 break; 5490 break;
5334 case XML_NAMESPACE_DECL: 5491 case XML_NAMESPACE_DECL:
5335 » xmlBufferCat(buffer, ((xmlNsPtr) cur)->href); 5492 » xmlBufCat(buf, ((xmlNsPtr) cur)->href);
5336 break; 5493 break;
5337 case XML_ELEMENT_DECL: 5494 case XML_ELEMENT_DECL:
5338 case XML_ATTRIBUTE_DECL: 5495 case XML_ATTRIBUTE_DECL:
5339 case XML_ENTITY_DECL: 5496 case XML_ENTITY_DECL:
5340 break; 5497 break;
5341 } 5498 }
5342 return(0); 5499 return(0);
5343 } 5500 }
5501
5344 /** 5502 /**
5345 * xmlNodeGetContent: 5503 * xmlNodeGetContent:
5346 * @cur: the node being read 5504 * @cur: the node being read
5347 * 5505 *
5348 * Read the value of a node, this can be either the text carried 5506 * 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 5507 * 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). 5508 * of the values carried by this node child's (TEXT and ENTITY_REF).
5351 * Entity references are substituted. 5509 * Entity references are substituted.
5352 * Returns a new #xmlChar * or NULL if no content is available. 5510 * Returns a new #xmlChar * or NULL if no content is available.
5353 * It's up to the caller to free the memory with xmlFree(). 5511 * It's up to the caller to free the memory with xmlFree().
5354 */ 5512 */
5355 xmlChar * 5513 xmlChar *
5356 xmlNodeGetContent(xmlNodePtr cur) 5514 xmlNodeGetContent(const xmlNode *cur)
5357 { 5515 {
5358 if (cur == NULL) 5516 if (cur == NULL)
5359 return (NULL); 5517 return (NULL);
5360 switch (cur->type) { 5518 switch (cur->type) {
5361 case XML_DOCUMENT_FRAG_NODE: 5519 case XML_DOCUMENT_FRAG_NODE:
5362 case XML_ELEMENT_NODE:{ 5520 case XML_ELEMENT_NODE:{
5363 xmlBufferPtr buffer; 5521 xmlBufPtr buf;
5364 xmlChar *ret; 5522 xmlChar *ret;
5365 5523
5366 buffer = xmlBufferCreateSize(64); 5524 buf = xmlBufCreateSize(64);
5367 if (buffer == NULL) 5525 if (buf == NULL)
5368 return (NULL); 5526 return (NULL);
5369 » » xmlNodeBufGetContent(buffer, cur); 5527 » » xmlBufGetNodeContent(buf, cur);
5370 ret = buffer->content; 5528 ret = xmlBufDetach(buf);
5371 buffer->content = NULL; 5529 xmlBufFree(buf);
5372 xmlBufferFree(buffer);
5373 return (ret); 5530 return (ret);
5374 } 5531 }
5375 case XML_ATTRIBUTE_NODE: 5532 case XML_ATTRIBUTE_NODE:
5376 return(xmlGetPropNodeValueInternal((xmlAttrPtr) cur)); 5533 return(xmlGetPropNodeValueInternal((xmlAttrPtr) cur));
5377 case XML_COMMENT_NODE: 5534 case XML_COMMENT_NODE:
5378 case XML_PI_NODE: 5535 case XML_PI_NODE:
5379 if (cur->content != NULL) 5536 if (cur->content != NULL)
5380 return (xmlStrdup(cur->content)); 5537 return (xmlStrdup(cur->content));
5381 return (NULL); 5538 return (NULL);
5382 case XML_ENTITY_REF_NODE:{ 5539 case XML_ENTITY_REF_NODE:{
5383 xmlEntityPtr ent; 5540 xmlEntityPtr ent;
5384 xmlBufferPtr buffer; 5541 xmlBufPtr buf;
5385 xmlChar *ret; 5542 xmlChar *ret;
5386 5543
5387 /* lookup entity declaration */ 5544 /* lookup entity declaration */
5388 ent = xmlGetDocEntity(cur->doc, cur->name); 5545 ent = xmlGetDocEntity(cur->doc, cur->name);
5389 if (ent == NULL) 5546 if (ent == NULL)
5390 return (NULL); 5547 return (NULL);
5391 5548
5392 buffer = xmlBufferCreate(); 5549 buf = xmlBufCreate();
5393 if (buffer == NULL) 5550 if (buf == NULL)
5394 return (NULL); 5551 return (NULL);
5395 5552
5396 xmlNodeBufGetContent(buffer, cur); 5553 xmlBufGetNodeContent(buf, cur);
5397 5554
5398 ret = buffer->content; 5555 ret = xmlBufDetach(buf);
5399 buffer->content = NULL; 5556 xmlBufFree(buf);
5400 xmlBufferFree(buffer);
5401 return (ret); 5557 return (ret);
5402 } 5558 }
5403 case XML_ENTITY_NODE: 5559 case XML_ENTITY_NODE:
5404 case XML_DOCUMENT_TYPE_NODE: 5560 case XML_DOCUMENT_TYPE_NODE:
5405 case XML_NOTATION_NODE: 5561 case XML_NOTATION_NODE:
5406 case XML_DTD_NODE: 5562 case XML_DTD_NODE:
5407 case XML_XINCLUDE_START: 5563 case XML_XINCLUDE_START:
5408 case XML_XINCLUDE_END: 5564 case XML_XINCLUDE_END:
5409 return (NULL); 5565 return (NULL);
5410 case XML_DOCUMENT_NODE: 5566 case XML_DOCUMENT_NODE:
5411 #ifdef LIBXML_DOCB_ENABLED 5567 #ifdef LIBXML_DOCB_ENABLED
5412 case XML_DOCB_DOCUMENT_NODE: 5568 case XML_DOCB_DOCUMENT_NODE:
5413 #endif 5569 #endif
5414 case XML_HTML_DOCUMENT_NODE: { 5570 case XML_HTML_DOCUMENT_NODE: {
5415 » xmlBufferPtr buffer; 5571 » xmlBufPtr buf;
5416 xmlChar *ret; 5572 xmlChar *ret;
5417 5573
5418 » buffer = xmlBufferCreate(); 5574 » buf = xmlBufCreate();
5419 » if (buffer == NULL) 5575 » if (buf == NULL)
5420 return (NULL); 5576 return (NULL);
5421 5577
5422 » xmlNodeBufGetContent(buffer, (xmlNodePtr) cur); 5578 » xmlBufGetNodeContent(buf, (xmlNodePtr) cur);
5423 5579
5424 » ret = buffer->content; 5580 » ret = xmlBufDetach(buf);
5425 » buffer->content = NULL; 5581 » xmlBufFree(buf);
5426 » xmlBufferFree(buffer);
5427 return (ret); 5582 return (ret);
5428 } 5583 }
5429 case XML_NAMESPACE_DECL: { 5584 case XML_NAMESPACE_DECL: {
5430 xmlChar *tmp; 5585 xmlChar *tmp;
5431 5586
5432 tmp = xmlStrdup(((xmlNsPtr) cur)->href); 5587 tmp = xmlStrdup(((xmlNsPtr) cur)->href);
5433 return (tmp); 5588 return (tmp);
5434 } 5589 }
5435 case XML_ELEMENT_DECL: 5590 case XML_ELEMENT_DECL:
5436 /* TODO !!! */ 5591 /* TODO !!! */
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
5729 * xmlGetNsList: 5884 * xmlGetNsList:
5730 * @doc: the document 5885 * @doc: the document
5731 * @node: the current node 5886 * @node: the current node
5732 * 5887 *
5733 * Search all the namespace applying to a given element. 5888 * Search all the namespace applying to a given element.
5734 * Returns an NULL terminated array of all the #xmlNsPtr found 5889 * Returns an NULL terminated array of all the #xmlNsPtr found
5735 * that need to be freed by the caller or NULL if no 5890 * that need to be freed by the caller or NULL if no
5736 * namespace if defined 5891 * namespace if defined
5737 */ 5892 */
5738 xmlNsPtr * 5893 xmlNsPtr *
5739 xmlGetNsList(xmlDocPtr doc ATTRIBUTE_UNUSED, xmlNodePtr node) 5894 xmlGetNsList(const xmlDoc *doc ATTRIBUTE_UNUSED, const xmlNode *node)
5740 { 5895 {
5741 xmlNsPtr cur; 5896 xmlNsPtr cur;
5742 xmlNsPtr *ret = NULL; 5897 xmlNsPtr *ret = NULL;
5743 int nbns = 0; 5898 int nbns = 0;
5744 int maxns = 10; 5899 int maxns = 10;
5745 int i; 5900 int i;
5746 5901
5902 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL))
5903 return(NULL);
5904
5747 while (node != NULL) { 5905 while (node != NULL) {
5748 if (node->type == XML_ELEMENT_NODE) { 5906 if (node->type == XML_ELEMENT_NODE) {
5749 cur = node->nsDef; 5907 cur = node->nsDef;
5750 while (cur != NULL) { 5908 while (cur != NULL) {
5751 if (ret == NULL) { 5909 if (ret == NULL) {
5752 ret = 5910 ret =
5753 (xmlNsPtr *) xmlMalloc((maxns + 1) * 5911 (xmlNsPtr *) xmlMalloc((maxns + 1) *
5754 sizeof(xmlNsPtr)); 5912 sizeof(xmlNsPtr));
5755 if (ret == NULL) { 5913 if (ret == NULL) {
5756 xmlTreeErrMemory("getting namespace list"); 5914 xmlTreeErrMemory("getting namespace list");
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
5833 * We don't allow to cross entities boundaries. If you don't declare 5991 * 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 5992 * the namespace within those you will be in troubles !!! A warning
5835 * is generated to cover this case. 5993 * is generated to cover this case.
5836 * 5994 *
5837 * Returns the namespace pointer or NULL. 5995 * Returns the namespace pointer or NULL.
5838 */ 5996 */
5839 xmlNsPtr 5997 xmlNsPtr
5840 xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace) { 5998 xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace) {
5841 5999
5842 xmlNsPtr cur; 6000 xmlNsPtr cur;
5843 xmlNodePtr orig = node; 6001 const xmlNode *orig = node;
5844 6002
5845 if (node == NULL) return(NULL); 6003 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) return(NULL);
5846 if ((nameSpace != NULL) && 6004 if ((nameSpace != NULL) &&
5847 (xmlStrEqual(nameSpace, (const xmlChar *)"xml"))) { 6005 (xmlStrEqual(nameSpace, (const xmlChar *)"xml"))) {
5848 if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) { 6006 if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) {
5849 /* 6007 /*
5850 * The XML-1.0 namespace is normally held on the root 6008 * The XML-1.0 namespace is normally held on the root
5851 * element. In this case exceptionally create it on the 6009 * element. In this case exceptionally create it on the
5852 * node element. 6010 * node element.
5853 */ 6011 */
5854 cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs)); 6012 cur = (xmlNsPtr) xmlMalloc(sizeof(xmlNs));
5855 if (cur == NULL) { 6013 if (cur == NULL) {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
5965 * the defined namespace or return NULL otherwise. 6123 * the defined namespace or return NULL otherwise.
5966 * Returns the namespace pointer or NULL. 6124 * Returns the namespace pointer or NULL.
5967 */ 6125 */
5968 xmlNsPtr 6126 xmlNsPtr
5969 xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const xmlChar * href) 6127 xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const xmlChar * href)
5970 { 6128 {
5971 xmlNsPtr cur; 6129 xmlNsPtr cur;
5972 xmlNodePtr orig = node; 6130 xmlNodePtr orig = node;
5973 int is_attr; 6131 int is_attr;
5974 6132
5975 if ((node == NULL) || (href == NULL)) 6133 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) || (href == NULL))
5976 return (NULL); 6134 return (NULL);
5977 if (xmlStrEqual(href, XML_XML_NAMESPACE)) { 6135 if (xmlStrEqual(href, XML_XML_NAMESPACE)) {
5978 /* 6136 /*
5979 * Only the document can hold the XML spec namespace. 6137 * Only the document can hold the XML spec namespace.
5980 */ 6138 */
5981 if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) { 6139 if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) {
5982 /* 6140 /*
5983 * The XML-1.0 namespace is normally held on the root 6141 * The XML-1.0 namespace is normally held on the root
5984 * element. In this case exceptionally create it on the 6142 * element. In this case exceptionally create it on the
5985 * node element. 6143 * node element.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
6056 * null (default namespace) or reused within the subtree defined by 6214 * null (default namespace) or reused within the subtree defined by
6057 * @tree or on one of its ancestors then a new prefix is generated. 6215 * @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 6216 * Returns the (new) namespace definition or NULL in case of error
6059 */ 6217 */
6060 static xmlNsPtr 6218 static xmlNsPtr
6061 xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) { 6219 xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) {
6062 xmlNsPtr def; 6220 xmlNsPtr def;
6063 xmlChar prefix[50]; 6221 xmlChar prefix[50];
6064 int counter = 1; 6222 int counter = 1;
6065 6223
6066 if (tree == NULL) { 6224 if ((tree == NULL) || (tree->type != XML_ELEMENT_NODE)) {
6067 #ifdef DEBUG_TREE 6225 #ifdef DEBUG_TREE
6068 xmlGenericError(xmlGenericErrorContext, 6226 xmlGenericError(xmlGenericErrorContext,
6069 "xmlNewReconciliedNs : tree == NULL\n"); 6227 "xmlNewReconciliedNs : tree == NULL\n");
6070 #endif 6228 #endif
6071 return(NULL); 6229 return(NULL);
6072 } 6230 }
6073 if ((ns == NULL) || (ns->type != XML_NAMESPACE_DECL)) { 6231 if ((ns == NULL) || (ns->type != XML_NAMESPACE_DECL)) {
6074 #ifdef DEBUG_TREE 6232 #ifdef DEBUG_TREE
6075 xmlGenericError(xmlGenericErrorContext, 6233 xmlGenericError(xmlGenericErrorContext,
6076 "xmlNewReconciliedNs : ns == NULL\n"); 6234 "xmlNewReconciliedNs : ns == NULL\n");
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
6302 } 6460 }
6303 if (oldNs != NULL) 6461 if (oldNs != NULL)
6304 xmlFree(oldNs); 6462 xmlFree(oldNs);
6305 if (newNs != NULL) 6463 if (newNs != NULL)
6306 xmlFree(newNs); 6464 xmlFree(newNs);
6307 return(ret); 6465 return(ret);
6308 } 6466 }
6309 #endif /* LIBXML_TREE_ENABLED */ 6467 #endif /* LIBXML_TREE_ENABLED */
6310 6468
6311 static xmlAttrPtr 6469 static xmlAttrPtr
6312 xmlGetPropNodeInternal(xmlNodePtr node, const xmlChar *name, 6470 xmlGetPropNodeInternal(const xmlNode *node, const xmlChar *name,
6313 const xmlChar *nsName, int useDTD) 6471 const xmlChar *nsName, int useDTD)
6314 { 6472 {
6315 xmlAttrPtr prop; 6473 xmlAttrPtr prop;
6316 6474
6317 if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) 6475 if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL))
6318 return(NULL); 6476 return(NULL);
6319 6477
6320 if (node->properties != NULL) { 6478 if (node->properties != NULL) {
6321 prop = node->properties; 6479 prop = node->properties;
6322 if (nsName == NULL) { 6480 if (nsName == NULL) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
6416 * Only default/fixed attrs are relevant. 6574 * Only default/fixed attrs are relevant.
6417 */ 6575 */
6418 if ((attrDecl != NULL) && (attrDecl->defaultValue != NULL)) 6576 if ((attrDecl != NULL) && (attrDecl->defaultValue != NULL))
6419 return((xmlAttrPtr) attrDecl); 6577 return((xmlAttrPtr) attrDecl);
6420 } 6578 }
6421 #endif /* LIBXML_TREE_ENABLED */ 6579 #endif /* LIBXML_TREE_ENABLED */
6422 return(NULL); 6580 return(NULL);
6423 } 6581 }
6424 6582
6425 static xmlChar* 6583 static xmlChar*
6426 xmlGetPropNodeValueInternal(xmlAttrPtr prop) 6584 xmlGetPropNodeValueInternal(const xmlAttr *prop)
6427 { 6585 {
6428 if (prop == NULL) 6586 if (prop == NULL)
6429 return(NULL); 6587 return(NULL);
6430 if (prop->type == XML_ATTRIBUTE_NODE) { 6588 if (prop->type == XML_ATTRIBUTE_NODE) {
6431 /* 6589 /*
6432 * Note that we return at least the empty string. 6590 * Note that we return at least the empty string.
6433 * TODO: Do we really always want that? 6591 * TODO: Do we really always want that?
6434 */ 6592 */
6435 if (prop->children != NULL) { 6593 if (prop->children != NULL) {
6436 if ((prop->children->next == NULL) && 6594 if ((prop->children->next == NULL) &&
(...skipping 25 matching lines...) Expand all
6462 * @name: the attribute name 6620 * @name: the attribute name
6463 * 6621 *
6464 * Search an attribute associated to a node 6622 * Search an attribute associated to a node
6465 * This function also looks in DTD attribute declaration for #FIXED or 6623 * This function also looks in DTD attribute declaration for #FIXED or
6466 * default declaration values unless DTD use has been turned off. 6624 * default declaration values unless DTD use has been turned off.
6467 * 6625 *
6468 * Returns the attribute or the attribute declaration or NULL if 6626 * Returns the attribute or the attribute declaration or NULL if
6469 * neither was found. 6627 * neither was found.
6470 */ 6628 */
6471 xmlAttrPtr 6629 xmlAttrPtr
6472 xmlHasProp(xmlNodePtr node, const xmlChar *name) { 6630 xmlHasProp(const xmlNode *node, const xmlChar *name) {
6473 xmlAttrPtr prop; 6631 xmlAttrPtr prop;
6474 xmlDocPtr doc; 6632 xmlDocPtr doc;
6475 6633
6476 if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) 6634 if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL))
6477 return(NULL); 6635 return(NULL);
6478 /* 6636 /*
6479 * Check on the properties attached to the node 6637 * Check on the properties attached to the node
6480 */ 6638 */
6481 prop = node->properties; 6639 prop = node->properties;
6482 while (prop != NULL) { 6640 while (prop != NULL) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
6517 * This attribute has to be anchored in the namespace specified. 6675 * This attribute has to be anchored in the namespace specified.
6518 * This does the entity substitution. 6676 * This does the entity substitution.
6519 * This function looks in DTD attribute declaration for #FIXED or 6677 * This function looks in DTD attribute declaration for #FIXED or
6520 * default declaration values unless DTD use has been turned off. 6678 * default declaration values unless DTD use has been turned off.
6521 * Note that a namespace of NULL indicates to use the default namespace. 6679 * Note that a namespace of NULL indicates to use the default namespace.
6522 * 6680 *
6523 * Returns the attribute or the attribute declaration or NULL 6681 * Returns the attribute or the attribute declaration or NULL
6524 * if neither was found. 6682 * if neither was found.
6525 */ 6683 */
6526 xmlAttrPtr 6684 xmlAttrPtr
6527 xmlHasNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) { 6685 xmlHasNsProp(const xmlNode *node, const xmlChar *name, const xmlChar *nameSpace) {
6528 6686
6529 return(xmlGetPropNodeInternal(node, name, nameSpace, xmlCheckDTD)); 6687 return(xmlGetPropNodeInternal(node, name, nameSpace, xmlCheckDTD));
6530 } 6688 }
6531 6689
6532 /** 6690 /**
6533 * xmlGetProp: 6691 * xmlGetProp:
6534 * @node: the node 6692 * @node: the node
6535 * @name: the attribute name 6693 * @name: the attribute name
6536 * 6694 *
6537 * Search and get the value of an attribute associated to a node 6695 * Search and get the value of an attribute associated to a node
6538 * This does the entity substitution. 6696 * This does the entity substitution.
6539 * This function looks in DTD attribute declaration for #FIXED or 6697 * This function looks in DTD attribute declaration for #FIXED or
6540 * default declaration values unless DTD use has been turned off. 6698 * default declaration values unless DTD use has been turned off.
6541 * NOTE: this function acts independently of namespaces associated 6699 * NOTE: this function acts independently of namespaces associated
6542 * to the attribute. Use xmlGetNsProp() or xmlGetNoNsProp() 6700 * to the attribute. Use xmlGetNsProp() or xmlGetNoNsProp()
6543 * for namespace aware processing. 6701 * for namespace aware processing.
6544 * 6702 *
6545 * Returns the attribute value or NULL if not found. 6703 * Returns the attribute value or NULL if not found.
6546 * It's up to the caller to free the memory with xmlFree(). 6704 * It's up to the caller to free the memory with xmlFree().
6547 */ 6705 */
6548 xmlChar * 6706 xmlChar *
6549 xmlGetProp(xmlNodePtr node, const xmlChar *name) { 6707 xmlGetProp(const xmlNode *node, const xmlChar *name) {
6550 xmlAttrPtr prop; 6708 xmlAttrPtr prop;
6551 6709
6552 prop = xmlHasProp(node, name); 6710 prop = xmlHasProp(node, name);
6553 if (prop == NULL) 6711 if (prop == NULL)
6554 return(NULL); 6712 return(NULL);
6555 return(xmlGetPropNodeValueInternal(prop)); 6713 return(xmlGetPropNodeValueInternal(prop));
6556 } 6714 }
6557 6715
6558 /** 6716 /**
6559 * xmlGetNoNsProp: 6717 * xmlGetNoNsProp:
6560 * @node: the node 6718 * @node: the node
6561 * @name: the attribute name 6719 * @name: the attribute name
6562 * 6720 *
6563 * Search and get the value of an attribute associated to a node 6721 * Search and get the value of an attribute associated to a node
6564 * This does the entity substitution. 6722 * This does the entity substitution.
6565 * This function looks in DTD attribute declaration for #FIXED or 6723 * This function looks in DTD attribute declaration for #FIXED or
6566 * default declaration values unless DTD use has been turned off. 6724 * default declaration values unless DTD use has been turned off.
6567 * This function is similar to xmlGetProp except it will accept only 6725 * This function is similar to xmlGetProp except it will accept only
6568 * an attribute in no namespace. 6726 * an attribute in no namespace.
6569 * 6727 *
6570 * Returns the attribute value or NULL if not found. 6728 * Returns the attribute value or NULL if not found.
6571 * It's up to the caller to free the memory with xmlFree(). 6729 * It's up to the caller to free the memory with xmlFree().
6572 */ 6730 */
6573 xmlChar * 6731 xmlChar *
6574 xmlGetNoNsProp(xmlNodePtr node, const xmlChar *name) { 6732 xmlGetNoNsProp(const xmlNode *node, const xmlChar *name) {
6575 xmlAttrPtr prop; 6733 xmlAttrPtr prop;
6576 6734
6577 prop = xmlGetPropNodeInternal(node, name, NULL, xmlCheckDTD); 6735 prop = xmlGetPropNodeInternal(node, name, NULL, xmlCheckDTD);
6578 if (prop == NULL) 6736 if (prop == NULL)
6579 return(NULL); 6737 return(NULL);
6580 return(xmlGetPropNodeValueInternal(prop)); 6738 return(xmlGetPropNodeValueInternal(prop));
6581 } 6739 }
6582 6740
6583 /** 6741 /**
6584 * xmlGetNsProp: 6742 * xmlGetNsProp:
6585 * @node: the node 6743 * @node: the node
6586 * @name: the attribute name 6744 * @name: the attribute name
6587 * @nameSpace: the URI of the namespace 6745 * @nameSpace: the URI of the namespace
6588 * 6746 *
6589 * Search and get the value of an attribute associated to a node 6747 * Search and get the value of an attribute associated to a node
6590 * This attribute has to be anchored in the namespace specified. 6748 * This attribute has to be anchored in the namespace specified.
6591 * This does the entity substitution. 6749 * This does the entity substitution.
6592 * This function looks in DTD attribute declaration for #FIXED or 6750 * This function looks in DTD attribute declaration for #FIXED or
6593 * default declaration values unless DTD use has been turned off. 6751 * default declaration values unless DTD use has been turned off.
6594 * 6752 *
6595 * Returns the attribute value or NULL if not found. 6753 * Returns the attribute value or NULL if not found.
6596 * It's up to the caller to free the memory with xmlFree(). 6754 * It's up to the caller to free the memory with xmlFree().
6597 */ 6755 */
6598 xmlChar * 6756 xmlChar *
6599 xmlGetNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) { 6757 xmlGetNsProp(const xmlNode *node, const xmlChar *name, const xmlChar *nameSpace) {
6600 xmlAttrPtr prop; 6758 xmlAttrPtr prop;
6601 6759
6602 prop = xmlGetPropNodeInternal(node, name, nameSpace, xmlCheckDTD); 6760 prop = xmlGetPropNodeInternal(node, name, nameSpace, xmlCheckDTD);
6603 if (prop == NULL) 6761 if (prop == NULL)
6604 return(NULL); 6762 return(NULL);
6605 return(xmlGetPropNodeValueInternal(prop)); 6763 return(xmlGetPropNodeValueInternal(prop));
6606 } 6764 }
6607 6765
6608 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) 6766 #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
6609 /** 6767 /**
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
6754 #endif /* LIBXML_TREE_ENABLED */ 6912 #endif /* LIBXML_TREE_ENABLED */
6755 6913
6756 /** 6914 /**
6757 * xmlNodeIsText: 6915 * xmlNodeIsText:
6758 * @node: the node 6916 * @node: the node
6759 * 6917 *
6760 * Is this node a Text node ? 6918 * Is this node a Text node ?
6761 * Returns 1 yes, 0 no 6919 * Returns 1 yes, 0 no
6762 */ 6920 */
6763 int 6921 int
6764 xmlNodeIsText(xmlNodePtr node) { 6922 xmlNodeIsText(const xmlNode *node) {
6765 if (node == NULL) return(0); 6923 if (node == NULL) return(0);
6766 6924
6767 if (node->type == XML_TEXT_NODE) return(1); 6925 if (node->type == XML_TEXT_NODE) return(1);
6768 return(0); 6926 return(0);
6769 } 6927 }
6770 6928
6771 /** 6929 /**
6772 * xmlIsBlankNode: 6930 * xmlIsBlankNode:
6773 * @node: the node 6931 * @node: the node
6774 * 6932 *
6775 * Checks whether this node is an empty or whitespace only 6933 * Checks whether this node is an empty or whitespace only
6776 * (and possibly ignorable) text-node. 6934 * (and possibly ignorable) text-node.
6777 * 6935 *
6778 * Returns 1 yes, 0 no 6936 * Returns 1 yes, 0 no
6779 */ 6937 */
6780 int 6938 int
6781 xmlIsBlankNode(xmlNodePtr node) { 6939 xmlIsBlankNode(const xmlNode *node) {
6782 const xmlChar *cur; 6940 const xmlChar *cur;
6783 if (node == NULL) return(0); 6941 if (node == NULL) return(0);
6784 6942
6785 if ((node->type != XML_TEXT_NODE) && 6943 if ((node->type != XML_TEXT_NODE) &&
6786 (node->type != XML_CDATA_SECTION_NODE)) 6944 (node->type != XML_CDATA_SECTION_NODE))
6787 return(0); 6945 return(0);
6788 if (node->content == NULL) return(1); 6946 if (node->content == NULL) return(1);
6789 cur = node->content; 6947 cur = node->content;
6790 while (*cur != 0) { 6948 while (*cur != 0) {
6791 if (!IS_BLANK_CH(*cur)) return(0); 6949 if (!IS_BLANK_CH(*cur)) return(0);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
6896 return(NULL); 7054 return(NULL);
6897 } 7055 }
6898 ret->content[0] = 0; 7056 ret->content[0] = 0;
6899 } else 7057 } else
6900 ret->content = NULL; 7058 ret->content = NULL;
6901 ret->contentIO = NULL; 7059 ret->contentIO = NULL;
6902 return(ret); 7060 return(ret);
6903 } 7061 }
6904 7062
6905 /** 7063 /**
7064 * xmlBufferDetach:
7065 * @buf: the buffer
7066 *
7067 * Remove the string contained in a buffer and gie it back to the
7068 * caller. The buffer is reset to an empty content.
7069 * This doesn't work with immutable buffers as they can't be reset.
7070 *
7071 * Returns the previous string contained by the buffer.
7072 */
7073 xmlChar *
7074 xmlBufferDetach(xmlBufferPtr buf) {
7075 xmlChar *ret;
7076
7077 if (buf == NULL)
7078 return(NULL);
7079 if (buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE)
7080 return(NULL);
7081
7082 ret = buf->content;
7083 buf->content = NULL;
7084 buf->size = 0;
7085 buf->use = 0;
7086
7087 return ret;
7088 }
7089
7090
7091 /**
6906 * xmlBufferCreateStatic: 7092 * xmlBufferCreateStatic:
6907 * @mem: the memory area 7093 * @mem: the memory area
6908 * @size: the size in byte 7094 * @size: the size in byte
6909 * 7095 *
6910 * routine to create an XML buffer from an immutable memory area. 7096 * 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 7097 * The area won't be modified nor copied, and is expected to be
6912 * present until the end of the buffer lifetime. 7098 * present until the end of the buffer lifetime.
6913 * 7099 *
6914 * returns the new structure. 7100 * returns the new structure.
6915 */ 7101 */
(...skipping 30 matching lines...) Expand all
6946 #ifdef DEBUG_BUFFER 7132 #ifdef DEBUG_BUFFER
6947 xmlGenericError(xmlGenericErrorContext, 7133 xmlGenericError(xmlGenericErrorContext,
6948 "xmlBufferSetAllocationScheme: buf == NULL\n"); 7134 "xmlBufferSetAllocationScheme: buf == NULL\n");
6949 #endif 7135 #endif
6950 return; 7136 return;
6951 } 7137 }
6952 if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) || 7138 if ((buf->alloc == XML_BUFFER_ALLOC_IMMUTABLE) ||
6953 (buf->alloc == XML_BUFFER_ALLOC_IO)) return; 7139 (buf->alloc == XML_BUFFER_ALLOC_IO)) return;
6954 if ((scheme == XML_BUFFER_ALLOC_DOUBLEIT) || 7140 if ((scheme == XML_BUFFER_ALLOC_DOUBLEIT) ||
6955 (scheme == XML_BUFFER_ALLOC_EXACT) || 7141 (scheme == XML_BUFFER_ALLOC_EXACT) ||
7142 (scheme == XML_BUFFER_ALLOC_HYBRID) ||
6956 (scheme == XML_BUFFER_ALLOC_IMMUTABLE)) 7143 (scheme == XML_BUFFER_ALLOC_IMMUTABLE))
6957 buf->alloc = scheme; 7144 buf->alloc = scheme;
6958 } 7145 }
6959 7146
6960 /** 7147 /**
6961 * xmlBufferFree: 7148 * xmlBufferFree:
6962 * @buf: the buffer to free 7149 * @buf: the buffer to free
6963 * 7150 *
6964 * Frees an XML buffer. It frees both the content and the structure which 7151 * Frees an XML buffer. It frees both the content and the structure which
6965 * encapsulate it. 7152 * encapsulate it.
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
7145 /** 7332 /**
7146 * xmlBufferContent: 7333 * xmlBufferContent:
7147 * @buf: the buffer 7334 * @buf: the buffer
7148 * 7335 *
7149 * Function to extract the content of a buffer 7336 * Function to extract the content of a buffer
7150 * 7337 *
7151 * Returns the internal content 7338 * Returns the internal content
7152 */ 7339 */
7153 7340
7154 const xmlChar * 7341 const xmlChar *
7155 xmlBufferContent(const xmlBufferPtr buf) 7342 xmlBufferContent(const xmlBuffer *buf)
7156 { 7343 {
7157 if(!buf) 7344 if(!buf)
7158 return NULL; 7345 return NULL;
7159 7346
7160 return buf->content; 7347 return buf->content;
7161 } 7348 }
7162 7349
7163 /** 7350 /**
7164 * xmlBufferLength: 7351 * xmlBufferLength:
7165 * @buf: the buffer 7352 * @buf: the buffer
7166 * 7353 *
7167 * Function to get the length of a buffer 7354 * Function to get the length of a buffer
7168 * 7355 *
7169 * Returns the length of data in the internal content 7356 * Returns the length of data in the internal content
7170 */ 7357 */
7171 7358
7172 int 7359 int
7173 xmlBufferLength(const xmlBufferPtr buf) 7360 xmlBufferLength(const xmlBuffer *buf)
7174 { 7361 {
7175 if(!buf) 7362 if(!buf)
7176 return 0; 7363 return 0;
7177 7364
7178 return buf->use; 7365 return buf->use;
7179 } 7366 }
7180 7367
7181 /** 7368 /**
7182 * xmlBufferResize: 7369 * xmlBufferResize:
7183 * @buf: the buffer to resize 7370 * @buf: the buffer to resize
(...skipping 29 matching lines...) Expand all
7213 if (newSize > UINT_MAX / 2) { 7400 if (newSize > UINT_MAX / 2) {
7214 xmlTreeErrMemory("growing buffer"); 7401 xmlTreeErrMemory("growing buffer");
7215 return 0; 7402 return 0;
7216 } 7403 }
7217 newSize *= 2; 7404 newSize *= 2;
7218 } 7405 }
7219 break; 7406 break;
7220 case XML_BUFFER_ALLOC_EXACT: 7407 case XML_BUFFER_ALLOC_EXACT:
7221 newSize = size+10; 7408 newSize = size+10;
7222 break; 7409 break;
7410 case XML_BUFFER_ALLOC_HYBRID:
7411 if (buf->use < BASE_BUFFER_SIZE)
7412 newSize = size;
7413 else {
7414 newSize = buf->size * 2;
7415 while (size > newSize) {
7416 if (newSize > UINT_MAX / 2) {
7417 xmlTreeErrMemory("growing buffer");
7418 return 0;
7419 }
7420 newSize *= 2;
7421 }
7422 }
7423 break;
7424
7223 default: 7425 default:
7224 newSize = size+10; 7426 newSize = size+10;
7225 break; 7427 break;
7226 } 7428 }
7227 7429
7228 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) { 7430 if ((buf->alloc == XML_BUFFER_ALLOC_IO) && (buf->contentIO != NULL)) {
7229 start_buf = buf->content - buf->contentIO; 7431 start_buf = buf->content - buf->contentIO;
7230 7432
7231 if (start_buf > newSize) { 7433 if (start_buf > newSize) {
7232 /* move data back to start */ 7434 /* move data back to start */
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
7532 7734
7533 7735
7534 /** 7736 /**
7535 * xmlGetDocCompressMode: 7737 * xmlGetDocCompressMode:
7536 * @doc: the document 7738 * @doc: the document
7537 * 7739 *
7538 * get the compression ratio for a document, ZLIB based 7740 * get the compression ratio for a document, ZLIB based
7539 * Returns 0 (uncompressed) to 9 (max compression) 7741 * Returns 0 (uncompressed) to 9 (max compression)
7540 */ 7742 */
7541 int 7743 int
7542 xmlGetDocCompressMode (xmlDocPtr doc) { 7744 xmlGetDocCompressMode (const xmlDoc *doc) {
7543 if (doc == NULL) return(-1); 7745 if (doc == NULL) return(-1);
7544 return(doc->compression); 7746 return(doc->compression);
7545 } 7747 }
7546 7748
7547 /** 7749 /**
7548 * xmlSetDocCompressMode: 7750 * xmlSetDocCompressMode:
7549 * @doc: the document 7751 * @doc: the document
7550 * @mode: the compression ratio 7752 * @mode: the compression ratio
7551 * 7753 *
7552 * set the compression ratio for a document, ZLIB based 7754 * set the compression ratio for a document, ZLIB based
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
7723 ret->prev = map->last; 7925 ret->prev = map->last;
7724 map->last->next = ret; 7926 map->last->next = ret;
7725 map->last = ret; 7927 map->last = ret;
7726 } else if (position == 0) { 7928 } else if (position == 0) {
7727 /* 7929 /*
7728 * Set on first position. 7930 * Set on first position.
7729 */ 7931 */
7730 map->first->prev = ret; 7932 map->first->prev = ret;
7731 ret->next = map->first; 7933 ret->next = map->first;
7732 map->first = ret; 7934 map->first = ret;
7733 } else 7935 }
7734 » return(NULL);
7735 7936
7736 ret->oldNs = oldNs; 7937 ret->oldNs = oldNs;
7737 ret->newNs = newNs; 7938 ret->newNs = newNs;
7738 ret->shadowDepth = -1; 7939 ret->shadowDepth = -1;
7739 ret->depth = depth; 7940 ret->depth = depth;
7740 return (ret); 7941 return (ret);
7741 } 7942 }
7742 7943
7743 /* 7944 /*
7744 * xmlDOMWrapStoreNs: 7945 * xmlDOMWrapStoreNs:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
7784 return (ns->next); 7985 return (ns->next);
7785 } 7986 }
7786 return(NULL); 7987 return(NULL);
7787 } 7988 }
7788 7989
7789 /* 7990 /*
7790 * xmlDOMWrapNewCtxt: 7991 * xmlDOMWrapNewCtxt:
7791 * 7992 *
7792 * Allocates and initializes a new DOM-wrapper context. 7993 * Allocates and initializes a new DOM-wrapper context.
7793 * 7994 *
7794 * Returns the xmlDOMWrapCtxtPtr or NULL in case of an internal errror. 7995 * Returns the xmlDOMWrapCtxtPtr or NULL in case of an internal error.
7795 */ 7996 */
7796 xmlDOMWrapCtxtPtr 7997 xmlDOMWrapCtxtPtr
7797 xmlDOMWrapNewCtxt(void) 7998 xmlDOMWrapNewCtxt(void)
7798 { 7999 {
7799 xmlDOMWrapCtxtPtr ret; 8000 xmlDOMWrapCtxtPtr ret;
7800 8001
7801 ret = xmlMalloc(sizeof(xmlDOMWrapCtxt)); 8002 ret = xmlMalloc(sizeof(xmlDOMWrapCtxt));
7802 if (ret == NULL) { 8003 if (ret == NULL) {
7803 xmlTreeErrMemory("allocating DOM-wrapper context"); 8004 xmlTreeErrMemory("allocating DOM-wrapper context");
7804 return (NULL); 8005 return (NULL);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
7869 xmlDOMWrapNSNormGatherInScopeNs(xmlNsMapPtr *map, 8070 xmlDOMWrapNSNormGatherInScopeNs(xmlNsMapPtr *map,
7870 xmlNodePtr node) 8071 xmlNodePtr node)
7871 { 8072 {
7872 xmlNodePtr cur; 8073 xmlNodePtr cur;
7873 xmlNsPtr ns; 8074 xmlNsPtr ns;
7874 xmlNsMapItemPtr mi; 8075 xmlNsMapItemPtr mi;
7875 int shadowed; 8076 int shadowed;
7876 8077
7877 if ((map == NULL) || (*map != NULL)) 8078 if ((map == NULL) || (*map != NULL))
7878 return (-1); 8079 return (-1);
8080 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL))
8081 return (-1);
7879 /* 8082 /*
7880 * Get in-scope ns-decls of @parent. 8083 * Get in-scope ns-decls of @parent.
7881 */ 8084 */
7882 cur = node; 8085 cur = node;
7883 while ((cur != NULL) && (cur != (xmlNodePtr) cur->doc)) { 8086 while ((cur != NULL) && (cur != (xmlNodePtr) cur->doc)) {
7884 if (cur->type == XML_ELEMENT_NODE) { 8087 if (cur->type == XML_ELEMENT_NODE) {
7885 if (cur->nsDef != NULL) { 8088 if (cur->nsDef != NULL) {
7886 ns = cur->nsDef; 8089 ns = cur->nsDef;
7887 do { 8090 do {
7888 shadowed = 0; 8091 shadowed = 0;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
8136 static int 8339 static int
8137 xmlSearchNsByNamespaceStrict(xmlDocPtr doc, xmlNodePtr node, 8340 xmlSearchNsByNamespaceStrict(xmlDocPtr doc, xmlNodePtr node,
8138 const xmlChar* nsName, 8341 const xmlChar* nsName,
8139 xmlNsPtr *retNs, int prefixed) 8342 xmlNsPtr *retNs, int prefixed)
8140 { 8343 {
8141 xmlNodePtr cur, prev = NULL, out = NULL; 8344 xmlNodePtr cur, prev = NULL, out = NULL;
8142 xmlNsPtr ns, prevns; 8345 xmlNsPtr ns, prevns;
8143 8346
8144 if ((doc == NULL) || (nsName == NULL) || (retNs == NULL)) 8347 if ((doc == NULL) || (nsName == NULL) || (retNs == NULL))
8145 return (-1); 8348 return (-1);
8349 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL))
8350 return(-1);
8146 8351
8147 *retNs = NULL; 8352 *retNs = NULL;
8148 if (xmlStrEqual(nsName, XML_XML_NAMESPACE)) { 8353 if (xmlStrEqual(nsName, XML_XML_NAMESPACE)) {
8149 *retNs = xmlTreeEnsureXMLDecl(doc); 8354 *retNs = xmlTreeEnsureXMLDecl(doc);
8150 if (*retNs == NULL) 8355 if (*retNs == NULL)
8151 return (-1); 8356 return (-1);
8152 return (1); 8357 return (1);
8153 } 8358 }
8154 cur = node; 8359 cur = node;
8155 do { 8360 do {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
8234 * and internal errors. 8439 * and internal errors.
8235 */ 8440 */
8236 static int 8441 static int
8237 xmlSearchNsByPrefixStrict(xmlDocPtr doc, xmlNodePtr node, 8442 xmlSearchNsByPrefixStrict(xmlDocPtr doc, xmlNodePtr node,
8238 const xmlChar* prefix, 8443 const xmlChar* prefix,
8239 xmlNsPtr *retNs) 8444 xmlNsPtr *retNs)
8240 { 8445 {
8241 xmlNodePtr cur; 8446 xmlNodePtr cur;
8242 xmlNsPtr ns; 8447 xmlNsPtr ns;
8243 8448
8244 if ((doc == NULL) || (node == NULL)) 8449 if ((doc == NULL) || (node == NULL) || (node->type == XML_NAMESPACE_DECL))
8245 » return (-1); 8450 return(-1);
8246 8451
8247 if (retNs) 8452 if (retNs)
8248 *retNs = NULL; 8453 *retNs = NULL;
8249 if (IS_STR_XML(prefix)) { 8454 if (IS_STR_XML(prefix)) {
8250 if (retNs) { 8455 if (retNs) {
8251 *retNs = xmlTreeEnsureXMLDecl(doc); 8456 *retNs = xmlTreeEnsureXMLDecl(doc);
8252 if (*retNs == NULL) 8457 if (*retNs == NULL)
8253 return (-1); 8458 return (-1);
8254 } 8459 }
8255 return (1); 8460 return (1);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
8303 xmlNodePtr elem, 8508 xmlNodePtr elem,
8304 const xmlChar *nsName, 8509 const xmlChar *nsName,
8305 const xmlChar *prefix, 8510 const xmlChar *prefix,
8306 int checkShadow) 8511 int checkShadow)
8307 { 8512 {
8308 8513
8309 xmlNsPtr ret; 8514 xmlNsPtr ret;
8310 char buf[50]; 8515 char buf[50];
8311 const xmlChar *pref; 8516 const xmlChar *pref;
8312 int counter = 0; 8517 int counter = 0;
8518
8519 if ((doc == NULL) || (elem == NULL) || (elem->type != XML_ELEMENT_NODE))
8520 return(NULL);
8313 /* 8521 /*
8314 * Create a ns-decl on @anchor. 8522 * Create a ns-decl on @anchor.
8315 */ 8523 */
8316 pref = prefix; 8524 pref = prefix;
8317 while (1) { 8525 while (1) {
8318 /* 8526 /*
8319 * Lookup whether the prefix is unused in elem's ns-decls. 8527 * Lookup whether the prefix is unused in elem's ns-decls.
8320 */ 8528 */
8321 if ((elem->nsDef != NULL) && 8529 if ((elem->nsDef != NULL) &&
8322 (xmlTreeNSListLookupByPrefix(elem->nsDef, pref) != NULL)) 8530 (xmlTreeNSListLookupByPrefix(elem->nsDef, pref) != NULL))
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
8819 * 2) custom ns-reference handling is used 9027 * 2) custom ns-reference handling is used
8820 */ 9028 */
8821 if ((destParent == NULL) || 9029 if ((destParent == NULL) ||
8822 (ctxt && ctxt->getNsForNodeFunc)) 9030 (ctxt && ctxt->getNsForNodeFunc))
8823 { 9031 {
8824 parnsdone = 1; 9032 parnsdone = 1;
8825 } else 9033 } else
8826 parnsdone = 0; 9034 parnsdone = 0;
8827 9035
8828 cur = node; 9036 cur = node;
9037 if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL))
9038 goto internal_error;
9039
8829 while (cur != NULL) { 9040 while (cur != NULL) {
8830 /* 9041 /*
8831 * Paranoid source-doc sanity check. 9042 * Paranoid source-doc sanity check.
8832 */ 9043 */
8833 if (cur->doc != sourceDoc) { 9044 if (cur->doc != sourceDoc) {
8834 /* 9045 /*
8835 * We'll assume XIncluded nodes if the doc differs. 9046 * We'll assume XIncluded nodes if the doc differs.
8836 * TODO: Do we need to reconciliate XIncluded nodes? 9047 * TODO: Do we need to reconciliate XIncluded nodes?
8837 * This here skips XIncluded nodes and tries to handle 9048 * This here skips XIncluded nodes and tries to handle
8838 * broken sequences. 9049 * broken sequences.
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
9198 dict = destDoc->dict; 9409 dict = destDoc->dict;
9199 /* 9410 /*
9200 * Reuse the namespace map of the context. 9411 * Reuse the namespace map of the context.
9201 */ 9412 */
9202 if (ctxt) 9413 if (ctxt)
9203 nsMap = (xmlNsMapPtr) ctxt->namespaceMap; 9414 nsMap = (xmlNsMapPtr) ctxt->namespaceMap;
9204 9415
9205 *resNode = NULL; 9416 *resNode = NULL;
9206 9417
9207 cur = node; 9418 cur = node;
9419 if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL))
9420 return(-1);
9421
9208 while (cur != NULL) { 9422 while (cur != NULL) {
9209 if (cur->doc != sourceDoc) { 9423 if (cur->doc != sourceDoc) {
9210 /* 9424 /*
9211 * We'll assume XIncluded nodes if the doc differs. 9425 * We'll assume XIncluded nodes if the doc differs.
9212 * TODO: Do we need to reconciliate XIncluded nodes? 9426 * TODO: Do we need to reconciliate XIncluded nodes?
9213 * TODO: This here returns -1 in this case. 9427 * TODO: This here returns -1 in this case.
9214 */ 9428 */
9215 goto internal_error; 9429 goto internal_error;
9216 } 9430 }
9217 /* 9431 /*
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
9596 if (cur->next != NULL) { 9810 if (cur->next != NULL) {
9597 prevClone = clone; 9811 prevClone = clone;
9598 cur = cur->next; 9812 cur = cur->next;
9599 } else if (cur->type != XML_ATTRIBUTE_NODE) { 9813 } else if (cur->type != XML_ATTRIBUTE_NODE) {
9600 /* 9814 /*
9601 * Set clone->last. 9815 * Set clone->last.
9602 */ 9816 */
9603 if (clone->parent != NULL) 9817 if (clone->parent != NULL)
9604 clone->parent->last = clone; 9818 clone->parent->last = clone;
9605 clone = clone->parent; 9819 clone = clone->parent;
9606 » parentClone = clone->parent; 9820 » if (clone != NULL)
9821 » » parentClone = clone->parent;
9607 /* 9822 /*
9608 * Process parent --> next; 9823 * Process parent --> next;
9609 */ 9824 */
9610 cur = cur->parent; 9825 cur = cur->parent;
9611 goto leave_node; 9826 goto leave_node;
9612 } else { 9827 } else {
9613 /* This is for attributes only. */ 9828 /* This is for attributes only. */
9614 clone = clone->parent; 9829 clone = clone->parent;
9615 parentClone = clone->parent; 9830 parentClone = clone->parent;
9616 /* 9831 /*
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
9715 9930
9716 XML_TREE_ADOPT_STR(attr->name); 9931 XML_TREE_ADOPT_STR(attr->name);
9717 attr->atype = 0; 9932 attr->atype = 0;
9718 attr->psvi = NULL; 9933 attr->psvi = NULL;
9719 /* 9934 /*
9720 * Walk content. 9935 * Walk content.
9721 */ 9936 */
9722 if (attr->children == NULL) 9937 if (attr->children == NULL)
9723 return (0); 9938 return (0);
9724 cur = attr->children; 9939 cur = attr->children;
9940 if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL))
9941 goto internal_error;
9725 while (cur != NULL) { 9942 while (cur != NULL) {
9726 cur->doc = destDoc; 9943 cur->doc = destDoc;
9727 switch (cur->type) { 9944 switch (cur->type) {
9728 case XML_TEXT_NODE: 9945 case XML_TEXT_NODE:
9729 case XML_CDATA_SECTION_NODE: 9946 case XML_CDATA_SECTION_NODE:
9730 XML_TREE_ADOPT_STR_2(cur->content) 9947 XML_TREE_ADOPT_STR_2(cur->content)
9731 break; 9948 break;
9732 case XML_ENTITY_REF_NODE: 9949 case XML_ENTITY_REF_NODE:
9733 /* 9950 /*
9734 * Remove reference to the entitity-node. 9951 * Remove reference to the entitity-node.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
9776 * @ctxt: the optional context for custom processing 9993 * @ctxt: the optional context for custom processing
9777 * @sourceDoc: the optional sourceDoc 9994 * @sourceDoc: the optional sourceDoc
9778 * @node: the node to start with 9995 * @node: the node to start with
9779 * @destDoc: the destination doc 9996 * @destDoc: the destination doc
9780 * @destParent: the optional new parent of @node in @destDoc 9997 * @destParent: the optional new parent of @node in @destDoc
9781 * @options: option flags 9998 * @options: option flags
9782 * 9999 *
9783 * References of out-of scope ns-decls are remapped to point to @destDoc: 10000 * 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 10001 * 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 10002 * 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 10003 * This is the case when you have an unlinked node and just want to move it
9787 * to the context of 10004 * to the context of
9788 * 10005 *
9789 * If @destParent is given, it ensures that the tree is namespace 10006 * If @destParent is given, it ensures that the tree is namespace
9790 * wellformed by creating additional ns-decls where needed. 10007 * wellformed by creating additional ns-decls where needed.
9791 * Note that, since prefixes of already existent ns-decls can be 10008 * Note that, since prefixes of already existent ns-decls can be
9792 * shadowed by this process, it could break QNames in attribute 10009 * shadowed by this process, it could break QNames in attribute
9793 * values or element content. 10010 * values or element content.
9794 * NOTE: This function was not intensively tested. 10011 * NOTE: This function was not intensively tested.
9795 * 10012 *
9796 * Returns 0 if the operation succeeded, 10013 * Returns 0 if the operation succeeded,
9797 * 1 if a node of unsupported type was given, 10014 * 1 if a node of unsupported type was given,
9798 * 2 if a node of not yet supported type was given and 10015 * 2 if a node of not yet supported type was given and
9799 * -1 on API/internal errors. 10016 * -1 on API/internal errors.
9800 */ 10017 */
9801 int 10018 int
9802 xmlDOMWrapAdoptNode(xmlDOMWrapCtxtPtr ctxt, 10019 xmlDOMWrapAdoptNode(xmlDOMWrapCtxtPtr ctxt,
9803 xmlDocPtr sourceDoc, 10020 xmlDocPtr sourceDoc,
9804 xmlNodePtr node, 10021 xmlNodePtr node,
9805 xmlDocPtr destDoc, 10022 xmlDocPtr destDoc,
9806 xmlNodePtr destParent, 10023 xmlNodePtr destParent,
9807 int options) 10024 int options)
9808 { 10025 {
9809 if ((node == NULL) || (destDoc == NULL) || 10026 if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) ||
10027 (destDoc == NULL) ||
9810 ((destParent != NULL) && (destParent->doc != destDoc))) 10028 ((destParent != NULL) && (destParent->doc != destDoc)))
9811 return(-1); 10029 return(-1);
9812 /* 10030 /*
9813 * Check node->doc sanity. 10031 * Check node->doc sanity.
9814 */ 10032 */
9815 if ((node->doc != NULL) && (sourceDoc != NULL) && 10033 if ((node->doc != NULL) && (sourceDoc != NULL) &&
9816 (node->doc != sourceDoc)) { 10034 (node->doc != sourceDoc)) {
9817 /* 10035 /*
9818 * Might be an XIncluded node. 10036 * Might be an XIncluded node.
9819 */ 10037 */
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
9894 } 10112 }
9895 default: 10113 default:
9896 break; 10114 break;
9897 } 10115 }
9898 } 10116 }
9899 return (0); 10117 return (0);
9900 } 10118 }
9901 10119
9902 #define bottom_tree 10120 #define bottom_tree
9903 #include "elfgcchack.h" 10121 #include "elfgcchack.h"
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698