diff --git a/src/xercesc/parsers/DOMBuilderImpl.cpp b/src/xercesc/parsers/DOMBuilderImpl.cpp
index 60a13215ef95433c66235446330025b56fdbf3ed..672093de4457a09d06a2b08b681f59a888e7c56f 100644
--- a/src/xercesc/parsers/DOMBuilderImpl.cpp
+++ b/src/xercesc/parsers/DOMBuilderImpl.cpp
@@ -96,6 +96,7 @@ AbstractDOMParser(valToAdopt)
 , fEntityResolver(0)
 , fFilter(0)
 , fCharsetOverridesXMLEncoding(true)
+, fUserAdoptsDocument(false)
 {
     // dom spec has different default from scanner's default, so set explicitly
     getScanner()->setNormalizeData(false);
@@ -207,9 +208,9 @@ void DOMBuilderImpl::setFeature(const XMLCh* const name, const bool state)
     else if (XMLString::compareIString(name, XMLUni::fgXercesUserAdoptsDOMDocument) == 0)
     {
         if(state)
-            adoptDocument();
+            fUserAdoptsDocument = true;
         else
-            throw DOMException(DOMException::NOT_SUPPORTED_ERR, 0);
+            fUserAdoptsDocument = false;
     }
 
     else if (XMLString::compareIString(name, XMLUni::fgXercesLoadExternalDTD) == 0)
@@ -317,7 +318,7 @@ bool DOMBuilderImpl::getFeature(const XMLCh* const name) const
         return getScanner()->getCalculateSrcOfs();
     }
     else if(XMLString::compareIString(name, XMLUni::fgXercesUserAdoptsDOMDocument) == 0) {
-        return isDocumentAdopted();
+        return fUserAdoptsDocument;
     }
     else {
         throw DOMException(DOMException::NOT_FOUND_ERR, 0);
@@ -336,6 +337,7 @@ bool DOMBuilderImpl::canSetFeature(const XMLCh* const name, const bool state) co
         (XMLString::compareIString(name, XMLUni::fgDOMValidateIfSchema) == 0) ||
         (XMLString::compareIString(name, XMLUni::fgDOMCharsetOverridesXMLEncoding) == 0) ||
         (XMLString::compareIString(name, XMLUni::fgDOMWhitespaceInElementContent) == 0) ||
+        (XMLString::compareIString(name, XMLUni::fgXercesUserAdoptsDOMDocument) == 0) ||
         (XMLString::compareIString(name, XMLUni::fgXercesCalculateSrcOfs) == 0)) {
         return true;
     }
@@ -347,8 +349,7 @@ bool DOMBuilderImpl::canSetFeature(const XMLCh* const name, const bool state) co
             return true;
     }
     else if (XMLString::compareIString(name, XMLUni::fgDOMNamespaceDeclarations) == 0 ||
-             XMLString::compareIString(name, XMLUni::fgDOMCDATASections) == 0 ||
-             XMLString::compareIString(name, XMLUni::fgXercesUserAdoptsDOMDocument) == 0) {
+             XMLString::compareIString(name, XMLUni::fgDOMCDATASections) == 0 ) {
         if (state)
             return true;
     }
@@ -420,19 +421,28 @@ DOMDocument* DOMBuilderImpl::parse(const DOMInputSource& source)
     Wrapper4DOMInputSource isWrapper((DOMInputSource*) &source, false);
 
     AbstractDOMParser::parse(isWrapper);
-    return getDocument();
+    if (fUserAdoptsDocument)
+        return adoptDocument();
+    else
+        return getDocument();
 }
 
 DOMDocument* DOMBuilderImpl::parseURI(const XMLCh* const systemId)
 {
     AbstractDOMParser::parse(systemId);
-    return getDocument();
+    if (fUserAdoptsDocument)
+        return adoptDocument();
+    else
+        return getDocument();
 }
 
 DOMDocument* DOMBuilderImpl::parseURI(const char* const systemId)
 {
     AbstractDOMParser::parse(systemId);
-    return getDocument();
+    if (fUserAdoptsDocument)
+        return adoptDocument();
+    else
+        return getDocument();
 }
 
 void DOMBuilderImpl::parseWithContext(const DOMInputSource& source,
diff --git a/src/xercesc/parsers/DOMBuilderImpl.hpp b/src/xercesc/parsers/DOMBuilderImpl.hpp
index dfc10bcdaa36fff2acb17a38b0d930c763ab959d..a5c505d3b8c16084ad8df120185386cd22cdae07 100644
--- a/src/xercesc/parsers/DOMBuilderImpl.hpp
+++ b/src/xercesc/parsers/DOMBuilderImpl.hpp
@@ -814,6 +814,11 @@ private :
     //
     //  fCharsetOverridesXMLEncoding
     //      Indicates if the "charset-overrides-xml-encoding" is set or not
+    //
+    //  fUserAdoptsDocument
+    //      The DOMDocument ownership has been transferred to application
+    //      If set to true, the parser does not own the document anymore
+    //      and thus will not release its memory.
     //-----------------------------------------------------------------------
     bool                        fAutoValidation;
     bool                        fValidation;
@@ -821,6 +826,7 @@ private :
     DOMErrorHandler*            fErrorHandler;
     DOMBuilderFilter*           fFilter;
     bool                        fCharsetOverridesXMLEncoding;
+    bool                        fUserAdoptsDocument;
 };