diff --git a/src/xercesc/internal/IGXMLScanner2.cpp b/src/xercesc/internal/IGXMLScanner2.cpp
index dd04941ffa70dcf1c556085bffd946929b3c1beb..53915c7d4c8378af41dd0f8a56432b37ed531ef7 100644
--- a/src/xercesc/internal/IGXMLScanner2.cpp
+++ b/src/xercesc/internal/IGXMLScanner2.cpp
@@ -281,7 +281,7 @@ IGXMLScanner::buildAttList(const  RefVectorOf<KVStringPair>&  providedAttrs
                 //we may have set it to invalid already, but this is the first time we are guarenteed to have the attDef
                 if(((SchemaAttDef *)(attDef))->getValidity() != PSVIDefs::INVALID)
                     ((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::VALID);
-                    
+
                 ((SchemaAttDef *)(attDef))->setValidationAttempted(PSVIDefs::FULL);
             }
 
@@ -292,7 +292,7 @@ IGXMLScanner::buildAttList(const  RefVectorOf<KVStringPair>&  providedAttrs
                 attDef->setCreateReason(XMLAttDef::JustFaultIn);
             }
 
-            bool errorCondition = fValidate && !attDefForWildCard && 
+            bool errorCondition = fValidate && !attDefForWildCard &&
                 attDef->getCreateReason() == XMLAttDef::JustFaultIn && !attDef->getProvided();
             if (errorCondition && !skipThisOne && !laxThisOne)
             {
@@ -334,7 +334,7 @@ IGXMLScanner::buildAttList(const  RefVectorOf<KVStringPair>&  providedAttrs
             if (attDef->getProvided())
             {
                 emitError
-                ( 
+                (
                     XMLErrs::AttrAlreadyUsedInSTag
                     , attDef->getFullName()
                     , elemDecl->getFullName()
@@ -517,7 +517,7 @@ IGXMLScanner::buildAttList(const  RefVectorOf<KVStringPair>&  providedAttrs
                             XMLValid::RequiredAttrNotProvided
                             , curDef->getFullName()
                         );
-                        if(fGrammarType == Grammar::SchemaGrammarType) 
+                        if(fGrammarType == Grammar::SchemaGrammarType)
                             ((SchemaAttDef *)(curDef))->setValidity(PSVIDefs::INVALID);
                     }
                     else if ((defType == XMLAttDef::Default) ||
@@ -527,7 +527,7 @@ IGXMLScanner::buildAttList(const  RefVectorOf<KVStringPair>&  providedAttrs
                         {
                             // XML 1.0 Section 2.9
                             // Document is standalone, so attributes must not be defaulted.
-                            fValidator->emitError(XMLValid::NoDefAttForStandalone, curDef->getFullName(), elemDecl->getFullName());                                                        
+                            fValidator->emitError(XMLValid::NoDefAttForStandalone, curDef->getFullName(), elemDecl->getFullName());
                             if(fGrammarType == Grammar::SchemaGrammarType)
                                 ((SchemaAttDef *)(curDef))->setValidity(PSVIDefs::INVALID);
                         }
@@ -993,7 +993,7 @@ void IGXMLScanner::sendCharData(XMLBuffer& toSend)
         {
             // They definitely cannot handle any type of char data
             fValidator->emitError(XMLValid::NoCharDataInCM);
-            if(fGrammarType == Grammar::SchemaGrammarType) 
+            if(fGrammarType == Grammar::SchemaGrammarType)
                 ((SchemaElementDecl *)topElem->fThisElement)->setValidity(PSVIDefs::INVALID);
         }
         else if (fReaderMgr.getCurrentReader()->isAllSpaces(rawBuf, len))
@@ -1086,7 +1086,7 @@ void IGXMLScanner::sendCharData(XMLBuffer& toSend)
             else
             {
                 fValidator->emitError(XMLValid::NoCharDataInCM);
-                if(fGrammarType == Grammar::SchemaGrammarType) 
+                if(fGrammarType == Grammar::SchemaGrammarType)
                     ((SchemaElementDecl *)topElem->fThisElement)->setValidity(PSVIDefs::INVALID);
             }
         }
@@ -1987,6 +1987,11 @@ void IGXMLScanner::scanCDSection()
     //  characters specially here.
     bool            emittedError = false;
     bool    gotLeadingSurrogate = false;
+
+    // Get the character data opts for the current element
+    const ElemStack::StackElem* topElem = fElemStack.topElement();
+    XMLElementDecl::CharDataOpts charOpts = topElem->fThisElement->getCharDataOpts();
+
     while (true)
     {
         const XMLCh nextCh = fReaderMgr.getNextChar();
@@ -2003,19 +2008,15 @@ void IGXMLScanner::scanCDSection()
             // This document is standalone; this ignorable CDATA whitespace is forbidden.
             // XML 1.0, Section 2.9
             // And see if the current element is a 'Children' style content model
-            const ElemStack::StackElem* topElem = fElemStack.topElement();
 
             if (topElem->fThisElement->isExternal()) {
 
-                // Get the character data opts for the current element
-                XMLElementDecl::CharDataOpts charOpts =  topElem->fThisElement->getCharDataOpts();
-
                 if (charOpts == XMLElementDecl::SpacesOk) // Element Content
                 {
                     // Error - standalone should have a value of "no" as whitespace detected in an
                     // element type with element content whose element declaration was external
                     fValidator->emitError(XMLValid::NoWSForStandalone);
-                    if(fGrammarType == Grammar::SchemaGrammarType) 
+                    if(fGrammarType == Grammar::SchemaGrammarType)
                         ((SchemaElementDecl *)topElem->fThisElement)->setValidity(PSVIDefs::INVALID);
                 }
             }
@@ -2025,16 +2026,47 @@ void IGXMLScanner::scanCDSection()
         //  sequence.
         if (nextCh == chCloseSquare && fReaderMgr.skippedString(CDataClose))
         {
+            //  make sure we were not expecting a trailing surrogate.
+            if (gotLeadingSurrogate)
+                emitError(XMLErrs::Expected2ndSurrogateChar);
+
             if (fGrammarType == Grammar::SchemaGrammarType) {
 
+                if (fNormalizeData) {
+                    // normalize the character according to schema whitespace facet
+                    XMLBufBid bbtemp(&fBufMgr);
+                    XMLBuffer& tempBuf = bbtemp.getBuffer();
+
+                    DatatypeValidator* tempDV = ((SchemaElementDecl*) topElem->fThisElement)->getDatatypeValidator();
+                    ((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, bbCData.getRawBuffer(),  tempBuf);
+                    bbCData.set(tempBuf.getRawBuffer());
+                }
+
+                if (fValidate) {
+
+                    // tell the schema validation about the character data for checkContent later
+                    ((SchemaValidator*) fValidator)->setDatatypeBuffer(bbCData.getRawBuffer());
+
+                    if (charOpts != XMLElementDecl::AllCharData)
+                    {
+                        // They definitely cannot handle any type of char data
+                        fValidator->emitError(XMLValid::NoCharDataInCM);
+                        ((SchemaElementDecl *)topElem->fThisElement)->setValidity(PSVIDefs::INVALID);
+                    }
+                }
+
                 if (fMatcherStack->getMatcherCount())
                     fContent.append(bbCData.getRawBuffer(), bbCData.getLen());
             }
+            else {
+                if (fValidate) {
 
-            // tell the schema validation about the character data for checkContent later
-            if (fValidate && fSchemaValidator)
-            {           
-                    fSchemaValidator->setDatatypeBuffer(bbCData.getRawBuffer());
+                    if (charOpts != XMLElementDecl::AllCharData)
+                    {
+                        // They definitely cannot handle any type of char data
+                        fValidator->emitError(XMLValid::NoCharDataInCM);
+                    }
+                }
             }
 
             // If we have a doc handler, call it
@@ -2105,22 +2137,6 @@ void IGXMLScanner::scanCDSection()
             }
         }
 
-        if (fValidate) {
-            // And see if the current element is a 'Children' style content model
-            const ElemStack::StackElem* topElem = fElemStack.topElement();
-
-            // Get the character data opts for the current element
-            XMLElementDecl::CharDataOpts charOpts = topElem->fThisElement->getCharDataOpts();
-
-            if (charOpts != XMLElementDecl::AllCharData)
-            {
-                // They definitely cannot handle any type of char data
-                fValidator->emitError(XMLValid::NoCharDataInCM);
-                if(fGrammarType == Grammar::SchemaGrammarType) 
-                    ((SchemaElementDecl *)topElem->fThisElement)->setValidity(PSVIDefs::INVALID);
-            }
-        }
-
         // Add it to the buffer
         bbCData.append(nextCh);
     }
@@ -2315,7 +2331,7 @@ void IGXMLScanner::scanCharData(XMLBuffer& toUse)
                     // element type with element content whose element declaration was external
                     //
                     fValidator->emitError(XMLValid::NoWSForStandalone);
-                    if(fGrammarType == Grammar::SchemaGrammarType) 
+                    if(fGrammarType == Grammar::SchemaGrammarType)
                         ((SchemaElementDecl *)fElemStack.topElement()->fThisElement)->setValidity(PSVIDefs::INVALID);
                 }
             }
diff --git a/src/xercesc/internal/SGXMLScanner.cpp b/src/xercesc/internal/SGXMLScanner.cpp
index a0d8ab8bde73adf7e09e1fd2b89dd401e1653c73..8fbc76b09ad0894f24140c64d96d948107ea8e1c 100644
--- a/src/xercesc/internal/SGXMLScanner.cpp
+++ b/src/xercesc/internal/SGXMLScanner.cpp
@@ -954,7 +954,7 @@ void SGXMLScanner::scanEndTag(bool& gotData)
                     , topElem->fThisElement->getFormattedContentModel()
                 );
             }
-            
+
         }
 
         // call matchers and de-activate context
@@ -1209,7 +1209,7 @@ bool SGXMLScanner::scanStartTag(bool& gotData)
                     ,uriStr
                 );
                 errorBeforeElementFound = true;
-            } 
+            }
             else if(errorCondition)
                 laxBeforeElementFound = true;
 
@@ -1252,7 +1252,7 @@ bool SGXMLScanner::scanStartTag(bool& gotData)
                     );
                     errorBeforeElementFound = true;
                 }
-                else if(errorCondition) 
+                else if(errorCondition)
                     laxBeforeElementFound = true;
 
             }
@@ -1297,10 +1297,10 @@ bool SGXMLScanner::scanStartTag(bool& gotData)
                   , XMLUni::fgZeroLenString
                 );
                 errorBeforeElementFound = true;
-                
+
             }
             else if(errorCondition)
-                laxBeforeElementFound = true; 
+                laxBeforeElementFound = true;
 
             elemDecl = fGrammar->getElemDecl
             (
@@ -1336,7 +1336,7 @@ bool SGXMLScanner::scanStartTag(bool& gotData)
                     errorBeforeElementFound = true;
                 }
                 else if(errorCondition)
-                    laxBeforeElementFound = true; 
+                    laxBeforeElementFound = true;
 
                 elemDecl = fGrammar->getElemDecl
                            (
@@ -1414,9 +1414,9 @@ bool SGXMLScanner::scanStartTag(bool& gotData)
         if (!elemDecl->isDeclared()) {
             if (laxThisOne) {
                 fValidate = false;
-                fElemStack.setValidationFlag(fValidate);                
+                fElemStack.setValidationFlag(fValidate);
             }
-            
+
             if (fValidate)
                 {
                 fValidator->emitError
@@ -2096,7 +2096,7 @@ SGXMLScanner::buildAttList(const  RefVectorOf<KVStringPair>&  providedAttrs
                 //we may have set it to invalid already, but this is the first time we are guarenteed to have the attDef
                 if(((SchemaAttDef *)(attDef))->getValidity() != PSVIDefs::INVALID)
                     ((SchemaAttDef *)(attDef))->setValidity(PSVIDefs::VALID);
-                    
+
                 ((SchemaAttDef *)(attDef))->setValidationAttempted(PSVIDefs::FULL);
             }
 
@@ -2107,7 +2107,7 @@ SGXMLScanner::buildAttList(const  RefVectorOf<KVStringPair>&  providedAttrs
                 attDef->setCreateReason(XMLAttDef::JustFaultIn);
             }
 
-            bool errorCondition = fValidate && !attDefForWildCard && 
+            bool errorCondition = fValidate && !attDefForWildCard &&
                 attDef->getCreateReason() == XMLAttDef::JustFaultIn && !attDef->getProvided();
             if (errorCondition && !skipThisOne && !laxThisOne)
             {
@@ -2384,7 +2384,7 @@ SGXMLScanner::buildAttList(const  RefVectorOf<KVStringPair>&  providedAttrs
                         XMLValid::ProhibitedAttributePresent
                         , curDef->getFullName()
                     );
-                    ((SchemaAttDef *)curDef)->setValidity(PSVIDefs::INVALID);         
+                    ((SchemaAttDef *)curDef)->setValidity(PSVIDefs::INVALID);
                 }
                 ((SchemaElementDecl *)elemDecl)->updateValidityFromAttribute((SchemaAttDef *)curDef);
             }
@@ -2463,7 +2463,7 @@ bool SGXMLScanner::normalizeAttValue( const   XMLAttDef* const    attDef
                          // Can't have a standalone document declaration of "yes" if  attribute
                          // values are subject to normalisation
                          fValidator->emitError(XMLValid::NoAttNormForStandalone, attrName);
-                         ((SchemaAttDef *)attDef)->setValidity(PSVIDefs::INVALID);     
+                         ((SchemaAttDef *)attDef)->setValidity(PSVIDefs::INVALID);
                     }
                     nextCh = chSpace;
                 }
@@ -3489,6 +3489,11 @@ void SGXMLScanner::scanCDSection()
     //  characters specially here.
     bool            emittedError = false;
     bool    gotLeadingSurrogate = false;
+
+    // Get the character data opts for the current element
+    const ElemStack::StackElem* topElem = fElemStack.topElement();
+    XMLElementDecl::CharDataOpts charOpts =  topElem->fThisElement->getCharDataOpts();
+
     while (true)
     {
         const XMLCh nextCh = fReaderMgr.getNextChar();
@@ -3505,13 +3510,8 @@ void SGXMLScanner::scanCDSection()
             // This document is standalone; this ignorable CDATA whitespace is forbidden.
             // XML 1.0, Section 2.9
             // And see if the current element is a 'Children' style content model
-            const ElemStack::StackElem* topElem = fElemStack.topElement();
-
             if (topElem->fThisElement->isExternal()) {
 
-                // Get the character data opts for the current element
-                XMLElementDecl::CharDataOpts charOpts =  topElem->fThisElement->getCharDataOpts();
-
                 if (charOpts == XMLElementDecl::SpacesOk) // Element Content
                 {
                     // Error - standalone should have a value of "no" as whitespace detected in an
@@ -3530,16 +3530,33 @@ void SGXMLScanner::scanCDSection()
             if (gotLeadingSurrogate)
                 emitError(XMLErrs::Expected2ndSurrogateChar);
 
+            if (fValidate) {
+
+                if (fNormalizeData) {
+                    // normalize the character according to schema whitespace facet
+                    XMLBufBid bbtemp(&fBufMgr);
+                    XMLBuffer& tempBuf = bbtemp.getBuffer();
+
+                    DatatypeValidator* tempDV = ((SchemaElementDecl*) topElem->fThisElement)->getDatatypeValidator();
+                    ((SchemaValidator*) fValidator)->normalizeWhiteSpace(tempDV, bbCData.getRawBuffer(),  tempBuf);
+                    bbCData.set(tempBuf.getRawBuffer());
+                }
+
+                // tell the schema validation about the character data for checkContent later
+                ((SchemaValidator*) fValidator)->setDatatypeBuffer(bbCData.getRawBuffer());
+
+                if (charOpts != XMLElementDecl::AllCharData)
+                {
+                    // They definitely cannot handle any type of char data
+                    fValidator->emitError(XMLValid::NoCharDataInCM);
+                    ((SchemaElementDecl *)topElem->fThisElement)->setValidity(PSVIDefs::INVALID);
+                }
+            }
+
             // call all active identity constraints
             if (fMatcherStack->getMatcherCount())
                 fContent.append(bbCData.getRawBuffer(), bbCData.getLen());
 
-            // tell the schema validation about the character data for checkContent later
-            if (fValidate && fSchemaValidator)
-            {           
-                    fSchemaValidator->setDatatypeBuffer(bbCData.getRawBuffer());
-            }
-
             // If we have a doc handler, call it
             if (fDocHandler)
             {
@@ -3608,21 +3625,6 @@ void SGXMLScanner::scanCDSection()
             }
         }
 
-        if (fValidate) {
-            // And see if the current element is a 'Children' style content model
-            const ElemStack::StackElem* topElem = fElemStack.topElement();
-
-            // Get the character data opts for the current element
-            XMLElementDecl::CharDataOpts charOpts = topElem->fThisElement->getCharDataOpts();
-
-            if (charOpts != XMLElementDecl::AllCharData)
-            {
-                // They definitely cannot handle any type of char data
-                fValidator->emitError(XMLValid::NoCharDataInCM);
-                ((SchemaElementDecl *)topElem->fThisElement)->setValidity(PSVIDefs::INVALID);
-            }
-        }
-
         // Add it to the buffer
         bbCData.append(nextCh);
     }