You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2001/05/23 22:36:27 UTC

cvs commit: xml-xerces/c/src/parsers DOMParser.cpp IDOMParser.cpp

tng         01/05/23 13:36:27

  Modified:    c/src/parsers DOMParser.cpp IDOMParser.cpp
  Log:
  DTD with Namespace Fix
  
  Revision  Changes    Path
  1.50      +25 -21    xml-xerces/c/src/parsers/DOMParser.cpp
  
  Index: DOMParser.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/parsers/DOMParser.cpp,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- DOMParser.cpp	2001/05/17 15:30:02	1.49
  +++ DOMParser.cpp	2001/05/23 20:36:21	1.50
  @@ -59,7 +59,7 @@
   *  handler with the scanner. In these handler methods, appropriate DOM nodes
   *  are created and added to the DOM tree.
   *
  -* $Id: DOMParser.cpp,v 1.49 2001/05/17 15:30:02 tng Exp $
  +* $Id: DOMParser.cpp,v 1.50 2001/05/23 20:36:21 tng Exp $
   *
   */
   
  @@ -991,33 +991,37 @@
               {
                   if (fScanner->getDoNamespaces())
                   {
  -                    // Namespaces is turned on...
  -                    //   While scanning the DTD there is no binding defined from
  -                    //   name space prefixes to name space URIs.
  -                    //   But since there is error checking in AttrNSImpl ctor,
  -                    //   if prefix exists, we still need to map it somehow
  -
  +                    // DOM Level 2 wants all namespace declaration attributes
  +                    // to be bound to "http://www.w3.org/2000/xmlns/"
  +                    // So as long as the XML parser doesn't do it, it needs to
  +                    // done here.
                       DOMString qualifiedName = attr->getFullName();
                       int index = DocumentImpl::indexofQualifiedName(qualifiedName);
   
  +                    XMLBuffer buf;
  +                    static const XMLCh XMLNS[] = {
  +                        chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chNull};
  +
                       if (index > 0) {
                           // there is prefix
  -                        XMLBuffer localPart;
  -                        XMLBuffer prefix;
  -                        XMLBuffer uriText;
  -                        int uriId = fScanner->resolveQName(qualifiedName.rawBuffer(), localPart, prefix, ElemStack::Mode_Attribute);
  -                        fScanner->getURIText(uriId, uriText);
  -
  -                        insertAttr = new AttrNSImpl((DocumentImpl*)fDocument.fImpl,
  -                           DOMString(uriText.getRawBuffer()),     // NameSpaceURI
  -                           qualifiedName);   // qualified name
  +                        // map to XML URI for all cases except when prefix == "xmlns"
  +                        DOMString prefix = qualifiedName.substringData(0, index);
  +
  +                        if (prefix.equals(XMLNS))
  +                            fScanner->getURIText(fScanner->getXMLNSNamespaceId(), buf);
  +                        else
  +                            fScanner->getURIText(fScanner->getXMLNamespaceId(), buf);
                       }
                       else {
  -                        //   No prefix, just set all the URIs to be null.
  -                        insertAttr = new AttrNSImpl((DocumentImpl*)fDocument.fImpl,
  -                            DOMString(0),                     // NameSpaceURI
  -                            qualifiedName);   // qualified name
  -                     }
  +                        //   No prefix
  +                        if (qualifiedName.equals(XMLNS))
  +                            fScanner->getURIText(fScanner->getXMLNSNamespaceId(), buf);
  +                    }
  +
  +                    insertAttr = new AttrNSImpl((DocumentImpl*)fDocument.fImpl,
  +                       DOMString(buf.getRawBuffer()),     // NameSpaceURI
  +                       qualifiedName);   // qualified name
  +
                   }
                   else
                   {
  
  
  
  1.2       +35 -21    xml-xerces/c/src/parsers/IDOMParser.cpp
  
  Index: IDOMParser.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/parsers/IDOMParser.cpp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- IDOMParser.cpp	2001/05/17 15:30:05	1.1
  +++ IDOMParser.cpp	2001/05/23 20:36:23	1.2
  @@ -59,7 +59,7 @@
   *  handler with the scanner. In these handler methods, appropriate IDOM nodes
   *  are created and added to the DOM tree.
   *
  -* $Id: IDOMParser.cpp,v 1.1 2001/05/17 15:30:05 tng Exp $
  +* $Id: IDOMParser.cpp,v 1.2 2001/05/23 20:36:23 tng Exp $
   *
   */
   
  @@ -1021,34 +1021,48 @@
               {
                   if (fScanner->getDoNamespaces())
                   {
  -                    // Namespaces is turned on...
  -                    //   While scanning the DTD there is no binding defined from
  -                    //   name space prefixes to name space URIs.
  -                    //   But since there is error checking in AttrNSImpl ctor,
  -                    //   if prefix exists, we still need to map it somehow
  -
  +                    // DOM Level 2 wants all namespace declaration attributes
  +                    // to be bound to "http://www.w3.org/2000/xmlns/"
  +                    // So as long as the XML parser doesn't do it, it needs to
  +                    // done here.
                       const XMLCh* qualifiedName = attr->getFullName();
                       int index = IDDocumentImpl::indexofQualifiedName(qualifiedName);
   
  +                    XMLBuffer buf;
  +                    static const XMLCh XMLNS[] = {
  +                        chLatin_x, chLatin_m, chLatin_l, chLatin_n, chLatin_s, chNull};
  +
                       if (index > 0) {
                           // there is prefix
  +                        // map to XML URI for all cases except when prefix == "xmlns"
  +                        XMLCh* prefix;
  +                        XMLCh temp[1000];
  +
  +                        if (index > 999)
  +                            prefix = new XMLCh[index+1];
  +                        else
  +                            prefix = temp;
  +
  +                        XMLString::subString(prefix ,qualifiedName, 0, index);
   
  -                        XMLBuffer localPart;
  -                        XMLBuffer prefix;
  -                        XMLBuffer uriText;
  -                        int uriId = fScanner->resolveQName(qualifiedName, localPart, prefix, ElemStack::Mode_Attribute);
  -                        fScanner->getURIText(uriId, uriText);
  -
  -                        insertAttr = (IDAttrImpl *) fDocument->createAttributeNS(
  -                           uriText.getRawBuffer(),     // NameSpaceURI
  -                           qualifiedName);   // qualified name
  +                        if (!XMLString::compareString(prefix,XMLNS))
  +                            fScanner->getURIText(fScanner->getXMLNSNamespaceId(), buf);
  +                        else
  +                            fScanner->getURIText(fScanner->getXMLNamespaceId(), buf);
  +
  +                        if (index > 999)
  +                            delete prefix;
                       }
                       else {
  -                        //   No prefix, just set all the URIs to be null.
  -                        insertAttr = (IDAttrImpl *) fDocument->createAttributeNS(
  -                            XMLUni::fgZeroLenString,                     // NameSpaceURI
  -                            qualifiedName);   // qualified name
  -                     }
  +                        //   No prefix
  +                        if (!XMLString::compareString(qualifiedName,XMLNS))
  +                            fScanner->getURIText(fScanner->getXMLNSNamespaceId(), buf);
  +                    }
  +
  +                    insertAttr = (IDAttrImpl *) fDocument->createAttributeNS(
  +                       buf.getRawBuffer(),     // NameSpaceURI
  +                       qualifiedName);   // qualified name
  +
                   }
                   else
                   {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org