You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by am...@apache.org on 2008/05/01 18:57:04 UTC

svn commit: r652578 - in /xerces/c/trunk/src/xercesc/dom/impl: DOMLSSerializerImpl.cpp DOMLSSerializerImpl.hpp

Author: amassari
Date: Thu May  1 09:57:04 2008
New Revision: 652578

URL: http://svn.apache.org/viewvc?rev=652578&view=rev
Log:
DOM serializer was not resetting the default namespace

Modified:
    xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp
    xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.hpp

Modified: xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp?rev=652578&r1=652577&r2=652578&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp (original)
+++ xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp Thu May  1 09:57:04 2008
@@ -814,38 +814,25 @@
                 // check if the namespace for the current node is already defined
                 const XMLCh* prefix = nodeToWrite->getPrefix();
                 const XMLCh* uri = nodeToWrite->getNamespaceURI();
-                if(uri && uri[0])
+                if((uri && uri[0]) || ((prefix==0 || prefix[0]==0) && isDefaultNamespacePrefixDeclared()))
                 {
                     if(prefix==0 || prefix[0]==0)
                         prefix=XMLUni::fgZeroLenString;
-                    bool bPrefixDeclared=false;
-                    for(int i=fNamespaceStack->size()-1;i>=0;i--)
-                    {
-                        RefHashTableOf<XMLCh>* curNamespaceMap=fNamespaceStack->elementAt(i);
-                        const XMLCh* thisUri=curNamespaceMap->get((void*)prefix);
-                        if(thisUri)
-                        {
-                            // the prefix has been declared: check if it binds to the correct namespace, otherwise, redeclare it
-                            if(XMLString::equals(thisUri,nodeToWrite->getNamespaceURI()))
-                                bPrefixDeclared=true;
-                            break;
-                        }
-                    }
-                    if(!bPrefixDeclared)
+                    if(!isNamespaceBindingActive(prefix, uri))
                     {
                         if(namespaceMap==NULL)
                         {
                             namespaceMap=new (fMemoryManager) RefHashTableOf<XMLCh>(12, false, fMemoryManager);
                             fNamespaceStack->addElement(namespaceMap);
                         }
-                        namespaceMap->put((void*)prefix,(XMLCh*)nodeToWrite->getNamespaceURI());
+                        namespaceMap->put((void*)prefix,(XMLCh*)uri);
                         *fFormatter  << XMLFormatter::NoEscapes
                                      << chSpace << XMLUni::fgXMLNSString;
                         if(!XMLString::equals(prefix,XMLUni::fgZeroLenString))
                             *fFormatter  << chColon << prefix;
                         *fFormatter  << chEqual << chDoubleQuote
                                      << XMLFormatter::AttrEscapes
-                                     << nodeToWrite->getNamespaceURI()
+                                     << uri
                                      << XMLFormatter::NoEscapes
                                      << chDoubleQuote;
                     }
@@ -908,32 +895,20 @@
                             const XMLCh* prefix = attribute->getPrefix();
                             if(prefix && prefix[0])
                             {
-                                bool bPrefixDeclared=false;
-                                for(int i=fNamespaceStack->size()-1;i>=0;i--)
-                                {
-                                    RefHashTableOf<XMLCh>* curNamespaceMap=fNamespaceStack->elementAt(i);
-                                    const XMLCh* thisUri=curNamespaceMap->get((void*)prefix);
-                                    if(thisUri)
-                                    {
-                                        // the prefix has been declared: check if it binds to the correct namespace, otherwise, redeclare it
-                                        if(XMLString::equals(thisUri,attribute->getNamespaceURI()))
-                                            bPrefixDeclared=true;
-                                        break;
-                                    }
-                                }
-                                if(!bPrefixDeclared)
+                                const XMLCh* uri = attribute->getNamespaceURI();
+                                if(!isNamespaceBindingActive(prefix, uri))
                                 {
                                     if(namespaceMap==NULL)
                                     {
                                         namespaceMap=new (fMemoryManager) RefHashTableOf<XMLCh>(12, false, fMemoryManager);
                                         fNamespaceStack->addElement(namespaceMap);
                                     }
-                                    namespaceMap->put((void*)prefix,(XMLCh*)attribute->getNamespaceURI());
+                                    namespaceMap->put((void*)prefix,(XMLCh*)uri);
                                     *fFormatter  << XMLFormatter::NoEscapes
                                                  << chSpace << XMLUni::fgXMLNSString << chColon << prefix
                                                  << chEqual << chDoubleQuote
                                                  << XMLFormatter::AttrEscapes
-                                                 << attribute->getNamespaceURI()
+                                                 << uri
                                                  << XMLFormatter::NoEscapes
                                                  << chDoubleQuote;
                                 }
@@ -1690,5 +1665,30 @@
     }
 }
 
+bool DOMLSSerializerImpl::isDefaultNamespacePrefixDeclared() const
+{
+    for(int i=fNamespaceStack->size()-1;i>=0;i--)
+    {
+        RefHashTableOf<XMLCh>* curNamespaceMap=fNamespaceStack->elementAt(i);
+        const XMLCh* thisUri=curNamespaceMap->get((void*)XMLUni::fgZeroLenString);
+        if(thisUri)
+            return true;
+    }
+    return false;
+}
+
+bool DOMLSSerializerImpl::isNamespaceBindingActive(const XMLCh* prefix, const XMLCh* uri) const
+{
+    for(int i=fNamespaceStack->size()-1;i>=0;i--)
+    {
+        RefHashTableOf<XMLCh>* curNamespaceMap=fNamespaceStack->elementAt(i);
+        const XMLCh* thisUri=curNamespaceMap->get((void*)prefix);
+        // if the prefix has been declared, check if it binds to the correct namespace, otherwise, reports it isn't bound
+        if(thisUri)
+            return XMLString::equals(thisUri,uri);
+    }
+    return false;
+}
+
 XERCES_CPP_NAMESPACE_END
 

Modified: xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.hpp?rev=652578&r1=652577&r2=652578&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.hpp (original)
+++ xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.hpp Thu May  1 09:57:04 2008
@@ -134,6 +134,8 @@
 
     void                          printNewLine();
     void                          setURCharRef();
+    bool                          isDefaultNamespacePrefixDeclared() const;
+    bool                          isNamespaceBindingActive(const XMLCh* prefix, const XMLCh* uri) const;
 
 
     void printIndent(unsigned int level);



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