diff --git a/src/xercesc/internal/ElemStack.hpp b/src/xercesc/internal/ElemStack.hpp
index 812c89d078465375d466f6d41ae2920dd6f96bdb..83bcdc7dee2eca11afa9fbbc657281fe23296f62 100644
--- a/src/xercesc/internal/ElemStack.hpp
+++ b/src/xercesc/internal/ElemStack.hpp
@@ -16,6 +16,9 @@
 
 /*
  * $Log$
+ * Revision 1.12  2005/04/26 17:37:50  cargilld
+ * Prefix mapping update to handle schema correctly.
+ *
  * Revision 1.11  2004/09/08 13:56:13  peiyongz
  * Apache License Version 2.0
  *
@@ -192,6 +195,8 @@ public :
         unsigned int        fCurrentURI;
         XMLCh *             fSchemaElemName;
         unsigned int        fSchemaElemNameMaxLen;
+        
+        int                 fPrefixColonPos;
     };
 
     enum MapModes
@@ -244,6 +249,9 @@ public :
     inline void setCurrentSchemaElemName(const XMLCh * const schemaElemName);
     inline XMLCh *getCurrentSchemaElemName();
 
+    void setPrefixColonPos(int colonPos);
+    int getPrefixColonPos() const;
+
     // -----------------------------------------------------------------------
     //  Prefix map methods
     // -----------------------------------------------------------------------
@@ -623,6 +631,15 @@ inline const XMLCh* ElemStack::getPrefixForId(unsigned int prefId) const
     return fPrefixPool.getValueForId(prefId);
 }
 
+inline void ElemStack::setPrefixColonPos(int colonPos)
+{
+    fStack[fStackTop-1]->fPrefixColonPos = colonPos;
+}
+ 
+inline int ElemStack::getPrefixColonPos() const {
+    return fStack[fStackTop-1]->fPrefixColonPos;
+}
+
 // ---------------------------------------------------------------------------
 //  WFElemStack: Miscellaneous methods
 // ---------------------------------------------------------------------------
diff --git a/src/xercesc/internal/IGXMLScanner.cpp b/src/xercesc/internal/IGXMLScanner.cpp
index 77bc86edfd2ad3ae6bea425ba084940e46c8bf16..0ce93db9ee938272d91b06d6b8b7f70626ef49cd 100644
--- a/src/xercesc/internal/IGXMLScanner.cpp
+++ b/src/xercesc/internal/IGXMLScanner.cpp
@@ -1160,13 +1160,22 @@ void IGXMLScanner::scanEndTag(bool& gotData)
 
     // If we have a doc handler, tell it about the end tag
     if (fDocHandler)
-    {
+    {        
+        if (fGrammarType == Grammar::SchemaGrammarType) {
+            if (topElem->fPrefixColonPos != -1)
+                fPrefixBuf.set(elemName, topElem->fPrefixColonPos);
+            else
+                fPrefixBuf.reset();
+        }
+        else {
+            fPrefixBuf.set(topElem->fThisElement->getElementName()->getPrefix());
+        }
         fDocHandler->endElement
         (
             *topElem->fThisElement
             , uriId
             , isRoot           
-            , topElem->fThisElement->getElementName()->getPrefix()
+            , fPrefixBuf.getRawBuffer()
         );
     }
 
@@ -2203,6 +2212,7 @@ bool IGXMLScanner::scanStartTagNS(bool& gotData)
     //  to expand up to get ready.
     unsigned int elemDepth = fElemStack.addLevel();
     fElemStack.setValidationFlag(fValidate);
+    fElemStack.setPrefixColonPos(prefixColonPos);
 
     //  Check if there is any external schema location specified, and if we are at root,
     //  go through them first before scanning those specified in the instance document
diff --git a/src/xercesc/internal/SGXMLScanner.cpp b/src/xercesc/internal/SGXMLScanner.cpp
index 2c420ad29b4d272b2a57e4eac41a800f85161d3d..c1a4cff67093fccb7cdd3e454b7d89e4390d9da2 100644
--- a/src/xercesc/internal/SGXMLScanner.cpp
+++ b/src/xercesc/internal/SGXMLScanner.cpp
@@ -1013,12 +1013,21 @@ void SGXMLScanner::scanEndTag(bool& gotData)
     // If we have a doc handler, tell it about the end tag
     if (fDocHandler)
     {
+        if (fGrammarType == Grammar::SchemaGrammarType) {
+            if (topElem->fPrefixColonPos != -1)
+                fPrefixBuf.set(elemName, topElem->fPrefixColonPos);
+            else
+                fPrefixBuf.reset();
+        }
+        else {
+            fPrefixBuf.set(topElem->fThisElement->getElementName()->getPrefix());
+        }
         fDocHandler->endElement
         (
             *topElem->fThisElement
             , uriId
             , isRoot            
-            , topElem->fThisElement->getElementName()->getPrefix()
+            , fPrefixBuf.getRawBuffer()
         );
     }
 
@@ -1155,6 +1164,7 @@ bool SGXMLScanner::scanStartTag(bool& gotData)
     //  to expand up to get ready.
     unsigned int elemDepth = fElemStack.addLevel();
     fElemStack.setValidationFlag(fValidate);
+    fElemStack.setPrefixColonPos(prefixColonPos);
 
     //  Check if there is any external schema location specified, and if we are at root,
     //  go through them first before scanning those specified in the instance document
diff --git a/src/xercesc/internal/XSAXMLScanner.cpp b/src/xercesc/internal/XSAXMLScanner.cpp
index 609018395d532e00472f10e58335cf0aa97505c6..2358a2b8bd91dbd2611c4f59503195545520bbb5 100644
--- a/src/xercesc/internal/XSAXMLScanner.cpp
+++ b/src/xercesc/internal/XSAXMLScanner.cpp
@@ -156,13 +156,17 @@ void XSAXMLScanner::scanEndTag(bool& gotData)
 
     // If we have a doc handler, tell it about the end tag
     if (fDocHandler)
-    {
+    {        
+        if (topElem->fPrefixColonPos != -1)
+            fPrefixBuf.set(elemName, topElem->fPrefixColonPos);
+        else
+            fPrefixBuf.reset();        
         fDocHandler->endElement
         (
             *topElem->fThisElement
             , uriId
             , isRoot
-            , topElem->fThisElement->getElementName()->getPrefix()
+            , fPrefixBuf.getRawBuffer()            
         );
     }
 
@@ -259,6 +263,7 @@ bool XSAXMLScanner::scanStartTag(bool& gotData)
     //  to expand up to get ready.
     unsigned int elemDepth = fElemStack.addLevel();
     fElemStack.setValidationFlag(fValidate);
+    fElemStack.setPrefixColonPos(prefixColonPos);
 
     //  Make an initial pass through the list and find any xmlns attributes or
     //  schema attributes.