diff options
author | Mike Hommey <glandium@debian.org> | 2005-09-05 17:10:35 +0000 |
---|---|---|
committer | Mike Hommey <glandium@debian.org> | 2005-09-05 17:10:35 +0000 |
commit | a464d9993e2acd5b8e1089b218ba74c6fcf215c5 (patch) | |
tree | 72fe00eb59147367a1d660b90d08172357e0dffc /tree.c | |
parent | 112cb5bb5475afec1c1cbf1d6728ce4880d0fee8 (diff) | |
download | libxml2-a464d9993e2acd5b8e1089b218ba74c6fcf215c5.tar.gz |
Load /usr/tmp/tmp.CMoFff/libxml2-2.6.21 intoupstream/2.6.21
packages/libxml2/branches/upstream/current.
Diffstat (limited to 'tree.c')
-rw-r--r-- | tree.c | 210 |
1 files changed, 140 insertions, 70 deletions
@@ -297,6 +297,7 @@ xmlSplitQName2(const xmlChar *name, xmlChar **prefix) { * * returns NULL if it is not a Qualified Name, otherwise, update len * with the lenght in byte of the prefix and return a pointer + * to the start of the name without the prefix */ const xmlChar * @@ -1133,8 +1134,10 @@ xmlFreeDoc(xmlDocPtr cur) { return; } #ifdef LIBXML_DEBUG_RUNTIME +#ifdef LIBXML_DEBUG_ENABLED xmlDebugCheckDocument(stderr, cur); #endif +#endif if (cur != NULL) dict = cur->dict; @@ -1721,80 +1724,87 @@ xmlNodeListGetRawString(xmlDocPtr doc, xmlNodePtr list, int inLine) } #endif /* LIBXML_TREE_ENABLED */ -static xmlAttrPtr xmlNewPropInternal(xmlNodePtr node, xmlNsPtr ns, - const xmlChar *name, const xmlChar *value, int eatname) { +static xmlAttrPtr +xmlNewPropInternal(xmlNodePtr node, xmlNsPtr ns, + const xmlChar * name, const xmlChar * value, + int eatname) +{ xmlAttrPtr cur; xmlDocPtr doc = NULL; if ((node != NULL) && (node->type != XML_ELEMENT_NODE)) { - if (eatname == 1) - xmlFree((xmlChar *) name); - return(NULL); - } + if (eatname == 1) + xmlFree((xmlChar *) name); + return (NULL); + } /* * Allocate a new property and fill the fields. */ cur = (xmlAttrPtr) xmlMalloc(sizeof(xmlAttr)); if (cur == NULL) { - if (eatname == 1) - xmlFree((xmlChar *) name); - xmlTreeErrMemory("building attribute"); - return(NULL); + if (eatname == 1) + xmlFree((xmlChar *) name); + xmlTreeErrMemory("building attribute"); + return (NULL); } memset(cur, 0, sizeof(xmlAttr)); cur->type = XML_ATTRIBUTE_NODE; - cur->parent = node; + cur->parent = node; if (node != NULL) { - doc = node->doc; - cur->doc = doc; + doc = node->doc; + cur->doc = doc; } - cur->ns = ns; + cur->ns = ns; - if (eatname == 0) { - if ((doc != NULL) && (doc->dict != NULL)) - cur->name = (xmlChar *) xmlDictLookup(doc->dict, name, -1); - else - cur->name = xmlStrdup(name); - } else - cur->name = name; + if (eatname == 0) { + if ((doc != NULL) && (doc->dict != NULL)) + cur->name = (xmlChar *) xmlDictLookup(doc->dict, name, -1); + else + cur->name = xmlStrdup(name); + } else + cur->name = name; if (value != NULL) { - xmlChar *buffer; - xmlNodePtr tmp; - - buffer = xmlEncodeEntitiesReentrant(doc, value); - cur->children = xmlStringGetNodeList(doc, buffer); - cur->last = NULL; - tmp = cur->children; - while (tmp != NULL) { - tmp->parent = (xmlNodePtr) cur; - if (tmp->next == NULL) - cur->last = tmp; - tmp = tmp->next; - } - xmlFree(buffer); - } + xmlChar *buffer; + xmlNodePtr tmp; + + buffer = xmlEncodeEntitiesReentrant(doc, value); + cur->children = xmlStringGetNodeList(doc, buffer); + cur->last = NULL; + tmp = cur->children; + while (tmp != NULL) { + tmp->parent = (xmlNodePtr) cur; + if (tmp->next == NULL) + cur->last = tmp; + tmp = tmp->next; + } + xmlFree(buffer); + } /* * Add it at the end to preserve parsing order ... */ if (node != NULL) { - if (node->properties == NULL) { - node->properties = cur; - } else { - xmlAttrPtr prev = node->properties; + if (node->properties == NULL) { + node->properties = cur; + } else { + xmlAttrPtr prev = node->properties; - while (prev->next != NULL) prev = prev->next; - prev->next = cur; - cur->prev = prev; - } + while (prev->next != NULL) + prev = prev->next; + prev->next = cur; + cur->prev = prev; + } } + if (xmlIsID((node == NULL) ? NULL : node->doc, node, cur) == 1) + xmlAddID(NULL, node->doc, value, cur); + if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) - xmlRegisterNodeDefaultValue((xmlNodePtr)cur); - return(cur); + xmlRegisterNodeDefaultValue((xmlNodePtr) cur); + return (cur); } #if defined(LIBXML_TREE_ENABLED) || defined(LIBXML_HTML_ENABLED) || \ @@ -3285,7 +3295,8 @@ xmlFreeNodeList(xmlNodePtr cur) { if ((cur->type != XML_ELEMENT_NODE) && (cur->type != XML_XINCLUDE_START) && (cur->type != XML_XINCLUDE_END) && - (cur->type != XML_ENTITY_REF_NODE)) { + (cur->type != XML_ENTITY_REF_NODE) && + (cur->content != (xmlChar *) &(cur->properties))) { DICT_FREE(cur->content) } if (((cur->type == XML_ELEMENT_NODE) || @@ -3354,7 +3365,8 @@ xmlFreeNode(xmlNodePtr cur) { (cur->content != NULL) && (cur->type != XML_ENTITY_REF_NODE) && (cur->type != XML_XINCLUDE_END) && - (cur->type != XML_XINCLUDE_START)) { + (cur->type != XML_XINCLUDE_START) && + (cur->content != (xmlChar *) &(cur->properties))) { DICT_FREE(cur->content) } @@ -3809,7 +3821,7 @@ xmlStaticCopyNode(const xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, if (!extended) goto out; - if (node->nsDef != NULL) + if ((node->type == XML_ELEMENT_NODE) && (node->nsDef != NULL)) ret->nsDef = xmlCopyNamespaceList(node->nsDef); if (node->ns != NULL) { @@ -3836,7 +3848,7 @@ xmlStaticCopyNode(const xmlNodePtr node, xmlDocPtr doc, xmlNodePtr parent, ret->ns = ns; } } - if (node->properties != NULL) + if ((node->type == XML_ELEMENT_NODE) && (node->properties != NULL)) ret->properties = xmlCopyPropList(ret, node->properties); if (node->type == XML_ENTITY_REF_NODE) { if ((doc == NULL) || (node->doc != doc)) { @@ -4136,15 +4148,19 @@ xmlGetLineNo(xmlNodePtr node) if (!node) return result; - if (node->type == XML_ELEMENT_NODE) + if ((node->type == XML_ELEMENT_NODE) || + (node->type == XML_TEXT_NODE) || + (node->type == XML_COMMENT_NODE) || + (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_TEXT_NODE) || + (node->prev->type == XML_COMMENT_NODE) || + (node->prev->type == XML_PI_NODE))) result = xmlGetLineNo(node->prev); else if ((node->parent != NULL) && - ((node->parent->type == XML_ELEMENT_NODE) || - (node->parent->type == XML_TEXT_NODE))) + (node->parent->type == XML_ELEMENT_NODE)) result = xmlGetLineNo(node->parent); return result; @@ -4332,6 +4348,16 @@ xmlGetNodePath(xmlNodePtr node) } else if (cur->type == XML_ATTRIBUTE_NODE) { sep = "/@"; name = (const char *) (((xmlAttrPtr) cur)->name); + if (cur->ns) { + if (cur->ns->prefix != NULL) + snprintf(nametemp, sizeof(nametemp) - 1, "%s:%s", + (char *)cur->ns->prefix, (char *)cur->name); + else + snprintf(nametemp, sizeof(nametemp) - 1, "%s", + (char *)cur->name); + nametemp[sizeof(nametemp) - 1] = 0; + name = nametemp; + } next = ((xmlAttrPtr) cur)->parent; } else { next = cur->parent; @@ -5090,7 +5116,8 @@ xmlNodeSetContent(xmlNodePtr cur, const xmlChar *content) { case XML_ENTITY_NODE: case XML_PI_NODE: case XML_COMMENT_NODE: - if (cur->content != NULL) { + if ((cur->content != NULL) && + (cur->content != (xmlChar *) &(cur->properties))) { if (!((cur->doc != NULL) && (cur->doc->dict != NULL) && (xmlDictOwns(cur->doc->dict, cur->content)))) xmlFree(cur->content); @@ -5101,6 +5128,8 @@ xmlNodeSetContent(xmlNodePtr cur, const xmlChar *content) { cur->content = xmlStrdup(content); } else cur->content = NULL; + cur->properties = NULL; + cur->nsDef = NULL; break; case XML_DOCUMENT_NODE: case XML_HTML_DOCUMENT_NODE: @@ -5162,8 +5191,11 @@ xmlNodeSetContentLen(xmlNodePtr cur, const xmlChar *content, int len) { case XML_PI_NODE: case XML_COMMENT_NODE: case XML_NOTATION_NODE: - if (cur->content != NULL) { - xmlFree(cur->content); + if ((cur->content != NULL) && + (cur->content != (xmlChar *) &(cur->properties))) { + if (!((cur->doc != NULL) && (cur->doc->dict != NULL) && + (xmlDictOwns(cur->doc->dict, cur->content)))) + xmlFree(cur->content); } if (cur->children != NULL) xmlFreeNodeList(cur->children); cur->children = cur->last = NULL; @@ -5171,6 +5203,8 @@ xmlNodeSetContentLen(xmlNodePtr cur, const xmlChar *content, int len) { cur->content = xmlStrndup(content, len); } else cur->content = NULL; + cur->properties = NULL; + cur->nsDef = NULL; break; case XML_DOCUMENT_NODE: case XML_DTD_NODE: @@ -5241,10 +5275,12 @@ xmlNodeAddContentLen(xmlNodePtr cur, const xmlChar *content, int len) { case XML_COMMENT_NODE: case XML_NOTATION_NODE: if (content != NULL) { - if ((cur->doc != NULL) && (cur->doc->dict != NULL) && - xmlDictOwns(cur->doc->dict, cur->content)) { - cur->content = - xmlStrncatNew(cur->content, content, len); + if ((cur->content == (xmlChar *) &(cur->properties)) || + ((cur->doc != NULL) && (cur->doc->dict != NULL) && + xmlDictOwns(cur->doc->dict, cur->content))) { + cur->content = xmlStrncatNew(cur->content, content, len); + cur->properties = NULL; + cur->nsDef = NULL; break; } cur->content = xmlStrncat(cur->content, content, len); @@ -5887,7 +5923,8 @@ xmlHasProp(xmlNodePtr node, const xmlChar *name) { xmlAttrPtr prop; xmlDocPtr doc; - if ((node == NULL) || (name == NULL)) return(NULL); + if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) + return(NULL); /* * Check on the properties attached to the node */ @@ -5943,7 +5980,7 @@ xmlHasNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) { xmlDocPtr doc; #endif /* LIBXML_TREE_ENABLED */ - if (node == NULL) + if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) return(NULL); prop = node->properties; @@ -6041,7 +6078,9 @@ xmlGetProp(xmlNodePtr node, const xmlChar *name) { xmlAttrPtr prop; xmlDocPtr doc; - if ((node == NULL) || (name == NULL)) return(NULL); + if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) + return(NULL); + /* * Check on the properties attached to the node */ @@ -6098,7 +6137,8 @@ xmlGetNoNsProp(xmlNodePtr node, const xmlChar *name) { xmlAttrPtr prop; xmlDocPtr doc; - if ((node == NULL) || (name == NULL)) return(NULL); + if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) + return(NULL); /* * Check on the properties attached to the node */ @@ -6156,7 +6196,7 @@ xmlGetNsProp(xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace) { xmlDocPtr doc; xmlNsPtr ns; - if (node == NULL) + if ((node == NULL) || (node->type != XML_ELEMENT_NODE)) return(NULL); prop = node->properties; @@ -6220,7 +6260,7 @@ int xmlUnsetProp(xmlNodePtr node, const xmlChar *name) { xmlAttrPtr prop, prev = NULL;; - if ((node == NULL) || (name == NULL)) + if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) return(-1); prop = node->properties; while (prop != NULL) { @@ -6249,7 +6289,7 @@ int xmlUnsetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name) { xmlAttrPtr prop, prev = NULL;; - if ((node == NULL) || (name == NULL)) + if ((node == NULL) || (node->type != XML_ELEMENT_NODE) || (name == NULL)) return(-1); prop = node->properties; if (ns == NULL) @@ -6284,16 +6324,36 @@ xmlAttrPtr xmlSetProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { xmlAttrPtr prop; xmlDocPtr doc; + int len; + const xmlChar *nqname; if ((node == NULL) || (name == NULL) || (node->type != XML_ELEMENT_NODE)) return(NULL); + + /* + * handle QNames + */ + nqname = xmlSplitQName3(name, &len); + if (nqname != NULL) { + xmlNsPtr ns; + xmlChar *prefix = xmlStrndup(name, len); + ns = xmlSearchNs(node->doc, node, prefix); + if (prefix != NULL) + xmlFree(prefix); + if (ns != NULL) + return(xmlSetNsProp(node, ns, nqname, value)); + } + doc = node->doc; prop = node->properties; while (prop != NULL) { if ((xmlStrEqual(prop->name, name)) && (prop->ns == NULL)){ xmlNodePtr oldprop = prop->children; + int id = xmlIsID(node->doc, node, prop); + if (id == 1) + xmlRemoveID(node->doc, prop); prop->children = NULL; prop->last = NULL; if (value != NULL) { @@ -6316,6 +6376,8 @@ xmlSetProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { } if (oldprop != NULL) xmlFreeNodeList(oldprop); + if (id) + xmlAddID(NULL, node->doc, value, prop); return(prop); } prop = prop->next; @@ -6358,6 +6420,10 @@ xmlSetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name, */ if ((xmlStrEqual(prop->name, name)) && (prop->ns != NULL) && (xmlStrEqual(prop->ns->href, ns->href))) { + int id = xmlIsID(node->doc, node, prop); + + if (id == 1) + xmlRemoveID(node->doc, prop); if (prop->children != NULL) xmlFreeNodeList(prop->children); prop->children = NULL; @@ -6379,6 +6445,8 @@ xmlSetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name, } xmlFree(buffer); } + if (id) + xmlAddID(NULL, node->doc, value, prop); return(prop); } prop = prop->next; @@ -6455,12 +6523,14 @@ xmlTextConcat(xmlNodePtr node, const xmlChar *content, int len) { return(-1); } /* need to check if content is currently in the dictionary */ - if ((node->doc != NULL) && (node->doc->dict != NULL) && - xmlDictOwns(node->doc->dict, node->content)) { + if ((node->content == (xmlChar *) &(node->properties)) || + ((node->doc != NULL) && (node->doc->dict != NULL) && + xmlDictOwns(node->doc->dict, node->content))) { node->content = xmlStrncatNew(node->content, content, len); } else { node->content = xmlStrncat(node->content, content, len); } + node->properties = NULL; if (node->content == NULL) return(-1); return(0); |