well, I'm afraid the solution is not sufficient, since the original document can contain some entities decoded and some not. Your solution will decode all possible entities.
Is there some other way how to preserve entities in state as they were in the original document?