Warning: DOMDocument :: loadXML () [function.DOMDocument-loadXML]: Object 'laquo' not defined in Entity

I take the server response using xml, xsl and extract the necessary fragments in order to extract the html fragments from the server response to client requrest. For example, suppose $ content has a server response before we process it.

$dom = new domDocument(); $dom->loadXML($content); $xslProgram = <<<xslProgram <xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:output method="html" encoding='UTF-8' indent="yes" /> <xsl:template match="/"> <xsl:copy-of select="$select" /> </xsl:template> </xsl:stylesheet> xslProgram; $domXsl = new domDocument(); $domXsl->loadXML($xslProgram); $xsl = new XSLTProcessor(); $xsl->importStylesheet($domXsl); $content = $xsl->transformToXml($dom); 

Everything seems to work correctly, but when it detects & nbsp, & laquo, & raquo, etc., the message "Warning: DOMDocument :: loadXML () [function.DOMDocument-loadXML]: Object 'laquo', not defined in Entity "

At first, I simply replaced all of these elements (& nbsp and others) with their unicode equivalents (str_replace), but then I understand that I cannot consider all of these options. How can I solve this problem?

Let me know if you did not make out, I can write a better explanation.

Thank you, Achmed.

+4
source share
2 answers

HTML objects are not defined in XML, so you get these errors. Have you considered using loadHTML() for your input document instead of loadXML() ?

 $dom = new domDocument(); $dom->loadHTML($content); 

http://php.net/manual/en/domdocument.loadhtml.php

+6
source

I think if you first passed $ content via html_entity_decode , your problems will go away.

+2
source

Source: https://habr.com/ru/post/1344367/


All Articles