[xml] attribute id handling part I



The attribute ID stuff is taking me a bit, mainly due to time, so I broke it up a bit. Here's is the beginning which handles removing IDs. Figure its safe for this functionality to live without the ID addition portion.

FreeProp - changed to just check atype flag so xml:id when not defined in a DTD will have ID removed

UnlinkNode - if it's an ID attribute it removes ID if defined in DTD. Keeps ID for attributes created by xml:id only

ReplaceNode - if old is an ID attribute it removes ID if defined in DTD. Keeps ID for attributes created by xml:id only

valid.c - set atype of attribute to 0 when ID removed

Rob
Index: tree.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/tree.c,v
retrieving revision 1.343
diff -c -r1.343 tree.c
*** tree.c      11 May 2005 18:03:42 -0000      1.343
--- tree.c      16 Jun 2005 13:25:59 -0000
***************
*** 1964,1974 ****
        xmlDeregisterNodeDefaultValue((xmlNodePtr)cur);
  
      /* Check for ID removal -> leading to invalid references ! */
!     if ((cur->parent != NULL) && (cur->parent->doc != NULL) &&
!       ((cur->parent->doc->intSubset != NULL) ||
!        (cur->parent->doc->extSubset != NULL))) {
!         if (xmlIsID(cur->parent->doc, cur->parent, cur))
!           xmlRemoveID(cur->parent->doc, cur);
      }
      if (cur->children != NULL) xmlFreeNodeList(cur->children);
      DICT_FREE(cur->name)
--- 1964,1971 ----
        xmlDeregisterNodeDefaultValue((xmlNodePtr)cur);
  
      /* Check for ID removal -> leading to invalid references ! */
!     if ((cur->doc != NULL) && (cur->atype == XML_ATTRIBUTE_ID)) {
!           xmlRemoveID(cur->doc, cur);
      }
      if (cur->children != NULL) xmlFreeNodeList(cur->children);
      DICT_FREE(cur->name)
***************
*** 3408,3413 ****
--- 3405,3415 ----
        xmlNodePtr parent;
        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 {
***************
*** 3481,3486 ****
--- 3483,3494 ----
        if (cur->type == XML_ATTRIBUTE_NODE) {
            if (cur->parent->properties == (xmlAttrPtr)old)
                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)
                cur->parent->children = cur;
Index: valid.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/valid.c,v
retrieving revision 1.209
diff -c -r1.209 valid.c
*** valid.c     15 Apr 2005 01:34:41 -0000      1.209
--- valid.c     16 Jun 2005 13:26:02 -0000
***************
*** 2772,2777 ****
--- 2772,2778 ----
      }
      xmlHashRemoveEntry(table, ID, (xmlHashDeallocator) xmlFreeID);
      xmlFree(ID);
+       attr->atype = 0;
      return(0);
  }
  


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]