From 810a78b30562b8b582e9f4bc543e90892e79d26c Mon Sep 17 00:00:00 2001 From: Rob Richards Date: Wed, 31 Dec 2008 22:13:57 +0000 Subject: [PATCH] set doc on last child tree in xmlAddChildList for bug #546772. Fix problem * tree.c: set doc on last child tree in xmlAddChildList for bug #546772. Fix problem adding an attribute via with xmlAddChild reported by Kris Breuker. svn path=/trunk/; revision=3806 --- ChangeLog | 6 ++++++ tree.c | 16 +++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ba17028..971a65b4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Dec 31 23:11:37 CET 2008 Rob Richards + + * tree.c: set doc on last child tree in xmlAddChildList for + bug #546772. Fix problem adding an attribute via with xmlAddChild + reported by Kris Breuker. + Sun Dec 27 14:16:13 CET 2008 Rob Richards * xmlwriter.c: fix indenting in xmlTextWriterFullEndElement for diff --git a/tree.c b/tree.c index fe89dc48..8e393dad 100644 --- a/tree.c +++ b/tree.c @@ -3216,7 +3216,10 @@ xmlAddChildList(xmlNodePtr parent, xmlNodePtr cur) { cur = cur->next; } cur->parent = parent; - cur->doc = parent->doc; /* the parent may not be linked to a doc ! */ + /* the parent may not be linked to a doc ! */ + if (cur->doc != parent->doc) { + xmlSetTreeDoc(cur, parent->doc); + } parent->last = cur; return(cur); @@ -3309,9 +3312,7 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { if (cur->type == XML_ATTRIBUTE_NODE) { if (parent->type != XML_ELEMENT_NODE) return(NULL); - if (parent->properties == NULL) { - parent->properties = (xmlAttrPtr) cur; - } else { + if (parent->properties != NULL) { /* check if an attribute with the same name exists */ xmlAttrPtr lastattr; @@ -3326,8 +3327,13 @@ xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) { } if (lastattr == (xmlAttrPtr) cur) return(cur); + + } + if (parent->properties == NULL) { + parent->properties = (xmlAttrPtr) cur; + } else { /* find the end */ - lastattr = parent->properties; + xmlAttrPtr lastattr = parent->properties; while (lastattr->next != NULL) { lastattr = lastattr->next; }