Re: [xml] DOM parser and HTML entities inside the <script> tag



Raymond Irving schrieb am 17.07.2012 um 13:51 (-0500):

When the following code is passed through the parser:

<script type="text/javascript">
   var d="&quot;Hello world;&quot;";
</script>

it will be converted to:

<script type="text/javascript">
   var d=""Hello world"";
</script>

The XML parser doesn't know that the <script> element is special (as you
correctly point out in the part I'm quoting below).

MiLu Dago: ~ > xmllint script.ml
<?xml version="1.0"?>
<script type="text/javascript">
   var d=""Hello world;"";
</script>

Use the HTML parser instead:

MiLu Dago: ~ > xmllint --html script.ml
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd";>
<html><head><script type="text/javascript">
   var d="&quot;Hello world;&quot;";
</script></head></html>

Michael

According to w3.org the entities should not be replaced replaces inside
CDATA sections, scripts or styles

http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/introduction.html#ID-E7C30824



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]