Handles encoding issues when generating DomDocument.