neilg       2003/12/07 16:10:47

  Modified:    c/src/xercesc/internal DGXMLScanner.cpp IGXMLScanner.cpp
  Log:
  fix duplicate attribute detection when namespaces are disabled
  
  Revision  Changes    Path
  1.32      +70 -60    xml-xerces/c/src/xercesc/internal/DGXMLScanner.cpp
  
  Index: DGXMLScanner.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/DGXMLScanner.cpp,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- DGXMLScanner.cpp  24 Nov 2003 05:09:38 -0000      1.31
  +++ DGXMLScanner.cpp  8 Dec 2003 00:10:47 -0000       1.32
  @@ -1264,6 +1264,74 @@
               //  not validating of course it will not be at first, but we will
               //  fault it into the pool (to avoid lots of redundant errors.)
               XMLAttDef* attDef = ((DTDElementDecl *)elemDecl)->getAttDef ( 
fAttNameBuf.getRawBuffer());
  +            XMLCh * namePtr = fAttNameBuf.getRawBuffer();
  +
  +            //  Add this attribute to the attribute list that we use to
  +            //  pass them to the handler. We reuse its existing elements
  +            //  but expand it as required.
  +            // Note that we want to this first since this will
  +            // make a copy of the namePtr; we can then make use of
  +            // that copy in the hashtable lookup that checks
  +            // for duplicates.  This will mean we may have to update
  +            // the type of the XMLAttr later.
  +            XMLAttr* curAtt;
  +            if (attCount >= curAttListSize)
  +            {
  +                if (fDoNamespaces) {
  +                    curAtt = new (fMemoryManager) XMLAttr
  +                    (
  +                        fEmptyNamespaceId
  +                        , fAttNameBuf.getRawBuffer()
  +                        , XMLUni::fgZeroLenString
  +                        , (attDef)?attDef->getType():XMLAttDef::CData
  +                        , true
  +                        , fMemoryManager
  +                    );
  +                }
  +                else
  +                {
  +                    curAtt = new (fMemoryManager) XMLAttr
  +                    (
  +                        -1
  +                        , fAttNameBuf.getRawBuffer()
  +                        , XMLUni::fgZeroLenString
  +                        , XMLUni::fgZeroLenString
  +                        , (attDef)?attDef->getType():XMLAttDef::CData
  +                        , true
  +                        , fMemoryManager
  +                    );
  +                }
  +                fAttrList->addElement(curAtt);
  +            }
  +            else
  +            {
  +                curAtt = fAttrList->elementAt(attCount);
  +
  +                if (fDoNamespaces)
  +                {
  +                    curAtt->set
  +                    (
  +                        fEmptyNamespaceId
  +                        , fAttNameBuf.getRawBuffer()
  +                        , XMLUni::fgZeroLenString
  +                        , (attDef)?attDef->getType():XMLAttDef::CData
  +                    );
  +                }
  +                else
  +                {
  +                    curAtt->set
  +                    (
  +                        -1
  +                        , fAttNameBuf.getRawBuffer()
  +                        , XMLUni::fgZeroLenString
  +                        , XMLUni::fgZeroLenString
  +                        , (attDef)?attDef->getType():XMLAttDef::CData
  +                    );
  +                }
  +                curAtt->setSpecified(true);
  +            }
  +            // reset namePtr so it refers to newly-allocated memory
  +            namePtr = (XMLCh *)curAtt->getName();
   
               // now need to prepare for duplicate detection
               if(attDef)
  @@ -1289,7 +1357,6 @@
               }
               else
               {
  -                XMLCh * namePtr = fAttNameBuf.getRawBuffer();
                   unsigned int *curCountPtr = fUndeclaredAttrRegistry->get(namePtr);
                   if(!curCountPtr)
                   {
  @@ -1360,6 +1427,8 @@
                       return false;
                   }
               }
  +            // must set the newly-minted value on the XMLAttr:
  +            curAtt->setValue(fAttValueBuf.getRawBuffer());
   
               //  Now that its all stretched out, lets look at its type and
               //  determine if it has a valid value. It will output any needed
  @@ -1404,65 +1473,6 @@
                   }
               }
   
  -            //  Add this attribute to the attribute list that we use to
  -            //  pass them to the handler. We reuse its existing elements
  -            //  but expand it as required.
  -            XMLAttr* curAtt;
  -            if (attCount >= curAttListSize)
  -            {
  -                if (fDoNamespaces) {
  -                    curAtt = new (fMemoryManager) XMLAttr
  -                    (
  -                        fEmptyNamespaceId
  -                        , fAttNameBuf.getRawBuffer()
  -                        , fAttValueBuf.getRawBuffer()
  -                        , (attDef)?attDef->getType():XMLAttDef::CData
  -                        , true
  -                        , fMemoryManager
  -                    );
  -                }
  -                else
  -                {
  -                    curAtt = new (fMemoryManager) XMLAttr
  -                    (
  -                        -1
  -                        , fAttNameBuf.getRawBuffer()
  -                        , XMLUni::fgZeroLenString
  -                        , fAttValueBuf.getRawBuffer()
  -                        , (attDef)?attDef->getType():XMLAttDef::CData
  -                        , true
  -                        , fMemoryManager
  -                    );
  -                }
  -                fAttrList->addElement(curAtt);
  -            }
  -            else
  -            {
  -                curAtt = fAttrList->elementAt(attCount);
  -
  -                if (fDoNamespaces)
  -                {
  -                    curAtt->set
  -                    (
  -                        fEmptyNamespaceId
  -                        , fAttNameBuf.getRawBuffer()
  -                        , fAttValueBuf.getRawBuffer()
  -                        , (attDef)?attDef->getType():XMLAttDef::CData
  -                    );
  -                }
  -                else
  -                {
  -                    curAtt->set
  -                    (
  -                        -1
  -                        , fAttNameBuf.getRawBuffer()
  -                        , XMLUni::fgZeroLenString
  -                        , fAttValueBuf.getRawBuffer()
  -                        , (attDef)?attDef->getType():XMLAttDef::CData
  -                    );
  -                }
  -                curAtt->setSpecified(true);
  -            }
               attCount++;
   
               // And jump back to the top of the loop
  
  
  
  1.44      +43 -33    xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp
  
  Index: IGXMLScanner.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- IGXMLScanner.cpp  3 Dec 2003 20:00:27 -0000       1.43
  +++ IGXMLScanner.cpp  8 Dec 2003 00:10:47 -0000       1.44
  @@ -1761,12 +1761,51 @@
                       return false;
                   }
               }
  -
               //  See if this attribute is declared for this element. If we are
               //  not validating of course it will not be at first, but we will
               //  fault it into the pool (to avoid lots of redundant errors.)
               XMLCh * namePtr = fAttNameBuf.getRawBuffer();
               XMLAttDef* attDef = ((DTDElementDecl *)elemDecl)->getAttDef(namePtr);
  +
  +            //  Add this attribute to the attribute list that we use to
  +            //  pass them to the handler. We reuse its existing elements
  +            //  but expand it as required.
  +            // Note that we want to this first since this will
  +            // make a copy of the namePtr; we can then make use of
  +            // that copy in the hashtable lookup that checks
  +            // for duplicates.  This will mean we may have to update
  +            // the type of the XMLAttr later.
  +            XMLAttr* curAtt;
  +            if (attCount >= curAttListSize)
  +            {
  +                curAtt = new (fMemoryManager) XMLAttr
  +                (
  +                    -1
  +                    , namePtr
  +                    , XMLUni::fgZeroLenString
  +                    , XMLUni::fgZeroLenString
  +                    , (attDef)?attDef->getType():XMLAttDef::CData
  +                    , true
  +                    , fMemoryManager
  +                );
  +                fAttrList->addElement(curAtt);
  +            }
  +            else
  +            {
  +                curAtt = fAttrList->elementAt(attCount);
  +                curAtt->set
  +                (
  +                    -1
  +                    , namePtr
  +                    , XMLUni::fgZeroLenString
  +                    , XMLUni::fgZeroLenString
  +                    , (attDef)?attDef->getType():XMLAttDef::CData
  +                );
  +                curAtt->setSpecified(true);
  +            }
  +            // reset namePtr so it refers to newly-allocated memory
  +            namePtr = (XMLCh *)curAtt->getName();
  +
               if (!attDef)
               {
                   //  If there is a validation handler, then we are validating
  @@ -1821,6 +1860,7 @@
                       );
                   }
               }
  +
               //  Skip any whitespace before the value and then scan the att
               //  value. This will come back normalized with entity refs and
               //  char refs expanded.
  @@ -1858,6 +1898,8 @@
                       return false;
                   }
               }
  +            // must set the newly-minted value on the XMLAttr:
  +            curAtt->setValue(fAttValueBuf.getRawBuffer());
   
               //  Now that its all stretched out, lets look at its type and
               //  determine if it has a valid value. It will output any needed
  @@ -1878,39 +1920,7 @@
                   }
               }
   
  -            //  Add this attribute to the attribute list that we use to
  -            //  pass them to the handler. We reuse its existing elements
  -            //  but expand it as required.
  -            XMLAttr* curAtt;
  -            if (attCount >= curAttListSize)
  -            {
  -                curAtt = new (fMemoryManager) XMLAttr
  -                (
  -                    -1
  -                    , namePtr
  -                    , XMLUni::fgZeroLenString
  -                    , fAttValueBuf.getRawBuffer()
  -                    , (attDef)?attDef->getType():XMLAttDef::CData
  -                    , true
  -                    , fMemoryManager
  -                );
  -                fAttrList->addElement(curAtt);
  -            }
  -            else
  -            {
  -                curAtt = fAttrList->elementAt(attCount);
  -                curAtt->set
  -                (
  -                    -1
  -                    , namePtr
  -                    , XMLUni::fgZeroLenString
  -                    , fAttValueBuf.getRawBuffer()
  -                    , (attDef)?attDef->getType():XMLAttDef::CData
  -                );
  -                curAtt->setSpecified(true);
  -            }
               attCount++;
  -
               // And jump back to the top of the loop
               continue;
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to