DOMDocument::loadXML() failed when parsing comments inside a script tag
| From: | Raymond Irving | Date: | Mon, 07 Jun 2010 02:39:57 +0000 |
| Subject: | DOMDocument::loadXML() failed when parsing comments inside a script tag | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-305869@lists.php.net to get a copy of this message | ||
Hello,
I'm experiencing another issue when attempting to use DOMDocument::loadXML()
to load the following HTML code:
<?php
$html = '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<script type="text/javascript">
<!--
var i = 0, html = "<strong>Bold Text</strong>,Normal Text";
document.write(html);
i--; // this line causes the parser to fail
alert(html);
-->
</script>
</body>
</html>';
$dom = new DOMDocument();
$dom->loadXML($html);
echo $dom->saveHTML();
?>
The parser throws the following error when it encounters "i--" in inside the
<script> tag:
Warning: DOMDocument::loadXML() [domdocument.loadxml]: Comment not
terminated <!-- var i = 0, html = "<strong>Bold Text< in Entity
If I remove the like "i--" it will load the HTML code just fine.
Any ideas as to why this throws an error?
__
Raymond