views:

23

answers:

2

When JSPX compiles, it automatically adds <?xml version="1.0" encoding="UTF-8"?> to top of file which causes some JavaScript code not to work on Internet Explorer 6.

How can I avoid it to add <?xml version="1.0" encoding="UTF-8"?> in output file?

A: 

You can't. That's where "X" in JSPX stands for. JSP in XML format. You've basically two options:

  1. Use JSP instead of JSPX. This way you can output strict HTML instead of being forced to use XML/XHTML (recommended, unless you really need the advantages JSPX offers over JSP).

  2. Fix the JavaScript code so that it doesn't error. You can do this by either moving it out of the JSPX file into its own .js file which you just include by <script src="file.js"></script> in the <head> (recommended), or by replacing all special/reserved XML characters like & and so on by XML entities like &amp;, or by placing all the JS code inside a <![CDATA[ ]]> block.

BalusC
Notice that you may want to prefix <![CDATA[ and ]]> with a JavaScript line comment (//) for greater reliability in the face of tag soup, too.
A: 

The XML declaration does not automatically cause your JavaScript to break. Rather you have JavaScript that relies on the idiosyncrasies of HTML which fail to hold true in XML. A specific example of such an assumption would be relying on case-insensitive behaviour for (element) names in HTML rather that case-sensitive behaviour in XML.