开发者

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

I intrecept server's response using xml,xsl and extract required fragments, to extract html fragments from server reponse on client requrest. For example, lets suppose, that $content have 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);

It looks like everything is working correct, b开发者_开发百科ut when it detects &nbsp, &laquo, &raquo, etc, there is a message appears "Warning: DOMDocument::loadXML() [function.DOMDocument-loadXML]: Entity 'laquo' not defined in Entity"

At first I just replaced all this elements (&nbsp and others) with their unicode equiavalents ( str_replace), but then I understand that I can't consider all this variants. How can I solve this problem?

Let me know if you don't undestand me, I can write better explanation.

Thanks, Ahmed.


The HTML entities are not defined in XML, this is why you get those 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


I think that if you passed $content through html_entity_decode first, your problems would disappear.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜