((EntityReferenceImpl)entityRef).setReadOnly(false, false);
// insert entity ref into tree and append middle text
Node parent = text.getParentNode();
parent.replaceChild(entityRef, text1);
entityRef.appendChild(text1);
// see if there are any nested entity refs
if (i < entityCount - 1) {
int nextEntityOffset = attributes.getEntityOffset(attrIndex, i + 1);
if (nextEntityOffset < entityOffset + entityLength) {