[Expat-checkins] expat/lib xmlparse.c,1.105,1.106

Fred L. Drake fdrake at users.sourceforge.net
Fri Jan 24 22:53:07 EST 2003


Update of /cvsroot/expat/expat/lib
In directory sc8-pr-cvs1:/tmp/cvs-serv22135/lib

Modified Files:
	xmlparse.c 
Log Message:
Karl's fix for SF bug #673791:
Error with xmlns:prefix= with namespace processing enabled.

It seems that storeAtts() has the following properties:
- when called with tagNamePtr = NULL and bindingsPtr = NULL,
  it does not process attributes incl. namespace declarations
- when called with all arguments non-NULL it processes
  attributes (incl. default attributes) and namespace declarations

We also have these requirements:

A) for start of element event:

  1) if we have a startElementHandler:
     we need to process at least default attributes, 
     so we must call storeAtts with all arguments non-NULL
  2) if we have no startElementHandler, but we have attributes:
     we need to process namespace declarations,
     so we must call storeAtts with all arguments non-NULL
  3) if we have no startElementHandler and no attributes:
     we need to store the name (for the end element event, where
     the names are compared) and call only the default handler

  Note: Storing the name is a pre-requisiste for calling
        storeAtts with all arguments non-NULL.

So there really is no place for calling storeAtts with
tagNamePtr = NULL and bindingsPtr = NULL.

B) for empty element event:

  1) if we have a startElementHandler:
     we need to process at least default attributes,
     so we must call storeAtts with all arguments non-NULL
  2) if we have no startElementHandler, but we have attributes:
     we need to process namespace declarations,
     so we must call storeAtts with all arguments non-NULL
  3) if we have no startElementHandler and no attributes,
     but we have an endElementHandler:
     we need to store the name for calling the handler,
     but we need not process any attributes (default or not)
  4) if we have no start- or endElementHandler, and no attributes:
     we need to call only the default handler

Given that storeAtts will now always be called with all arguments
non-NULL we could remove a few internal checks in storeAtts,
if that improves efficiency. Not sure if that is worth it.

This patch should therefore fix the problem of namespace declarations
not being processed when no startElementHandler is set, that is,
it will fix Jeremy's NS processing patch.


Index: xmlparse.c
===================================================================
RCS file: /cvsroot/expat/expat/lib/xmlparse.c,v
retrieving revision 1.105
retrieving revision 1.106
diff -u -d -r1.105 -r1.106
--- xmlparse.c	24 Jan 2003 05:01:45 -0000	1.105
+++ xmlparse.c	25 Jan 2003 06:53:05 -0000	1.106
@@ -2046,14 +2046,9 @@
           reportDefault(parser, enc, s, next);
         break;
       }
-    case XML_TOK_START_TAG_WITH_ATTS:
-      if (!startElementHandler) {
-        enum XML_Error result = storeAtts(parser, enc, s, 0, 0);
-        if (result)
-          return result;
-      }
-      /* fall through */
     case XML_TOK_START_TAG_NO_ATTS:
+      /* fall through */
+    case XML_TOK_START_TAG_WITH_ATTS:
       {
         TAG *tag;
         enum XML_Error result;
@@ -2109,30 +2104,33 @@
         }
         tag->name.str = (XML_Char *)tag->buf;
         *toPtr = XML_T('\0');
-        if (startElementHandler) {
-          result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings));
-          if (result)
-            return result;
-          if (startElementHandler)
-            startElementHandler(handlerArg, tag->name.str,
-                                (const XML_Char **)atts);
-          else if (defaultHandler)
+        if (!startElementHandler && (tok == XML_TOK_START_TAG_NO_ATTS)) {
+          if (defaultHandler)
             reportDefault(parser, enc, s, next);
+          break;
         }
+        result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings));
+        if (result)
+          return result;
+        if (startElementHandler)
+          startElementHandler(handlerArg, tag->name.str,
+                              (const XML_Char **)atts);
         else if (defaultHandler)
           reportDefault(parser, enc, s, next);
         poolClear(&tempPool);
         break;
       }
-    case XML_TOK_EMPTY_ELEMENT_WITH_ATTS:
+    case XML_TOK_EMPTY_ELEMENT_NO_ATTS:
       if (!startElementHandler && !endElementHandler) {
-        enum XML_Error result = storeAtts(parser, enc, s, 0, 0);
-        if (result)
-          return result;
+        if (defaultHandler)
+          reportDefault(parser, enc, s, next);
+        if (tagLevel == 0)
+          return epilogProcessor(parser, next, end, nextPtr);
+        break;
       }
       /* fall through */
-    case XML_TOK_EMPTY_ELEMENT_NO_ATTS:
-      if (startElementHandler || endElementHandler) {
+    case XML_TOK_EMPTY_ELEMENT_WITH_ATTS:
+      {
         const char *rawName = s + enc->minBytesPerChar;
         enum XML_Error result;
         BINDING *bindings = NULL;
@@ -2143,10 +2141,13 @@
         if (!name.str)
           return XML_ERROR_NO_MEMORY;
         poolFinish(&tempPool);
-        result = storeAtts(parser, enc, s, &name, &bindings);
-        if (result)
-          return result;
-        poolFinish(&tempPool);
+        if (startElementHandler || 
+            (tok == XML_TOK_EMPTY_ELEMENT_WITH_ATTS)) {
+          result = storeAtts(parser, enc, s, &name, &bindings);
+          if (result)
+            return result;
+          poolFinish(&tempPool);
+        }
         if (startElementHandler) {
           startElementHandler(handlerArg, name.str, (const XML_Char **)atts);
           noElmHandlers = XML_FALSE;
@@ -2170,8 +2171,6 @@
           b->prefix->binding = b->prevPrefixBinding;
         }
       }
-      else if (defaultHandler)
-        reportDefault(parser, enc, s, next);
       if (tagLevel == 0)
         return epilogProcessor(parser, next, end, nextPtr);
       break;





More information about the Expat-checkins mailing list