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, but when it detects  , «, », 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 (  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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With