If you are generating XML from UTF-8 data source such a database table encoded in UTF-8, you will "XMLEscapeEntities: char out of range" error unless you encode the XML in UTF-8 as well. Just edit your new DOMDocument statement to the following to fix this problem.
$xml = new DOMDocument('1.0','utf-8');