diff --git a/ChangeLog b/ChangeLog index 7a5516bd..07259221 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri May 11 19:37:30 CEST 2001 Daniel Veillard + + * tree.[ch]: fixing bug #54446, by cleaning some bugs in the + attributes handling and #54433 by adding xmlUnsetProp() + and xmlUnsetNsProp() + Fri May 11 16:07:13 CEST 2001 Daniel Veillard * HTMLparser.c: Patch from Jonas Borgström diff --git a/include/libxml/tree.h b/include/libxml/tree.h index 604f8811..841fef1b 100644 --- a/include/libxml/tree.h +++ b/include/libxml/tree.h @@ -584,6 +584,8 @@ xmlAttrPtr xmlSetProp (xmlNodePtr node, const xmlChar *value); xmlChar * xmlGetProp (xmlNodePtr node, const xmlChar *name); +int xmlUnsetProp (xmlNodePtr node, + const xmlChar *name); xmlAttrPtr xmlHasProp (xmlNodePtr node, const xmlChar *name); xmlAttrPtr xmlSetNsProp (xmlNodePtr node, @@ -593,6 +595,9 @@ xmlAttrPtr xmlSetNsProp (xmlNodePtr node, xmlChar * xmlGetNsProp (xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace); +int xmlUnsetNsProp (xmlNodePtr node, + xmlNsPtr ns, + const xmlChar *name); xmlNodePtr xmlStringGetNodeList (xmlDocPtr doc, const xmlChar *value); xmlNodePtr xmlStringLenGetNodeList (xmlDocPtr doc, diff --git a/tree.c b/tree.c index 3f6bcbf1..16d64869 100644 --- a/tree.c +++ b/tree.c @@ -770,7 +770,7 @@ xmlStringGetNodeList(xmlDocPtr doc, const xmlChar *value) { } else cur++; } - if (cur != q) { + if ((cur != q) || (ret == NULL)) { /* * Handle the last piece of text. */ @@ -4342,7 +4342,8 @@ xmlSetProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { return(NULL); doc = node->doc; while (prop != NULL) { - if (xmlStrEqual(prop->name, name)) { + if ((xmlStrEqual(prop->name, name)) && + (prop->ns == NULL)){ if (prop->children != NULL) xmlFreeNodeList(prop->children); prop->children = NULL; @@ -4364,7 +4365,7 @@ xmlSetProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { tmp = tmp->next; } xmlFree(buffer); - } + } return(prop); } prop = prop->next; @@ -4373,6 +4374,36 @@ xmlSetProp(xmlNodePtr node, const xmlChar *name, const xmlChar *value) { return(prop); } +/** + * xmlUnsetProp: + * @node: the node + * @name: the attribute name + * + * Remove an attribute carried by a node. + * Returns 0 if successful, -1 if not found + */ +int +xmlUnsetProp(xmlNodePtr node, const xmlChar *name) { + xmlAttrPtr prop = node->properties, prev = NULL;; + + if ((node == NULL) || (name == NULL)) + return(-1); + while (prop != NULL) { + if ((xmlStrEqual(prop->name, name)) && + (prop->ns == NULL)) { + if (prev == NULL) + node->properties = prop->next; + else + prev->next = prop->next; + xmlFreeProp(prop); + return(0); + } + prev = prop; + prop = prop->next; + } + return(-1); +} + /** * xmlSetNsProp: * @node: the node @@ -4440,6 +4471,43 @@ xmlSetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name, return(prop); } +/** + * xmlUnsetNsProp: + * @node: the node + * @ns: the namespace definition + * @name: the attribute name + * + * Remove an attribute carried by a node. + * Returns 0 if successful, -1 if not found + */ +int +xmlUnsetNsProp(xmlNodePtr node, xmlNsPtr ns, const xmlChar *name) { + xmlAttrPtr prop = node->properties, prev = NULL;; + + if ((node == NULL) || (name == NULL)) + return(-1); + if (ns == NULL) + return(xmlUnsetProp(node, name)); + if (ns->href == NULL) + return(-1); + while (prop != NULL) { + if ((xmlStrEqual(prop->name, name)) && + (((prop->ns == NULL) && (node->ns != NULL) && + (xmlStrEqual(node->ns->href, ns->href))) || + ((prop->ns != NULL) && (xmlStrEqual(prop->ns->href, ns->href))))) { + if (prev == NULL) + node->properties = prop->next; + else + prev->next = prop->next; + xmlFreeProp(prop); + return(0); + } + prev = prop; + prop = prop->next; + } + return(-1); +} + /** * xmlNodeIsText: * @node: the node diff --git a/tree.h b/tree.h index 604f8811..841fef1b 100644 --- a/tree.h +++ b/tree.h @@ -584,6 +584,8 @@ xmlAttrPtr xmlSetProp (xmlNodePtr node, const xmlChar *value); xmlChar * xmlGetProp (xmlNodePtr node, const xmlChar *name); +int xmlUnsetProp (xmlNodePtr node, + const xmlChar *name); xmlAttrPtr xmlHasProp (xmlNodePtr node, const xmlChar *name); xmlAttrPtr xmlSetNsProp (xmlNodePtr node, @@ -593,6 +595,9 @@ xmlAttrPtr xmlSetNsProp (xmlNodePtr node, xmlChar * xmlGetNsProp (xmlNodePtr node, const xmlChar *name, const xmlChar *nameSpace); +int xmlUnsetNsProp (xmlNodePtr node, + xmlNsPtr ns, + const xmlChar *name); xmlNodePtr xmlStringGetNodeList (xmlDocPtr doc, const xmlChar *value); xmlNodePtr xmlStringLenGetNodeList (xmlDocPtr doc,