I am generating XML using PHP library as below:
$dom = new DOMDocument(\"1.0\",\"utf-8\");
Doing above results in a page which shows a mess
Prashant is absolutely right. You can also strip away invalid characters in Javascript by doing:
function utf8_for_xml(inputStr) { return inputStr.replace(/[^\x09\x0A\x0D\x20-\xFF\x85\xA0-\uD7FF\uE000-\uFDCF\uFDE0-\uFFFD]/gm, ''); }