Re: [xml] Questions about xml:id



Daniel Veillard wrote:

 need to be extremely cautious about that part of the code because it
affects streaming DTD validation for ID/REF(S) checks, even when the node
have been removed. But in general the code need fixing for correct ID/xml:id support when
mutating trees. Not sure I will have time looking at it now, but if you're
interested I would take patches of course !
From what I can discern, SAX wouldn't have an issue as it is either building the tree or just passing name/values. Would there ever be a case where you could have the doc->ids built with no tree? This seem like the only way you could end up with an attribute with no element. As far as the reader goes, it has its own FreeProp function so it should never call xmlFreeProp. In the event you grab an expanded node, can the xmlFreeNode functions be used or is it mantatory to use the reader free node functions?

As far as trying to fix this area, see attached file for an idea of what I think is a more appropriate direction for this. I believe xmlIsID is used incorrectly when mutating trees when trying to determine if an existing attribute is an id or not. xmlIsID/xmlIsRef should really only be used when determining whether an attribute should be created as an ID or IDRef, but not for testing whether an attribute is really an ID or IDRef.

Last question on this, as I couldn't find an answer for this anywhere, is when an attribute which is an ID is unlinked from an element, though still is associated to a document, is the attribute still an ID or does it revert to a normal attribute at that point?

Rob
Index: tree.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/tree.c,v
retrieving revision 1.339
diff -c -r1.339 tree.c
*** tree.c      28 Feb 2005 10:28:20 -0000      1.339
--- tree.c      22 Mar 2005 12:55:56 -0000
***************
*** 2058,2068 ****
        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)
--- 2058,2065 ----
        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)
***************
*** 3738,3744 ****
      if ((target!= NULL) && (cur!= NULL) &&
        (target->doc != NULL) && (cur->doc != NULL) &&
        (cur->doc->ids != NULL) && (cur->parent != NULL)) {
!       if (xmlIsID(cur->doc, cur->parent, cur)) {
            xmlChar *id;
  
            id = xmlNodeListGetString(cur->doc, cur->children, 1);
--- 3735,3741 ----
      if ((target!= NULL) && (cur!= NULL) &&
        (target->doc != NULL) && (cur->doc != NULL) &&
        (cur->doc->ids != NULL) && (cur->parent != NULL)) {
!       if (cur->atype == XML_ATTRIBUTE_ID) {
            xmlChar *id;
  
            id = xmlNodeListGetString(cur->doc, cur->children, 1);
Index: valid.c
===================================================================
RCS file: /cvs/gnome/gnome-xml/valid.c,v
retrieving revision 1.207
diff -c -r1.207 valid.c
*** valid.c     26 Jan 2005 00:04:52 -0000      1.207
--- valid.c     22 Mar 2005 12:56:00 -0000
***************
*** 2768,2773 ****
--- 2768,2774 ----
      }
      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]