mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-30 22:43:14 +03:00
- tree.[ch]: fixing bug #54446, by cleaning some bugs in the
attributes handling and #54433 by adding xmlUnsetProp() and xmlUnsetNsProp() Daniel
This commit is contained in:
74
tree.c
74
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
|
||||
|
Reference in New Issue
Block a user