diff --git a/src/xercesc/dom/ElementImpl.cpp b/src/xercesc/dom/ElementImpl.cpp
index f5e5e49a84d9e578df97cbbfb46e360c1d5a6e78..0c9fec88e1c6829c224ae874d6db278546936b94 100644
--- a/src/xercesc/dom/ElementImpl.cpp
+++ b/src/xercesc/dom/ElementImpl.cpp
@@ -284,7 +284,8 @@ AttrImpl * ElementImpl::setAttributeNode(AttrImpl *newAttr)
 void ElementImpl::setReadOnly(bool readOnl, bool deep)
 {
     ParentNode::setReadOnly(readOnl,deep);
-    attributes->setReadOnly(readOnl,true);
+    if (attributes != null)
+        attributes->setReadOnly(readOnl,true);
 };
 
 
diff --git a/src/xercesc/dom/EntityImpl.cpp b/src/xercesc/dom/EntityImpl.cpp
index 11e074a2816dc2ab9d244f5f7890436f02cb0efd..95a9335b649513386e0e664d813d09aae3e2dc6c 100644
--- a/src/xercesc/dom/EntityImpl.cpp
+++ b/src/xercesc/dom/EntityImpl.cpp
@@ -69,7 +69,7 @@ EntityImpl::EntityImpl(DocumentImpl *ownerDoc, const DOMString &eName)
 
 {
     name        = eName.clone();
-    isReadOnly(true);
+    setReadOnly(true, true);
 };
 
 
@@ -87,7 +87,7 @@ EntityImpl::EntityImpl(const EntityImpl &other, bool deep)
     refEntity       = other.refEntity;	
     RefCountedImpl::addRef(other.refEntity);
 
-    isReadOnly(true);
+    setReadOnly(true, true);
 };
 
 
@@ -166,9 +166,9 @@ void	EntityImpl::cloneEntityRefTree()
 	if (!refEntity)
 		return;
 
-   isReadOnly(false);
+   setReadOnly(false, true);
 	this->cloneChildren(*refEntity);
-   isReadOnly(true);
+   setReadOnly(true, true);
 }
 
 NodeImpl * EntityImpl::getFirstChild()
diff --git a/src/xercesc/dom/EntityReferenceImpl.cpp b/src/xercesc/dom/EntityReferenceImpl.cpp
index 197c9f61bed9233868fdadb4f40703bebfcd5288..fde30acef2a1a8775b6d14f7b9a84a0ffb2c8c64 100644
--- a/src/xercesc/dom/EntityReferenceImpl.cpp
+++ b/src/xercesc/dom/EntityReferenceImpl.cpp
@@ -127,8 +127,22 @@ EntityReferenceImpl::EntityReferenceImpl(DocumentImpl *ownerDoc,
     name = entityName.clone();
     // EntityReference behaves as a read-only node, since its contents
     // reflect the Entity it refers to -- but see setNodeName().
-    isReadOnly(true);
-    entityChanges=-1;
+
+    //retrieve the corresponding entity content
+    if (ownerDoc) {
+        if (ownerDoc->getDoctype()) {
+            if (ownerDoc->getDoctype()->getEntities()) {
+                EntityImpl* entity = (EntityImpl*)ownerDoc->getDoctype()->getEntities()->getNamedItem(entityName);
+                if (entity) {
+                    EntityReferenceImpl* refEntity = entity->getEntityRef();
+                    if (refEntity)
+                        cloneChildren(*refEntity);
+                }
+            }
+        }
+    }
+
+    setReadOnly(true, true);
 }
 
 
@@ -140,8 +154,7 @@ EntityReferenceImpl::EntityReferenceImpl(const EntityReferenceImpl &other,
     name = other.name.clone();
     if (deep)
         cloneChildren(other);
-    entityChanges = other.entityChanges;
-    isReadOnly(true);
+    setReadOnly(true, true);
 }
 
 
@@ -184,7 +197,7 @@ bool EntityReferenceImpl::isEntityReference()
 */
 void EntityReferenceImpl::setReadOnly(bool readOnl,bool deep)
 {
-    if(readOnl==false)
+    if(getOwnerDocument()->getErrorChecking() && readOnl==false)
         throw DOM_DOMException(DOM_DOMException::NO_MODIFICATION_ALLOWED_ERR,null);
     ParentNode::setReadOnly(readOnl,deep);
 }
diff --git a/src/xercesc/dom/EntityReferenceImpl.hpp b/src/xercesc/dom/EntityReferenceImpl.hpp
index 7742b95aa3ea991c4e8b16b59671e0c2c0699880..d19e9194612b8875c6fa1399694854fdea60662d 100644
--- a/src/xercesc/dom/EntityReferenceImpl.hpp
+++ b/src/xercesc/dom/EntityReferenceImpl.hpp
@@ -77,7 +77,6 @@ class CDOM_EXPORT EntityReferenceImpl: public ParentNode
 {
 private:
     DOMString name;
-    int entityChanges;
 
 public:
     EntityReferenceImpl(DocumentImpl *ownerDoc, const DOMString &entityName);
diff --git a/src/xercesc/idom/IDEntityImpl.cpp b/src/xercesc/idom/IDEntityImpl.cpp
index 198e1f27b0a090c7bfc06c76cec253e5c3ac0814..601ea3db5b31065d28532a68dd54184d454e67ac 100644
--- a/src/xercesc/idom/IDEntityImpl.cpp
+++ b/src/xercesc/idom/IDEntityImpl.cpp
@@ -70,7 +70,7 @@ IDEntityImpl::IDEntityImpl(IDOM_Document *ownerDoc, const XMLCh *eName)
 {
     fRefEntity  = 0;
     fName        = ((IDDocumentImpl *)ownerDoc)->getPooledString(eName);
-    fNode.isReadOnly(true);
+    fNode.setReadOnly(true, true);
 };
 
 
@@ -85,7 +85,7 @@ IDEntityImpl::IDEntityImpl(const IDEntityImpl &other, bool deep)
     fNotationName    = other.fNotationName;
 
     fRefEntity       = other.fRefEntity;	
-    fNode.isReadOnly(true);
+    fNode.setReadOnly(true, true);
 };
 
 
@@ -177,9 +177,9 @@ void	IDEntityImpl::cloneEntityRefTree() const
     if (!fRefEntity)
         return;
 
-    ncThis->fNode.isReadOnly(false);
+    ncThis->fNode.setReadOnly(false, true);
     ncThis->fParent.cloneChildren(fRefEntity);
-    ncThis->fNode.isReadOnly(true);
+    ncThis->fNode.setReadOnly(true, true);
 }
 
 IDOM_Node * IDEntityImpl::getFirstChild() const
diff --git a/src/xercesc/idom/IDEntityReferenceImpl.cpp b/src/xercesc/idom/IDEntityReferenceImpl.cpp
index e6b78588c828d46d68162204a8d2c710ada48200..b201e2518de6045f6a515e4a712b538da222d2b7 100644
--- a/src/xercesc/idom/IDEntityReferenceImpl.cpp
+++ b/src/xercesc/idom/IDEntityReferenceImpl.cpp
@@ -127,7 +127,22 @@ IDEntityReferenceImpl::IDEntityReferenceImpl(IDOM_Document *ownerDoc,
     fName = ((IDDocumentImpl *)getOwnerDocument())->getPooledString(entityName);
     // EntityReference behaves as a read-only node, since its contents
     // reflect the Entity it refers to -- but see setNodeName().
-    fNode.isReadOnly(true);
+    //retrieve the corresponding entity content
+
+    if (ownerDoc) {
+        if (ownerDoc->getDoctype()) {
+            if (ownerDoc->getDoctype()->getEntities()) {
+                IDEntityImpl* entity = (IDEntityImpl*)ownerDoc->getDoctype()->getEntities()->getNamedItem(entityName);
+                if (entity) {
+                    IDOM_EntityReference* refEntity = entity->getEntityRef();
+                    if (refEntity)
+                        fParent.cloneChildren(refEntity);
+                }
+            }
+        }
+    }
+
+    fNode.setReadOnly(true, true);
 }
 
 
@@ -139,7 +154,7 @@ IDEntityReferenceImpl::IDEntityReferenceImpl(const IDEntityReferenceImpl &other,
     fName = other.fName;
     if (deep)
         fParent.cloneChildren(&other);
-    fNode.isReadOnly(true);
+    fNode.setReadOnly(true, true);
 }
 
 
@@ -187,7 +202,7 @@ void IDEntityReferenceImpl::setNodeValue(const XMLCh *x)
 */
 void IDEntityReferenceImpl::setReadOnly(bool readOnl,bool deep)
 {
-    if(readOnl==false)
+    if(((IDDocumentImpl *)getOwnerDocument())->getErrorChecking() && readOnl==false)
         throw IDOM_DOMException(IDOM_DOMException::NO_MODIFICATION_ALLOWED_ERR, 0);
     fNode.setReadOnly(readOnl,deep);
 }