diff options
Diffstat (limited to 'tree.c')
-rw-r--r-- | tree.c | 133 |
1 files changed, 57 insertions, 76 deletions
@@ -55,7 +55,7 @@ int __xmlRegisterCallbacks = 0; static xmlNsPtr xmlNewReconciliedNs(xmlDocPtr doc, xmlNodePtr tree, xmlNsPtr ns); -static xmlChar* xmlGetPropNodeValueInternal(const xmlAttr *prop); +static xmlChar* xmlGetPropNodeValueInternal(xmlAttrPtr prop); /************************************************************************ * * @@ -160,7 +160,7 @@ static int xmlCheckDTD = 1; * Returns A pointer to the entity structure or NULL if not found. */ static xmlEntityPtr -xmlGetEntityFromDtd(const xmlDtd *dtd, const xmlChar *name) { +xmlGetEntityFromDtd(xmlDtdPtr dtd, const xmlChar *name) { xmlEntitiesTablePtr table; if((dtd != NULL) && (dtd->entities != NULL)) { @@ -181,7 +181,7 @@ xmlGetEntityFromDtd(const xmlDtd *dtd, const xmlChar *name) { * Returns A pointer to the entity structure or NULL if not found. */ static xmlEntityPtr -xmlGetParameterEntityFromDtd(const xmlDtd *dtd, const xmlChar *name) { +xmlGetParameterEntityFromDtd(xmlDtdPtr dtd, const xmlChar *name) { xmlEntitiesTablePtr table; if ((dtd != NULL) && (dtd->pentities != NULL)) { @@ -352,7 +352,7 @@ xmlSplitQName3(const xmlChar *name, int *len) { #define CUR_SCHAR(s, l) xmlStringCurrentChar(NULL, s, &l) -#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) || defined (LIBXML_HTML_ENABLED) || defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) || defined(LIBXML_LEGACY_ENABLED) +#if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_DEBUG_ENABLED) || defined (LIBXML_HTML_ENABLED) || defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) /** * xmlValidateNCName: * @value: the value to check @@ -717,11 +717,8 @@ xmlGetBufferAllocationScheme(void) { * Creation of a new Namespace. This function will refuse to create * a namespace with a similar prefix than an existing one present on this * node. - * Note that for a default namespace, @prefix should be NULL. - * * We use href==NULL in the case of an element creation where the namespace * was not defined. - * * Returns a new namespace pointer or NULL */ xmlNsPtr @@ -806,9 +803,7 @@ xmlSetNs(xmlNodePtr node, xmlNsPtr ns) { #endif return; } - if ((node->type == XML_ELEMENT_NODE) || - (node->type == XML_ATTRIBUTE_NODE)) - node->ns = ns; + node->ns = ns; } /** @@ -916,7 +911,7 @@ xmlNewDtd(xmlDocPtr doc, const xmlChar *name, */ xmlDtdPtr -xmlGetIntSubset(const xmlDoc *doc) { +xmlGetIntSubset(xmlDocPtr doc) { xmlNodePtr cur; if (doc == NULL) @@ -1266,7 +1261,7 @@ xmlFreeDoc(xmlDocPtr cur) { * Returns a pointer to the first child */ xmlNodePtr -xmlStringLenGetNodeList(const xmlDoc *doc, const xmlChar *value, int len) { +xmlStringLenGetNodeList(xmlDocPtr doc, const xmlChar *value, int len) { xmlNodePtr ret = NULL, last = NULL; xmlNodePtr node; xmlChar *val; @@ -1474,7 +1469,7 @@ out: * Returns a pointer to the first child */ xmlNodePtr -xmlStringGetNodeList(const xmlDoc *doc, const xmlChar *value) { +xmlStringGetNodeList(xmlDocPtr doc, const xmlChar *value) { xmlNodePtr ret = NULL, last = NULL; xmlNodePtr node; xmlChar *val; @@ -1662,9 +1657,9 @@ out: * Returns a pointer to the string copy, the caller must free it with xmlFree(). */ xmlChar * -xmlNodeListGetString(xmlDocPtr doc, const xmlNode *list, int inLine) +xmlNodeListGetString(xmlDocPtr doc, xmlNodePtr list, int inLine) { - const xmlNode *node = list; + xmlNodePtr node = list; xmlChar *ret = NULL; xmlEntityPtr ent; int attr; @@ -1752,9 +1747,9 @@ xmlNodeListGetString(xmlDocPtr doc, const xmlNode *list, int inLine) * Returns a pointer to the string copy, the caller must free it with xmlFree(). */ xmlChar * -xmlNodeListGetRawString(const xmlDoc *doc, const xmlNode *list, int inLine) +xmlNodeListGetRawString(xmlDocPtr doc, xmlNodePtr list, int inLine) { - const xmlNode *node = list; + xmlNodePtr node = list; xmlChar *ret = NULL; xmlEntityPtr ent; @@ -2583,7 +2578,7 @@ xmlNewCharRef(xmlDocPtr doc, const xmlChar *name) { * Returns a pointer to the new node object. */ xmlNodePtr -xmlNewReference(const xmlDoc *doc, const xmlChar *name) { +xmlNewReference(xmlDocPtr doc, const xmlChar *name) { xmlNodePtr cur; xmlEntityPtr ent; @@ -2601,7 +2596,7 @@ xmlNewReference(const xmlDoc *doc, const xmlChar *name) { memset(cur, 0, sizeof(xmlNode)); cur->type = XML_ENTITY_REF_NODE; - cur->doc = (xmlDoc *)doc; + cur->doc = doc; if (name[0] == '&') { int len; name++; @@ -2639,11 +2634,11 @@ xmlNewReference(const xmlDoc *doc, const xmlChar *name) { * Returns a pointer to the new node object. */ xmlNodePtr -xmlNewDocText(const xmlDoc *doc, const xmlChar *content) { +xmlNewDocText(xmlDocPtr doc, const xmlChar *content) { xmlNodePtr cur; cur = xmlNewText(content); - if (cur != NULL) cur->doc = (xmlDoc *)doc; + if (cur != NULL) cur->doc = doc; return(cur); } @@ -3039,7 +3034,7 @@ xmlAddNextSibling(xmlNodePtr cur, xmlNodePtr elem) { } #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_HTML_ENABLED) || \ - defined(LIBXML_SCHEMAS_ENABLED) || defined(LIBXML_XINCLUDE_ENABLED) + defined(LIBXML_SCHEMAS_ENABLED) /** * xmlAddPrevSibling: * @cur: the child node @@ -3417,7 +3412,7 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { * Returns the last child or NULL if none. */ xmlNodePtr -xmlGetLastChild(const xmlNode *parent) { +xmlGetLastChild(xmlNodePtr parent) { if ((parent == NULL) || (parent->type == XML_NAMESPACE_DECL)) { #ifdef DEBUG_TREE xmlGenericError(xmlGenericErrorContext, @@ -3456,7 +3451,6 @@ xmlChildElementCount(xmlNodePtr parent) { case XML_ELEMENT_NODE: case XML_ENTITY_NODE: case XML_DOCUMENT_NODE: - case XML_DOCUMENT_FRAG_NODE: case XML_HTML_DOCUMENT_NODE: cur = parent->children; break; @@ -3492,7 +3486,6 @@ xmlFirstElementChild(xmlNodePtr parent) { case XML_ELEMENT_NODE: case XML_ENTITY_NODE: case XML_DOCUMENT_NODE: - case XML_DOCUMENT_FRAG_NODE: case XML_HTML_DOCUMENT_NODE: cur = parent->children; break; @@ -3528,7 +3521,6 @@ xmlLastElementChild(xmlNodePtr parent) { case XML_ELEMENT_NODE: case XML_ENTITY_NODE: case XML_DOCUMENT_NODE: - case XML_DOCUMENT_FRAG_NODE: case XML_HTML_DOCUMENT_NODE: cur = parent->last; break; @@ -4136,7 +4128,7 @@ xmlCopyPropList(xmlNodePtr target, xmlAttrPtr cur) { */ static xmlNodePtr -xmlStaticCopyNode(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, +xmlStaticCopyNode(const xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, int extended) { xmlNodePtr ret; @@ -4302,7 +4294,6 @@ xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent) { } if (doc->intSubset == NULL) { q = (xmlNodePtr) xmlCopyDtd( (xmlDtdPtr) node ); - if (q == NULL) return(NULL); q->doc = doc; q->parent = parent; doc->intSubset = (xmlDtdPtr) q; @@ -4314,7 +4305,6 @@ xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent) { } else #endif /* LIBXML_TREE_ENABLED */ q = xmlStaticCopyNode(node, doc, parent, 1); - if (q == NULL) return(NULL); if (ret == NULL) { q->prev = NULL; ret = p = q; @@ -4341,7 +4331,7 @@ xmlStaticCopyNodeList(xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent) { * Returns: a new #xmlNodePtr, or NULL in case of error. */ xmlNodePtr -xmlCopyNode(xmlNodePtr node, int extended) { +xmlCopyNode(const xmlNodePtr node, int extended) { xmlNodePtr ret; ret = xmlStaticCopyNode(node, NULL, NULL, extended); @@ -4361,7 +4351,7 @@ xmlCopyNode(xmlNodePtr node, int extended) { * Returns: a new #xmlNodePtr, or NULL in case of error. */ xmlNodePtr -xmlDocCopyNode(xmlNodePtr node, xmlDocPtr doc, int extended) { +xmlDocCopyNode(const xmlNodePtr node, xmlDocPtr doc, int extended) { xmlNodePtr ret; ret = xmlStaticCopyNode(node, doc, NULL, extended); @@ -4377,7 +4367,7 @@ xmlDocCopyNode(xmlNodePtr node, xmlDocPtr doc, int extended) { * * Returns: a new #xmlNodePtr, or NULL in case of error. */ -xmlNodePtr xmlDocCopyNodeList(xmlDocPtr doc, xmlNodePtr node) { +xmlNodePtr xmlDocCopyNodeList(xmlDocPtr doc, const xmlNodePtr node) { xmlNodePtr ret = xmlStaticCopyNodeList(node, doc, NULL); return(ret); } @@ -4391,7 +4381,7 @@ xmlNodePtr xmlDocCopyNodeList(xmlDocPtr doc, xmlNodePtr node) { * * Returns: a new #xmlNodePtr, or NULL in case of error. */ -xmlNodePtr xmlCopyNodeList(xmlNodePtr node) { +xmlNodePtr xmlCopyNodeList(const xmlNodePtr node) { xmlNodePtr ret = xmlStaticCopyNodeList(node, NULL, NULL); return(ret); } @@ -4517,10 +4507,6 @@ xmlCopyDoc(xmlDocPtr doc, int recursive) { #ifdef LIBXML_TREE_ENABLED if (doc->intSubset != NULL) { ret->intSubset = xmlCopyDtd(doc->intSubset); - if (ret->intSubset == NULL) { - xmlFreeDoc(ret); - return(NULL); - } xmlSetTreeDoc((xmlNodePtr)ret->intSubset, ret); ret->intSubset->parent = ret; } @@ -4561,7 +4547,7 @@ xmlCopyDoc(xmlDocPtr doc, int recursive) { * Returns the line number if successful, -1 otherwise */ static long -xmlGetLineNoInternal(const xmlNode *node, int depth) +xmlGetLineNoInternal(xmlNodePtr node, int depth) { long result = -1; @@ -4611,7 +4597,7 @@ xmlGetLineNoInternal(const xmlNode *node, int depth) * Returns the line number if successful, -1 otherwise */ long -xmlGetLineNo(const xmlNode *node) +xmlGetLineNo(xmlNodePtr node) { return(xmlGetLineNoInternal(node, 0)); } @@ -4627,9 +4613,9 @@ xmlGetLineNo(const xmlNode *node) * the returned string */ xmlChar * -xmlGetNodePath(const xmlNode *node) +xmlGetNodePath(xmlNodePtr node) { - const xmlNode *cur, *tmp, *next; + xmlNodePtr cur, tmp, next; xmlChar *buffer = NULL, *temp; size_t buf_len; xmlChar *buf; @@ -4873,7 +4859,7 @@ xmlGetNodePath(const xmlNode *node) * Returns the #xmlNodePtr for the root or NULL */ xmlNodePtr -xmlDocGetRootElement(const xmlDoc *doc) { +xmlDocGetRootElement(xmlDocPtr doc) { xmlNodePtr ret; if (doc == NULL) return(NULL); @@ -4987,7 +4973,7 @@ xmlNodeSetLang(xmlNodePtr cur, const xmlChar *lang) { * It's up to the caller to free the memory with xmlFree(). */ xmlChar * -xmlNodeGetLang(const xmlNode *cur) { +xmlNodeGetLang(xmlNodePtr cur) { xmlChar *lang; if ((cur == NULL) || (cur->type == XML_NAMESPACE_DECL)) @@ -5068,7 +5054,7 @@ xmlNodeSetSpacePreserve(xmlNodePtr cur, int val) { * Returns -1 if xml:space is not inherited, 0 if "default", 1 if "preserve" */ int -xmlNodeGetSpacePreserve(const xmlNode *cur) { +xmlNodeGetSpacePreserve(xmlNodePtr cur) { xmlChar *space; if ((cur == NULL) || (cur->type != XML_ELEMENT_NODE)) @@ -5103,7 +5089,6 @@ void xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) { xmlDocPtr doc; xmlDictPtr dict; - const xmlChar *freeme = NULL; if (cur == NULL) return; if (name == NULL) return; @@ -5141,16 +5126,12 @@ xmlNodeSetName(xmlNodePtr cur, const xmlChar *name) { dict = NULL; if (dict != NULL) { if ((cur->name != NULL) && (!xmlDictOwns(dict, cur->name))) - freeme = cur->name; + xmlFree((xmlChar *) cur->name); cur->name = xmlDictLookup(dict, name, -1); } else { - if (cur->name != NULL) - freeme = cur->name; + if (cur->name != NULL) xmlFree((xmlChar *) cur->name); cur->name = xmlStrdup(name); } - - if (freeme) - xmlFree((xmlChar *) freeme); } #endif @@ -5238,7 +5219,7 @@ xmlNodeSetBase(xmlNodePtr cur, const xmlChar* uri) { * It's up to the caller to free the memory with xmlFree(). */ xmlChar * -xmlNodeGetBase(const xmlDoc *doc, const xmlNode *cur) { +xmlNodeGetBase(xmlDocPtr doc, xmlNodePtr cur) { xmlChar *oldbase = NULL; xmlChar *base, *newbase; @@ -5323,7 +5304,7 @@ xmlNodeGetBase(const xmlDoc *doc, const xmlNode *cur) { * Returns 0 in case of success and -1 in case of error. */ int -xmlNodeBufGetContent(xmlBufferPtr buffer, const xmlNode *cur) +xmlNodeBufGetContent(xmlBufferPtr buffer, xmlNodePtr cur) { xmlBufPtr buf; int ret; @@ -5346,12 +5327,12 @@ xmlNodeBufGetContent(xmlBufferPtr buffer, const xmlNode *cur) * 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 @buf with this value + * Fills up the buffer @buffer with this value * * Returns 0 in case of success and -1 in case of error. */ int -xmlBufGetNodeContent(xmlBufPtr buf, const xmlNode *cur) +xmlBufGetNodeContent(xmlBufPtr buf, xmlNodePtr cur) { if ((cur == NULL) || (buf == NULL)) return(-1); switch (cur->type) { @@ -5361,7 +5342,7 @@ xmlBufGetNodeContent(xmlBufPtr buf, const xmlNode *cur) break; case XML_DOCUMENT_FRAG_NODE: case XML_ELEMENT_NODE:{ - const xmlNode *tmp = cur; + xmlNodePtr tmp = cur; while (tmp != NULL) { switch (tmp->type) { @@ -5492,7 +5473,7 @@ xmlBufGetNodeContent(xmlBufPtr buf, const xmlNode *cur) * It's up to the caller to free the memory with xmlFree(). */ xmlChar * -xmlNodeGetContent(const xmlNode *cur) +xmlNodeGetContent(xmlNodePtr cur) { if (cur == NULL) return (NULL); @@ -5872,7 +5853,7 @@ xmlTextMerge(xmlNodePtr first, xmlNodePtr second) { * namespace if defined */ xmlNsPtr * -xmlGetNsList(const xmlDoc *doc ATTRIBUTE_UNUSED, const xmlNode *node) +xmlGetNsList(xmlDocPtr doc ATTRIBUTE_UNUSED, xmlNodePtr node) { xmlNsPtr cur; xmlNsPtr *ret = NULL; @@ -5979,7 +5960,7 @@ xmlNsPtr xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace) { xmlNsPtr cur; - const xmlNode *orig = node; + xmlNodePtr orig = node; if ((node == NULL) || (node->type == XML_NAMESPACE_DECL)) return(NULL); if ((nameSpace != NULL) && @@ -6448,7 +6429,7 @@ xmlReconciliateNs(xmlDocPtr doc, xmlNodePtr tree) { #endif /* LIBXML_TREE_ENABLED */ static xmlAttrPtr -xmlGetPropNodeInternal(const xmlNode *node, const xmlChar *name, +xmlGetPropNodeInternal(xmlNodePtr node, const xmlChar *name, const xmlChar *nsName, int useDTD) { xmlAttrPtr prop; @@ -6562,7 +6543,7 @@ xmlGetPropNodeInternal(const xmlNode *node, const xmlChar *name, } static xmlChar* -xmlGetPropNodeValueInternal(const xmlAttr *prop) +xmlGetPropNodeValueInternal(xmlAttrPtr prop) { if (prop == NULL) return(NULL); @@ -6608,7 +6589,7 @@ xmlGetPropNodeValueInternal(const xmlAttr *prop) * neither was found. */ xmlAttrPtr -xmlHasProp(const xmlNode *node, const xmlChar *name) { +xmlHasProp(xmlNodePtr node, const xmlChar *name) { xmlAttrPtr prop; xmlDocPtr doc; @@ -6663,7 +6644,7 @@ xmlHasProp(const xmlNode *node, const xmlChar *name) { * if neither was found. */ xmlAttrPtr -xmlHasNsProp(const xmlNode *node, const xmlChar *name, const xmlChar *nameSpace) { +xmlHasNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) { return(xmlGetPropNodeInternal(node, name, nameSpace, xmlCheckDTD)); } @@ -6685,7 +6666,7 @@ xmlHasNsProp(const xmlNode *node, const xmlChar *name, const xmlChar *nameSpace) * It's up to the caller to free the memory with xmlFree(). */ xmlChar * -xmlGetProp(const xmlNode *node, const xmlChar *name) { +xmlGetProp(xmlNodePtr node, const xmlChar *name) { xmlAttrPtr prop; prop = xmlHasProp(node, name); @@ -6710,7 +6691,7 @@ xmlGetProp(const xmlNode *node, const xmlChar *name) { * It's up to the caller to free the memory with xmlFree(). */ xmlChar * -xmlGetNoNsProp(const xmlNode *node, const xmlChar *name) { +xmlGetNoNsProp(xmlNodePtr node, const xmlChar *name) { xmlAttrPtr prop; prop = xmlGetPropNodeInternal(node, name, NULL, xmlCheckDTD); @@ -6735,7 +6716,7 @@ xmlGetNoNsProp(const xmlNode *node, const xmlChar *name) { * It's up to the caller to free the memory with xmlFree(). */ xmlChar * -xmlGetNsProp(const xmlNode *node, const xmlChar *name, const xmlChar *nameSpace) { +xmlGetNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) { xmlAttrPtr prop; prop = xmlGetPropNodeInternal(node, name, nameSpace, xmlCheckDTD); @@ -6900,7 +6881,7 @@ xmlSetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name, * Returns 1 yes, 0 no */ int -xmlNodeIsText(const xmlNode *node) { +xmlNodeIsText(xmlNodePtr node) { if (node == NULL) return(0); if (node->type == XML_TEXT_NODE) return(1); @@ -6917,7 +6898,7 @@ xmlNodeIsText(const xmlNode *node) { * Returns 1 yes, 0 no */ int -xmlIsBlankNode(const xmlNode *node) { +xmlIsBlankNode(xmlNodePtr node) { const xmlChar *cur; if (node == NULL) return(0); @@ -7320,7 +7301,7 @@ xmlBufferDump(FILE *file, xmlBufferPtr buf) { */ const xmlChar * -xmlBufferContent(const xmlBuffer *buf) +xmlBufferContent(const xmlBufferPtr buf) { if(!buf) return NULL; @@ -7338,7 +7319,7 @@ xmlBufferContent(const xmlBuffer *buf) */ int -xmlBufferLength(const xmlBuffer *buf) +xmlBufferLength(const xmlBufferPtr buf) { if(!buf) return 0; @@ -7722,7 +7703,7 @@ xmlBufferWriteQuotedString(xmlBufferPtr buf, const xmlChar *string) { * Returns 0 (uncompressed) to 9 (max compression) */ int -xmlGetDocCompressMode (const xmlDoc *doc) { +xmlGetDocCompressMode (xmlDocPtr doc) { if (doc == NULL) return(-1); return(doc->compression); } @@ -7913,7 +7894,8 @@ xmlDOMWrapNsMapAddItem(xmlNsMapPtr *nsmap, int position, map->first->prev = ret; ret->next = map->first; map->first = ret; - } + } else + return(NULL); ret->oldNs = oldNs; ret->newNs = newNs; @@ -7973,7 +7955,7 @@ xmlDOMWrapStoreNs(xmlDocPtr doc, * * Allocates and initializes a new DOM-wrapper context. * -* Returns the xmlDOMWrapCtxtPtr or NULL in case of an internal error. +* Returns the xmlDOMWrapCtxtPtr or NULL in case of an internal errror. */ xmlDOMWrapCtxtPtr xmlDOMWrapNewCtxt(void) @@ -9798,8 +9780,7 @@ leave_node: if (clone->parent != NULL) clone->parent->last = clone; clone = clone->parent; - if (clone != NULL) - parentClone = clone->parent; + parentClone = clone->parent; /* * Process parent --> next; */ @@ -9981,7 +9962,7 @@ internal_error: * References of out-of scope ns-decls are remapped to point to @destDoc: * 1) If @destParent is given, then nsDef entries on element-nodes are used * 2) If *no* @destParent is given, then @destDoc->oldNs entries are used -* This is the case when you have an unlinked node and just want to move it +* This is the case when you have an unliked node and just want to move it * to the context of * * If @destParent is given, it ensures that the tree is namespace |