Commit 75bea548 authored by Daniel Veillard's avatar Daniel Veillard
Browse files

- tree.[ch]: fixing bug #54446, by cleaning some bugs in the

  attributes handling and #54433 by adding xmlUnsetProp()
  and xmlUnsetNsProp()
Daniel
parent 0a2a163d
Fri May 11 19:37:30 CEST 2001 Daniel Veillard <Daniel.Veillard@imag.fr>
* 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 <Daniel.Veillard@imag.fr>
* HTMLparser.c: Patch from Jonas Borgstrm
......
......@@ -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,
......
......@@ -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
......
......@@ -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,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment