It drives me crazy, there are many similar problems on the Internet, but I canโt find the right solution.
I am creating an XML document in php to send as a response to an ajax request. The answer will look something like this:
<?xml version="1.0" encoding="iso-8859-1"?>
<response>
<status>success</status>
<message> —</message>
</response>
The tag will contain more meaningful information than that, but these are entities similar to those that give me the problem.
The php code that this xml generates is below:
header("Content-Type: text/xml");
$dom = new DOMDocument('1.0', 'iso-8859-1');
$dom->formatOutput = true;
$response_node = $dom->createElement("response");
$dom->appendChild($response_node);
$response_node->appendChild($dom->createElement('status', 'success'));
$response_node->appendChild($dom->createElement('message', " &mdash"));
echo $dom->saveXML();
return;
The xml shown above successfully returns to the javascript function that made the call, but when it tries to parse the XML document, it fails.
If I try to validate xml using this validator , I get the following error:
This page contains the following errors:
5 15: Entity 'nbsp'
— .
, - xml:
<!ENTITY name "entity_value">
, , . ? , ? , ?