diff --git a/ChangeLog b/ChangeLog index 727b7ee5..412a6d85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Jan 22 22:38:42 CET 2002 Daniel Veillard + + * tree.c: apply an patch from Petr Kozelka for unlink and replace + support of attribute nodes + Tue Jan 22 19:12:06 CET 2002 Daniel Veillard * doc/libxml2-api.xml doc/parsedecl.py: Build a new version diff --git a/tree.c b/tree.c index 66e8acd8..241bd08a 100644 --- a/tree.c +++ b/tree.c @@ -2506,16 +2506,25 @@ xmlUnlinkNode(xmlNodePtr cur) { if (doc->extSubset == (xmlDtdPtr) cur) doc->extSubset = NULL; } - if ((cur->parent != NULL) && (cur->parent->children == cur)) - cur->parent->children = cur->next; - if ((cur->parent != NULL) && (cur->parent->last == cur)) - cur->parent->last = cur->prev; + if (cur->parent != NULL) { + xmlNodePtr parent; + parent = cur->parent; + if (cur->type == XML_ATTRIBUTE_NODE) { + if (parent->properties == (xmlAttrPtr) cur) + parent->properties = ((xmlAttrPtr) cur)->next; + } else { + if (parent->children == cur) + parent->children = cur->next; + if (parent->last == cur) + parent->last = cur->prev; + } + cur->parent = NULL; + } if (cur->next != NULL) cur->next->prev = cur->prev; if (cur->prev != NULL) cur->prev->next = cur->next; cur->next = cur->prev = NULL; - cur->parent = NULL; } /** @@ -2545,6 +2554,20 @@ xmlReplaceNode(xmlNodePtr old, xmlNodePtr cur) { if (cur == old) { return(old); } + if ((old->type==XML_ATTRIBUTE_NODE) && (cur->type!=XML_ATTRIBUTE_NODE)) { +#ifdef DEBUG_TREE + xmlGenericError(xmlGenericErrorContext, + "xmlReplaceNode : Trying to replace attribute node with other node type\n"); +#endif + return(old); + } + if ((cur->type==XML_ATTRIBUTE_NODE) && (old->type!=XML_ATTRIBUTE_NODE)) { +#ifdef DEBUG_TREE + xmlGenericError(xmlGenericErrorContext, + "xmlReplaceNode : Trying to replace a non-attribute node with attribute node\n"); +#endif + return(old); + } xmlUnlinkNode(cur); cur->doc = old->doc; cur->parent = old->parent; @@ -2555,10 +2578,15 @@ xmlReplaceNode(xmlNodePtr old, xmlNodePtr cur) { if (cur->prev != NULL) cur->prev->next = cur; if (cur->parent != NULL) { - if (cur->parent->children == old) - cur->parent->children = cur; - if (cur->parent->last == old) - cur->parent->last = cur; + if (cur->type == XML_ATTRIBUTE_NODE) { + if (cur->parent->properties == (xmlAttrPtr)old) + cur->parent->properties = ((xmlAttrPtr) cur); + } else { + if (cur->parent->children == old) + cur->parent->children = cur; + if (cur->parent->last == old) + cur->parent->last = cur; + } } old->next = old->prev = NULL; old->parent = NULL;