JavaScript EditorBest javascript editor debugger     Ajax website 

Main Page

Previous Page
Next Page

Hiding Scripts from XML Parsers

Scripts sometimes contain symbols that have special meaning in XHTML documents, namely the & and the >. If you use these symbols in a script, you should enclose them in a CDATA section to hide them from XML parsers (the programs that ensure that the XML, or XHTML in this case, is properly written).

To hide internal scripts from XML parsers:

Type <script> to begin your script as usual.

Type <![CDATA[ to hide the script from the XML parser.

Insert the script itself.

Type ]]> to complete the CDATA section.

And then type </script> to complete the script element.

Figure 19.19. This JavaScript script is adapted from Figure 20.1 on page 322. The CDATA section removes the special meaning from the characters in the script, essentially hiding them from the XML parser.


  • This is only necessary for XHTML documents with internal scripts. External scripts are automatically hidden from XML parsers.

  • It is also only necessary if you are serving your XHTML documents as XML. If you are serving them as HTML (which is true for the vast majority of Web pages), you don't have to enclose scripts in CDATA sections.

  • You can also hide internal style sheets in a CDATA section (see page 131).

Previous Page
Next Page

JavaScript EditorBest javascript editor debugger     Ajax website