diff options
Diffstat (limited to 'tree.c')
-rw-r--r-- | tree.c | 301 |
1 files changed, 98 insertions, 203 deletions
@@ -41,9 +41,6 @@ #include <libxml/debugXML.h> #endif -#include "buf.h" -#include "save.h" - int __xmlRegisterCallbacks = 0; /************************************************************************ @@ -314,7 +311,7 @@ xmlSplitQName2(const xmlChar *name, xmlChar **prefix) { * parse an XML qualified name string,i * * returns NULL if it is not a Qualified Name, otherwise, update len - * with the length in byte of the prefix and return a pointer + * with the lenght in byte of the prefix and return a pointer * to the start of the name without the prefix */ @@ -1268,13 +1265,13 @@ xmlStringLenGetNodeList(xmlDocPtr doc, const xmlChar *value, int len) { const xmlChar *cur = value, *end = cur + len; const xmlChar *q; xmlEntityPtr ent; - xmlBufPtr buf; + xmlBufferPtr buffer; if (value == NULL) return(NULL); - buf = xmlBufCreateSize(0); - if (buf == NULL) return(NULL); - xmlBufSetAllocationScheme(buf, XML_BUFFER_ALLOC_HYBRID); + buffer = xmlBufferCreateSize(0); + if (buffer == NULL) return(NULL); + xmlBufferSetAllocationScheme(buffer, XML_BUFFER_ALLOC_HYBRID); q = cur; while ((cur < end) && (*cur != 0)) { @@ -1286,7 +1283,7 @@ xmlStringLenGetNodeList(xmlDocPtr doc, const xmlChar *value, int len) { * Save the current text. */ if (cur != q) { - if (xmlBufAdd(buf, q, cur - q)) + if (xmlBufferAdd(buffer, q, cur - q)) goto out; } q = cur; @@ -1363,20 +1360,20 @@ xmlStringLenGetNodeList(xmlDocPtr doc, const xmlChar *value, int len) { if ((ent != NULL) && (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { - if (xmlBufCat(buf, ent->content)) + if (xmlBufferCat(buffer, ent->content)) goto out; } else { /* * Flush buffer so far */ - if (!xmlBufIsEmpty(buf)) { + if (buffer->use) { node = xmlNewDocText(doc, NULL); if (node == NULL) { if (val != NULL) xmlFree(val); goto out; } - node->content = xmlBufDetach(buf); + node->content = xmlBufferDetach(buffer); if (last == NULL) { last = ret = node; @@ -1418,13 +1415,13 @@ xmlStringLenGetNodeList(xmlDocPtr doc, const xmlChar *value, int len) { q = cur; } if (charval != 0) { - xmlChar buffer[10]; + xmlChar buf[10]; int l; - l = xmlCopyCharMultiByte(buffer, charval); - buffer[l] = 0; + l = xmlCopyCharMultiByte(buf, charval); + buf[l] = 0; - if (xmlBufCat(buf, buffer)) + if (xmlBufferCat(buffer, buf)) goto out; charval = 0; } @@ -1436,14 +1433,14 @@ xmlStringLenGetNodeList(xmlDocPtr doc, const xmlChar *value, int len) { /* * Handle the last piece of text. */ - if (xmlBufAdd(buf, q, cur - q)) + if (xmlBufferAdd(buffer, q, cur - q)) goto out; } - if (!xmlBufIsEmpty(buf)) { + if (buffer->use) { node = xmlNewDocText(doc, NULL); if (node == NULL) goto out; - node->content = xmlBufDetach(buf); + node->content = xmlBufferDetach(buffer); if (last == NULL) { last = ret = node; @@ -1455,7 +1452,7 @@ xmlStringLenGetNodeList(xmlDocPtr doc, const xmlChar *value, int len) { } out: - xmlBufFree(buf); + xmlBufferFree(buffer); return(ret); } @@ -1476,13 +1473,13 @@ xmlStringGetNodeList(xmlDocPtr doc, const xmlChar *value) { const xmlChar *cur = value; const xmlChar *q; xmlEntityPtr ent; - xmlBufPtr buf; + xmlBufferPtr buffer; if (value == NULL) return(NULL); - buf = xmlBufCreateSize(0); - if (buf == NULL) return(NULL); - xmlBufSetAllocationScheme(buf, XML_BUFFER_ALLOC_HYBRID); + buffer = xmlBufferCreateSize(0); + if (buffer == NULL) return(NULL); + xmlBufferSetAllocationScheme(buffer, XML_BUFFER_ALLOC_HYBRID); q = cur; while (*cur != 0) { @@ -1494,7 +1491,7 @@ xmlStringGetNodeList(xmlDocPtr doc, const xmlChar *value) { * Save the current text. */ if (cur != q) { - if (xmlBufAdd(buf, q, cur - q)) + if (xmlBufferAdd(buffer, q, cur - q)) goto out; } q = cur; @@ -1559,16 +1556,16 @@ xmlStringGetNodeList(xmlDocPtr doc, const xmlChar *value) { if ((ent != NULL) && (ent->etype == XML_INTERNAL_PREDEFINED_ENTITY)) { - if (xmlBufCat(buf, ent->content)) + if (xmlBufferCat(buffer, ent->content)) goto out; } else { /* * Flush buffer so far */ - if (!xmlBufIsEmpty(buf)) { + if (buffer->use) { node = xmlNewDocText(doc, NULL); - node->content = xmlBufDetach(buf); + node->content = xmlBufferDetach(buffer); if (last == NULL) { last = ret = node; @@ -1609,13 +1606,13 @@ xmlStringGetNodeList(xmlDocPtr doc, const xmlChar *value) { q = cur; } if (charval != 0) { - xmlChar buffer[10]; + xmlChar buf[10]; int len; - len = xmlCopyCharMultiByte(buffer, charval); - buffer[len] = 0; + len = xmlCopyCharMultiByte(buf, charval); + buf[len] = 0; - if (xmlBufCat(buf, buffer)) + if (xmlBufferCat(buffer, buf)) goto out; charval = 0; } @@ -1626,12 +1623,12 @@ xmlStringGetNodeList(xmlDocPtr doc, const xmlChar *value) { /* * Handle the last piece of text. */ - xmlBufAdd(buf, q, cur - q); + xmlBufferAdd(buffer, q, cur - q); } - if (!xmlBufIsEmpty(buf)) { + if (buffer->use) { node = xmlNewDocText(doc, NULL); - node->content = xmlBufDetach(buf); + node->content = xmlBufferDetach(buffer); if (last == NULL) { last = ret = node; @@ -1641,7 +1638,7 @@ xmlStringGetNodeList(xmlDocPtr doc, const xmlChar *value) { } out: - xmlBufFree(buf); + xmlBufferFree(buffer); return(ret); } @@ -1662,14 +1659,9 @@ xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine) xmlNodePtr node = list; xmlChar *ret = NULL; xmlEntityPtr ent; - int attr; if (list == NULL) return (NULL); - if ((list->parent != NULL) && (list->parent->type == XML_ATTRIBUTE_NODE)) - attr = 1; - else - attr = 0; while (node != NULL) { if ((node->type == XML_TEXT_NODE) || @@ -1679,10 +1671,7 @@ xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine) } else { xmlChar *buffer; - if (attr) - buffer = xmlEncodeAttributeEntities(doc, node->content); - else - buffer = xmlEncodeEntitiesReentrant(doc, node->content); + buffer = xmlEncodeEntitiesReentrant(doc, node->content); if (buffer != NULL) { ret = xmlStrcat(ret, buffer); xmlFree(buffer); @@ -2788,7 +2777,7 @@ void xmlSetTreeDoc(xmlNodePtr tree, xmlDocPtr doc) { xmlAttrPtr prop; - if ((tree == NULL) || (tree->type == XML_NAMESPACE_DECL)) + if (tree == NULL) return; if (tree->doc != doc) { if(tree->type == XML_ELEMENT_NODE) { @@ -2816,7 +2805,7 @@ void xmlSetListDoc(xmlNodePtr list, xmlDocPtr doc) { xmlNodePtr cur; - if ((list == NULL) || (list->type == XML_NAMESPACE_DECL)) + if (list == NULL) return; cur = list; while (cur != NULL) { @@ -2923,9 +2912,7 @@ static xmlNodePtr xmlAddPropSibling(xmlNodePtr prev, xmlNodePtr cur, xmlNodePtr prop) { xmlAttrPtr attr; - if ((cur == NULL) || (cur->type != XML_ATTRIBUTE_NODE) || - (prop == NULL) || (prop->type != XML_ATTRIBUTE_NODE) || - ((prev != NULL) && (prev->type != XML_ATTRIBUTE_NODE))) + if (cur->type != XML_ATTRIBUTE_NODE) return(NULL); /* check if an attribute with the same name exists */ @@ -2973,14 +2960,14 @@ xmlAddPropSibling(xmlNodePtr prev, xmlNodePtr cur, xmlNodePtr prop) { */ xmlNodePtr xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) { - if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { + if (cur == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, "xmlAddNextSibling : cur == NULL\n"); #endif return(NULL); } - if ((elem == NULL) || (elem->type == XML_NAMESPACE_DECL)) { + if (elem == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, "xmlAddNextSibling : elem == NULL\n"); @@ -3051,14 +3038,14 @@ xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) { */ xmlNodePtr xmlAddPrevSibling(xmlNodePtr cur, xmlNodePtr elem) { - if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { + if (cur == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, "xmlAddPrevSibling : cur == NULL\n"); #endif return(NULL); } - if ((elem == NULL) || (elem->type == XML_NAMESPACE_DECL)) { + if (elem == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, "xmlAddPrevSibling : elem == NULL\n"); @@ -3129,7 +3116,7 @@ xmlNodePtr xmlAddSibling(xmlNodePtr cur, xmlNodePtr elem) { xmlNodePtr parent; - if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { + if (cur == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, "xmlAddSibling : cur == NULL\n"); @@ -3137,7 +3124,7 @@ xmlAddSibling(xmlNodePtr cur, xmlNodePtr elem) { return(NULL); } - if ((elem == NULL) || (elem->type == XML_NAMESPACE_DECL)) { + if (elem == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, "xmlAddSibling : elem == NULL\n"); @@ -3205,7 +3192,7 @@ xmlNodePtr xmlAddChildList(xmlNodePtr parent, xmlNodePtr cur) { xmlNodePtr prev; - if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) { + if (parent == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, "xmlAddChildList : parent == NULL\n"); @@ -3213,7 +3200,7 @@ xmlAddChildList(xmlNodePtr parent, xmlNodePtr cur) { return(NULL); } - if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { + if (cur == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, "xmlAddChildList : child == NULL\n"); @@ -3291,7 +3278,7 @@ xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { xmlNodePtr prev; - if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) { + if (parent == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, "xmlAddChild : parent == NULL\n"); @@ -3299,7 +3286,7 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { return(NULL); } - if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { + if (cur == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, "xmlAddChild : child == NULL\n"); @@ -3413,7 +3400,7 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { */ xmlNodePtr xmlGetLastChild(xmlNodePtr parent) { - if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) { + if (parent == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, "xmlGetLastChild : parent == NULL\n"); @@ -3765,8 +3752,6 @@ xmlFreeNode(xmlNodePtr cur) { * Unlink a node from it's current context, the node is not freed * If one need to free the node, use xmlFreeNode() routine after the * unlink to discard it. - * Note that namespace nodes can't be unlinked as they do not have - * pointer to their parent. */ void xmlUnlinkNode(xmlNodePtr cur) { @@ -3777,8 +3762,6 @@ xmlUnlinkNode(xmlNodePtr cur) { #endif return; } - if (cur->type == XML_NAMESPACE_DECL) - return; if (cur->type == XML_DTD_NODE) { xmlDocPtr doc; doc = cur->doc; @@ -3847,15 +3830,14 @@ xmlUnlinkNode(xmlNodePtr cur) { xmlNodePtr xmlReplaceNode(xmlNodePtr old, xmlNodePtr cur) { if (old == cur) return(NULL); - if ((old == NULL) || (old->type == XML_NAMESPACE_DECL) || - (old->parent == NULL)) { + if ((old == NULL) || (old->parent == NULL)) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, "xmlReplaceNode : old == NULL or without parent\n"); #endif return(NULL); } - if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) { + if (cur == NULL) { xmlUnlinkNode(old); return(old); } @@ -3969,8 +3951,6 @@ xmlCopyPropInternal(xmlDocPtr doc, xmlNodePtr target, xmlAttrPtr cur) { xmlAttrPtr ret; if (cur == NULL) return(NULL); - if ((target != NULL) && (target->type != XML_ELEMENT_NODE)) - return(NULL); if (target != NULL) ret = xmlNewDocProp(target->doc, cur->name, NULL); else if (doc != NULL) @@ -4090,8 +4070,6 @@ xmlCopyPropList(xmlNodePtr target, xmlAttrPtr cur) { xmlAttrPtr ret = NULL; xmlAttrPtr p = NULL,q; - if ((target != NULL) && (target->type != XML_ELEMENT_NODE)) - return(NULL); while (cur != NULL) { q = xmlCopyProp(target, cur); if (q == NULL) @@ -4537,71 +4515,39 @@ xmlCopyDoc(xmlDocPtr doc, int recursive) { ************************************************************************/ /** - * xmlGetLineNoInternal: + * xmlGetLineNo: * @node: valid node - * @depth: used to limit any risk of recursion * - * Get line number of @node. - * Try to override the limitation of lines being store in 16 bits ints + * Get line number of @node. This requires activation of this option + * before invoking the parser by calling xmlLineNumbersDefault(1) * * Returns the line number if successful, -1 otherwise */ -static long -xmlGetLineNoInternal(xmlNodePtr node, int depth) +long +xmlGetLineNo(xmlNodePtr node) { long result = -1; - if (depth >= 5) - return(-1); - if (!node) return result; if ((node->type == XML_ELEMENT_NODE) || (node->type == XML_TEXT_NODE) || (node->type == XML_COMMENT_NODE) || - (node->type == XML_PI_NODE)) { - if (node->line == 65535) { - if ((node->type == XML_TEXT_NODE) && (node->psvi != NULL)) - result = (long) node->psvi; - else if ((node->type == XML_ELEMENT_NODE) && - (node->children != NULL)) - result = xmlGetLineNoInternal(node->children, depth + 1); - else if (node->next != NULL) - result = xmlGetLineNoInternal(node->next, depth + 1); - else if (node->prev != NULL) - result = xmlGetLineNoInternal(node->prev, depth + 1); - } - if ((result == -1) || (result == 65535)) - result = (long) node->line; - } else if ((node->prev != NULL) && + (node->type == XML_PI_NODE)) + result = (long) node->line; + else if ((node->prev != NULL) && ((node->prev->type == XML_ELEMENT_NODE) || (node->prev->type == XML_TEXT_NODE) || (node->prev->type == XML_COMMENT_NODE) || (node->prev->type == XML_PI_NODE))) - result = xmlGetLineNoInternal(node->prev, depth + 1); + result = xmlGetLineNo(node->prev); else if ((node->parent != NULL) && (node->parent->type == XML_ELEMENT_NODE)) - result = xmlGetLineNoInternal(node->parent, depth + 1); + result = xmlGetLineNo(node->parent); return result; } -/** - * xmlGetLineNo: - * @node: valid node - * - * Get line number of @node. - * Try to override the limitation of lines being store in 16 bits ints - * if XML_PARSE_BIG_LINES parser option was used - * - * Returns the line number if successful, -1 otherwise - */ -long -xmlGetLineNo(xmlNodePtr node) -{ - return(xmlGetLineNoInternal(node, 0)); -} - #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_DEBUG_ENABLED) /** * xmlGetNodePath: @@ -4624,7 +4570,7 @@ xmlGetNodePath(xmlNodePtr node) char nametemp[100]; int occur = 0, generic; - if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) + if (node == NULL) return (NULL); buf_len = 500; @@ -4889,7 +4835,7 @@ xmlDocSetRootElement(xmlDocPtr doc, xmlNodePtr root) { xmlNodePtr old = NULL; if (doc == NULL) return(NULL); - if ((root == NULL) || (root->type == XML_NAMESPACE_DECL)) + if (root == NULL) return(NULL); xmlUnlinkNode(root); xmlSetTreeDoc(root, doc); @@ -4976,8 +4922,6 @@ xmlChar * xmlNodeGetLang(xmlNodePtr cur) { xmlChar *lang; - if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) - return(NULL); while (cur != NULL) { lang = xmlGetNsProp(cur, BAD_CAST "lang", XML_XML_NAMESPACE); if (lang != NULL) @@ -5057,8 +5001,6 @@ int xmlNodeGetSpacePreserve(xmlNodePtr cur) { xmlChar *space; - if ((cur == NULL) || (cur->type != XML_ELEMENT_NODE)) - return(-1); while (cur != NULL) { space = xmlGetNsProp(cur, BAD_CAST "space", XML_XML_NAMESPACE); if (space != NULL) { @@ -5225,8 +5167,6 @@ xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) { if ((cur == NULL) && (doc == NULL)) return(NULL); - if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) - return(NULL); if (doc == NULL) doc = cur->doc; if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) { cur = doc->children; @@ -5306,39 +5246,11 @@ xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) { int xmlNodeBufGetContent(xmlBufferPtr buffer, xmlNodePtr cur) { - xmlBufPtr buf; - int ret; - if ((cur == NULL) || (buffer == NULL)) return(-1); - buf = xmlBufFromBuffer(buffer); - ret = xmlBufGetNodeContent(buf, cur); - buffer = xmlBufBackToBuffer(buf); - if ((ret < 0) || (buffer == NULL)) - return(-1); - return(0); -} - -/** - * xmlBufGetNodeContent: - * @buf: a buffer xmlBufPtr - * @cur: the node being read - * - * Read the value of a node @cur, this can be either the text carried - * directly by this node if it's a TEXT node or the aggregate string - * of the values carried by this node child's (TEXT and ENTITY_REF). - * Entity references are substituted. - * Fills up the buffer @buffer with this value - * - * Returns 0 in case of success and -1 in case of error. - */ -int -xmlBufGetNodeContent(xmlBufPtr buf, xmlNodePtr cur) -{ - if ((cur == NULL) || (buf == NULL)) return(-1); switch (cur->type) { case XML_CDATA_SECTION_NODE: case XML_TEXT_NODE: - xmlBufCat(buf, cur->content); + xmlBufferCat(buffer, cur->content); break; case XML_DOCUMENT_FRAG_NODE: case XML_ELEMENT_NODE:{ @@ -5349,10 +5261,10 @@ xmlBufGetNodeContent(xmlBufPtr buf, xmlNodePtr cur) case XML_CDATA_SECTION_NODE: case XML_TEXT_NODE: if (tmp->content != NULL) - xmlBufCat(buf, tmp->content); + xmlBufferCat(buffer, tmp->content); break; case XML_ENTITY_REF_NODE: - xmlBufGetNodeContent(buf, tmp); + xmlNodeBufGetContent(buffer, tmp); break; default: break; @@ -5396,16 +5308,16 @@ xmlBufGetNodeContent(xmlBufPtr buf, xmlNodePtr cur) while (tmp != NULL) { if (tmp->type == XML_TEXT_NODE) - xmlBufCat(buf, tmp->content); + xmlBufferCat(buffer, tmp->content); else - xmlBufGetNodeContent(buf, tmp); + xmlNodeBufGetContent(buffer, tmp); tmp = tmp->next; } break; } case XML_COMMENT_NODE: case XML_PI_NODE: - xmlBufCat(buf, cur->content); + xmlBufferCat(buffer, cur->content); break; case XML_ENTITY_REF_NODE:{ xmlEntityPtr ent; @@ -5423,7 +5335,7 @@ xmlBufGetNodeContent(xmlBufPtr buf, xmlNodePtr cur) * xmlNodeGetContent() which handles all possible node types */ tmp = ent->children; while (tmp) { - xmlBufGetNodeContent(buf, tmp); + xmlNodeBufGetContent(buffer, tmp); tmp = tmp->next; } break; @@ -5445,13 +5357,13 @@ xmlBufGetNodeContent(xmlBufPtr buf, xmlNodePtr cur) if ((cur->type == XML_ELEMENT_NODE) || (cur->type == XML_TEXT_NODE) || (cur->type == XML_CDATA_SECTION_NODE)) { - xmlBufGetNodeContent(buf, cur); + xmlNodeBufGetContent(buffer, cur); } cur = cur->next; } break; case XML_NAMESPACE_DECL: - xmlBufCat(buf, ((xmlNsPtr) cur)->href); + xmlBufferCat(buffer, ((xmlNsPtr) cur)->href); break; case XML_ELEMENT_DECL: case XML_ATTRIBUTE_DECL: @@ -5460,7 +5372,6 @@ xmlBufGetNodeContent(xmlBufPtr buf, xmlNodePtr cur) } return(0); } - /** * xmlNodeGetContent: * @cur: the node being read @@ -5480,15 +5391,16 @@ xmlNodeGetContent(xmlNodePtr cur) switch (cur->type) { case XML_DOCUMENT_FRAG_NODE: case XML_ELEMENT_NODE:{ - xmlBufPtr buf; + xmlBufferPtr buffer; xmlChar *ret; - buf = xmlBufCreateSize(64); - if (buf == NULL) + buffer = xmlBufferCreateSize(64); + if (buffer == NULL) return (NULL); - xmlBufGetNodeContent(buf, cur); - ret = xmlBufDetach(buf); - xmlBufFree(buf); + xmlNodeBufGetContent(buffer, cur); + ret = buffer->content; + buffer->content = NULL; + xmlBufferFree(buffer); return (ret); } case XML_ATTRIBUTE_NODE: @@ -5500,7 +5412,7 @@ xmlNodeGetContent(xmlNodePtr cur) return (NULL); case XML_ENTITY_REF_NODE:{ xmlEntityPtr ent; - xmlBufPtr buf; + xmlBufferPtr buffer; xmlChar *ret; /* lookup entity declaration */ @@ -5508,14 +5420,15 @@ xmlNodeGetContent(xmlNodePtr cur) if (ent == NULL) return (NULL); - buf = xmlBufCreate(); - if (buf == NULL) + buffer = xmlBufferCreate(); + if (buffer == NULL) return (NULL); - xmlBufGetNodeContent(buf, cur); + xmlNodeBufGetContent(buffer, cur); - ret = xmlBufDetach(buf); - xmlBufFree(buf); + ret = buffer->content; + buffer->content = NULL; + xmlBufferFree(buffer); return (ret); } case XML_ENTITY_NODE: @@ -5530,17 +5443,18 @@ xmlNodeGetContent(xmlNodePtr cur) case XML_DOCB_DOCUMENT_NODE: #endif case XML_HTML_DOCUMENT_NODE: { - xmlBufPtr buf; + xmlBufferPtr buffer; xmlChar *ret; - buf = xmlBufCreate(); - if (buf == NULL) + buffer = xmlBufferCreate(); + if (buffer == NULL) return (NULL); - xmlBufGetNodeContent(buf, (xmlNodePtr) cur); + xmlNodeBufGetContent(buffer, (xmlNodePtr) cur); - ret = xmlBufDetach(buf); - xmlBufFree(buf); + ret = buffer->content; + buffer->content = NULL; + xmlBufferFree(buffer); return (ret); } case XML_NAMESPACE_DECL: { @@ -5861,9 +5775,6 @@ xmlGetNsList(xmlDocPtr doc ATTRIBUTE_UNUSED, xmlNodePtr node) int maxns = 10; int i; - if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) - return(NULL); - while (node != NULL) { if (node->type == XML_ELEMENT_NODE) { cur = node->nsDef; @@ -5962,7 +5873,7 @@ xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace) { xmlNsPtr cur; xmlNodePtr orig = node; - if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) return(NULL); + if (node == NULL) return(NULL); if ((nameSpace != NULL) && (xmlStrEqual(nameSpace, (const xmlChar *)"xml"))) { if ((doc == NULL) && (node->type == XML_ELEMENT_NODE)) { @@ -6092,7 +6003,7 @@ xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node, const xmlChar * href) xmlNodePtr orig = node; int is_attr; - if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) || (href == NULL)) + if ((node == NULL) || (href == NULL)) return (NULL); if (xmlStrEqual(href, XML_XML_NAMESPACE)) { /* @@ -6183,7 +6094,7 @@ xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns) { xmlChar prefix[50]; int counter = 1; - if ((tree == NULL) || (tree->type != XML_ELEMENT_NODE)) { + if (tree == NULL) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, "xmlNewReconciliedNs : tree == NULL\n"); @@ -8040,8 +7951,6 @@ xmlDOMWrapNSNormGatherInScopeNs(xmlNsMapPtr *map, if ((map == NULL) || (*map != NULL)) return (-1); - if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) - return (-1); /* * Get in-scope ns-decls of @parent. */ @@ -8309,8 +8218,6 @@ xmlSearchNsByNamespaceStrict(xmlDocPtr doc, xmlNodePtr node, if ((doc == NULL) || (nsName == NULL) || (retNs == NULL)) return (-1); - if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) - return(-1); *retNs = NULL; if (xmlStrEqual(nsName, XML_XML_NAMESPACE)) { @@ -8409,8 +8316,8 @@ xmlSearchNsByPrefixStrict(xmlDocPtr doc, xmlNodePtr node, xmlNodePtr cur; xmlNsPtr ns; - if ((doc == NULL) || (node == NULL) || (node->type == XML_NAMESPACE_DECL)) - return(-1); + if ((doc == NULL) || (node == NULL)) + return (-1); if (retNs) *retNs = NULL; @@ -8478,9 +8385,6 @@ xmlDOMWrapNSNormDeclareNsForced(xmlDocPtr doc, char buf[50]; const xmlChar *pref; int counter = 0; - - if ((doc == NULL) || (elem == NULL) || (elem->type != XML_ELEMENT_NODE)) - return(NULL); /* * Create a ns-decl on @anchor. */ @@ -8997,9 +8901,6 @@ xmlDOMWrapAdoptBranch(xmlDOMWrapCtxtPtr ctxt, parnsdone = 0; cur = node; - if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) - goto internal_error; - while (cur != NULL) { /* * Paranoid source-doc sanity check. @@ -9379,9 +9280,6 @@ xmlDOMWrapCloneNode(xmlDOMWrapCtxtPtr ctxt, *resNode = NULL; cur = node; - if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) - return(-1); - while (cur != NULL) { if (cur->doc != sourceDoc) { /* @@ -9899,8 +9797,6 @@ xmlDOMWrapAdoptAttr(xmlDOMWrapCtxtPtr ctxt, if (attr->children == NULL) return (0); cur = attr->children; - if ((cur != NULL) && (cur->type == XML_NAMESPACE_DECL)) - goto internal_error; while (cur != NULL) { cur->doc = destDoc; switch (cur->type) { @@ -9985,8 +9881,7 @@ xmlDOMWrapAdoptNode(xmlDOMWrapCtxtPtr ctxt, xmlNodePtr destParent, int options) { - if ((node == NULL) || (node->type == XML_NAMESPACE_DECL) || - (destDoc == NULL) || + if ((node == NULL) || (destDoc == NULL) || ((destParent != NULL) && (destParent->doc != destDoc))) return(-1); /* |