I have been given an unusual goal and that is to remove CDATA from the XML(containing HTML) and to encode the following chars <, >, ‘, “, & in it.
But when I’m setting the nodeValue after converting ‘ and ” to '
and "
, the value is not being retained in the XML node and are being unescaped.
private function convertElement(DOMElement $element, $value)
{...
$value = htmlspecialchars($value ?? '', ENT_XML1 | ENT_QUOTES);
$element->nodeValue = $value;
dd($element->nodeValue);
//<p itemprop="description">'Test single quotes'</p><p itemprop="description">
//Should retain
//<p itemprop="description">'Test single quotes'</p>
And if i use appendChild(), it is causing the values to double escape.
//value = Test Ampersand &
$textNode = $this->document->createTextNode($value);
$element->appendChild($textNode);
//Test Amersand &
I’ll appreciate any workaround or suggestions.
Thanks!