Index: tree.c =================================================================== RCS file: /cvs/gnome/gnome-xml/tree.c,v retrieving revision 1.364 diff -c -r1.364 tree.c *** tree.c 15 Feb 2006 10:57:50 -0000 1.364 --- tree.c 19 Feb 2006 11:51:12 -0000 *************** *** 1799,1805 **** } } ! if (xmlIsID((node == NULL) ? NULL : node->doc, node, cur) == 1) xmlAddID(NULL, node->doc, value, cur); if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) --- 1799,1805 ---- } } ! if (node && (xmlIsID(node->doc, node, cur) == 1)) xmlAddID(NULL, node->doc, value, cur); if ((__xmlRegisterCallbacks) && (xmlRegisterNodeDefaultValue)) *************** *** 2864,2870 **** /* check if an attribute with the same name exists */ xmlAttrPtr attr; ! if (cur->type != XML_ATTRIBUTE_NODE) return(NULL); if (elem->ns == NULL) attr = xmlHasNsProp(cur->parent, elem->name, NULL); --- 2864,2870 ---- /* check if an attribute with the same name exists */ xmlAttrPtr attr; ! if (cur->type != XML_ATTRIBUTE_NODE || cur->parent == NULL) return(NULL); if (elem->ns == NULL) attr = xmlHasNsProp(cur->parent, elem->name, NULL); *************** *** 2887,2893 **** cur->next = elem; if (elem->next != NULL) elem->next->prev = elem; ! if ((elem->parent != NULL) && (elem->parent->last == cur) && (elem->type != XML_ATTRIBUTE_NODE)) elem->parent->last = elem; return(elem); } --- 2887,2908 ---- cur->next = elem; if (elem->next != NULL) elem->next->prev = elem; ! if (elem->type == XML_ATTRIBUTE_NODE) { ! /* FIX ME - only if cur is removed ! if (elem->parent->properties == (xmlAttrPtr) cur) { ! elem->parent->properties = (xmlAttrPtr) elem; ! } ! */ ! if (xmlIsID(elem->doc, elem->parent, (xmlAttrPtr) elem)) { ! xmlChar *id; ! ! id = xmlNodeListGetString(elem->doc, elem->children, 1); ! if (id != NULL) { ! xmlAddID(NULL, elem->doc, id, (xmlAttrPtr) elem); ! xmlFree(id); ! } ! } ! } else if ((elem->parent != NULL) && (elem->parent->last == cur)) elem->parent->last = elem; return(elem); } *************** *** 2956,2962 **** /* check if an attribute with the same name exists */ xmlAttrPtr attr; ! if (cur->type != XML_ATTRIBUTE_NODE) return(NULL); if (elem->ns == NULL) attr = xmlHasNsProp(cur->parent, elem->name, NULL); --- 2971,2977 ---- /* check if an attribute with the same name exists */ xmlAttrPtr attr; ! if (cur->type != XML_ATTRIBUTE_NODE || cur->parent == NULL) return(NULL); if (elem->ns == NULL) attr = xmlHasNsProp(cur->parent, elem->name, NULL); *************** *** 2964,2982 **** attr = xmlHasNsProp(cur->parent, elem->name, elem->ns->href); /* elem has already been unlinked so can never be attr */ if ((attr != NULL) && (attr->type != XML_ATTRIBUTE_DECL)) { /* different instance, destroy it (attributes must be unique) */ xmlUnlinkNode((xmlNodePtr) attr); xmlFreeProp(attr); } } ! if (elem->doc != cur->doc) { ! xmlSetTreeDoc(elem, cur->doc); ! } ! elem->parent = cur->parent; elem->next = cur; - elem->prev = cur->prev; - cur->prev = elem; if (elem->prev != NULL) elem->prev->next = elem; if (elem->parent != NULL) { --- 2979,3012 ---- attr = xmlHasNsProp(cur->parent, elem->name, elem->ns->href); /* elem has already been unlinked so can never be attr */ if ((attr != NULL) && (attr->type != XML_ATTRIBUTE_DECL)) { + if (cur == (xmlNodePtr) attr) { + if (cur->prev == NULL) { + if (cur->next == NULL) { + if (elem->doc != cur->doc) { + xmlSetTreeDoc(elem, cur->doc); + } + elem->prev = NULL; + elem->parent = cur->parent; + cur = NULL; + } else + cur = cur->next; + } + } /* different instance, destroy it (attributes must be unique) */ xmlUnlinkNode((xmlNodePtr) attr); xmlFreeProp(attr); } } ! if (cur != NULL) { ! if (elem->doc != cur->doc) { ! xmlSetTreeDoc(elem, cur->doc); ! } ! elem->parent = cur->parent; ! elem->prev = cur->prev; ! cur->prev = elem; ! } elem->next = cur; if (elem->prev != NULL) elem->prev->next = elem; if (elem->parent != NULL) { *************** *** 2984,2989 **** --- 3014,3028 ---- if (elem->parent->properties == (xmlAttrPtr) cur) { elem->parent->properties = (xmlAttrPtr) elem; } + if (xmlIsID(elem->doc, elem->parent, (xmlAttrPtr) elem)) { + xmlChar *id; + + id = xmlNodeListGetString(elem->doc, elem->children, 1); + if (id != NULL) { + xmlAddID(NULL, elem->doc, id, (xmlAttrPtr) elem); + xmlFree(id); + } + } } else { if (elem->parent->children == cur) { elem->parent->children = elem; *************** *** 3030,3036 **** * Constant time is we can rely on the ->parent->last to find * the last sibling. */ ! if ((cur->parent != NULL) && (cur->parent->children != NULL) && (cur->parent->last != NULL) && (cur->parent->last->next == NULL)) { --- 3069,3075 ---- * Constant time is we can rely on the ->parent->last to find * the last sibling. */ ! if ((cur->type != XML_ATTRIBUTE_NODE) && (cur->parent != NULL) && (cur->parent->children != NULL) && (cur->parent->last != NULL) && (cur->parent->last->next == NULL)) { *************** *** 3046,3051 **** --- 3085,3106 ---- xmlNodeAddContent(cur, elem->content); xmlFreeNode(elem); return(cur); + } else if (elem->type == XML_ATTRIBUTE_NODE) { + /* check if an attribute with the same name exists */ + xmlAttrPtr attr; + + if (cur->type != XML_ATTRIBUTE_NODE || cur->parent == NULL) + return(NULL); + if (elem->ns == NULL) + attr = xmlHasNsProp(cur->parent, elem->name, NULL); + else + attr = xmlHasNsProp(cur->parent, elem->name, elem->ns->href); + /* elem has already been unlinked so can never be attr */ + if ((attr != NULL) && (attr->type != XML_ATTRIBUTE_DECL)) { + /* different instance, destroy it (attributes must be unique) */ + xmlUnlinkNode((xmlNodePtr) attr); + xmlFreeProp(attr); + } } if (elem->doc != cur->doc) { *************** *** 3056,3064 **** elem->next = NULL; elem->parent = parent; cur->next = elem; - if (parent != NULL) - parent->last = elem; return(elem); } --- 3111,3134 ---- elem->next = NULL; elem->parent = parent; cur->next = elem; + if (parent != NULL) { + if (elem->type == XML_ATTRIBUTE_NODE) { + if (elem->parent->properties == (xmlAttrPtr) cur) { + elem->parent->properties = (xmlAttrPtr) elem; + } + if (xmlIsID(elem->doc, parent, (xmlAttrPtr) elem)) { + xmlChar *id; + + id = xmlNodeListGetString(elem->doc, elem->children, 1); + if (id != NULL) { + xmlAddID(NULL, elem->doc, id, (xmlAttrPtr) elem); + xmlFree(id); + } + } + } else + parent->last = elem; + } return(elem); } *************** *** 3255,3260 **** --- 3325,3339 ---- lastattr->next = (xmlAttrPtr) cur; ((xmlAttrPtr) cur)->prev = lastattr; } + if (xmlIsID(cur->doc, parent, (xmlAttrPtr) cur)) { + xmlChar *id; + + id = xmlNodeListGetString(cur->doc, cur->children, 1); + if (id != NULL) { + xmlAddID(NULL, cur->doc, id, (xmlAttrPtr) cur); + xmlFree(id); + } + } } else { if (parent->children == NULL) { parent->children = cur; *************** *** 3455,3464 **** parent = cur->parent; if (cur->type == XML_ATTRIBUTE_NODE) { /* If attribute is an ID from subset then remove it */ ! if ((((xmlAttrPtr) cur)->atype == XML_ATTRIBUTE_ID) && ! xmlIsID(parent->doc, parent, (xmlAttrPtr) cur)) { xmlRemoveID(cur->doc, (xmlAttrPtr) cur); - } if (parent->properties == (xmlAttrPtr) cur) parent->properties = ((xmlAttrPtr) cur)->next; } else { --- 3534,3541 ---- parent = cur->parent; if (cur->type == XML_ATTRIBUTE_NODE) { /* If attribute is an ID from subset then remove it */ ! if (((xmlAttrPtr) cur)->atype == XML_ATTRIBUTE_ID) xmlRemoveID(cur->doc, (xmlAttrPtr) cur); if (parent->properties == (xmlAttrPtr) cur) parent->properties = ((xmlAttrPtr) cur)->next; } else { *************** *** 3534,3542 **** cur->parent->properties = ((xmlAttrPtr) cur); /* If old attribute is ID and defined in DTD then remove ID */ ! if ((((xmlAttrPtr) old)->atype == XML_ATTRIBUTE_ID) && ! xmlIsID(old->doc, old->parent, (xmlAttrPtr) old)) { xmlRemoveID(old->doc, (xmlAttrPtr) old); } } else { if (cur->parent->children == old) --- 3611,3627 ---- cur->parent->properties = ((xmlAttrPtr) cur); /* If old attribute is ID and defined in DTD then remove ID */ ! if (((xmlAttrPtr) old)->atype == XML_ATTRIBUTE_ID) xmlRemoveID(old->doc, (xmlAttrPtr) old); + /* Check if new attribute is ID */ + if (xmlIsID(cur->doc, cur->parent, (xmlAttrPtr) cur)) { + xmlChar *id; + + id = xmlNodeListGetString(cur->doc, cur->children, 1); + if (id != NULL) { + xmlAddID(NULL, cur->doc, id, (xmlAttrPtr) cur); + xmlFree(id); + } } } else { if (cur->parent->children == old) *************** *** 6395,6407 **** doc = node->doc; prop = node->properties; while (prop != NULL) { if ((xmlStrEqual(prop->name, name)) && (prop->ns == NULL)){ xmlNodePtr oldprop = prop->children; ! int id = xmlIsID(node->doc, node, prop); ! ! if (id == 1) xmlRemoveID(node->doc, prop); prop->children = NULL; prop->last = NULL; if (value != NULL) { --- 6480,6493 ---- doc = node->doc; prop = node->properties; while (prop != NULL) { + int id = 0; if ((xmlStrEqual(prop->name, name)) && (prop->ns == NULL)){ xmlNodePtr oldprop = prop->children; ! if (prop->atype == XML_ATTRIBUTE_ID) { ! id = 1; xmlRemoveID(node->doc, prop); + } prop->children = NULL; prop->last = NULL; if (value != NULL) { *************** *** 6468,6477 **** */ if ((xmlStrEqual(prop->name, name)) && (prop->ns != NULL) && (xmlStrEqual(prop->ns->href, ns->href))) { ! int id = xmlIsID(node->doc, node, prop); ! ! if (id == 1) xmlRemoveID(node->doc, prop); if (prop->children != NULL) xmlFreeNodeList(prop->children); prop->children = NULL; --- 6554,6564 ---- */ if ((xmlStrEqual(prop->name, name)) && (prop->ns != NULL) && (xmlStrEqual(prop->ns->href, ns->href))) { ! int id = 0; ! if (prop->atype == XML_ATTRIBUTE_ID) { ! id = 1; xmlRemoveID(node->doc, prop); + } if (prop->children != NULL) xmlFreeNodeList(prop->children); prop->children = NULL;