[xmlc] Javascript output into XHTML
[email protected] Thu, 15 Sep 2005 17:53:46 +0200
| Newsgroups | gmane.comp.java.enhydra.xmlc |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format...
------------=_1126799631-21748-97
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
This is very frustrating. I want to output some javascript into my document via XMLC. The problem comes with < and > symbols. They get escaped into, for example:
---
<script type="text/javascript">
for(var i=0;i < someArray.length; i++)
{
// do stuff
}
</script>
---
This is invalid javascript, and generates an error in all the browsers I've tried.
Personally, I find section 4.8 of the XHTML Specification (http://www.w3.org/TR/xhtml1/#h-4.8) to be rather ridiculous. Why would the contents of the <script> tag be PCDATA?!? Why would they force you to make your javascript into CDATA just to do some comparisons or loops? I'd love to hear any explanations other than "backwards compatibility" for this.
Note that this is not a problem at all if I make my mime type "application/xhtml+xml", but then my page only works in Firefox, and I can't use any innerHTML javascript. The latter, I could eschew, but the former is a show stopper.
I can't use the org.w3c.dom.Document.createCDATASection() method, because that results in something like:
---
<script type="text/javascript"><![CDATA[
for(var i=0;i < someArray.length; i++)
{
// do stuff
}
]]></script>
---
And that's not valid javascript either!
From what I can tell from searching internet forums, you have to do something like:
---
<script>
<!-- // <![CDATA[ -->
for(var i=0;i < someArray.length; i++)
{
// do stuff
}
<!-- ]]> -->
</script>
---
Unfortunately, with the DOM methods available to me with XMLC, that's simply impossible to output.
As far as I can see, the only solution to this is to put some lessThan(a, b) and greaterThan(a, b) methods into an included js file. Obviously, this solution is revolting, and I would love to hear any other suggestions you might have.
Cheers,
Erik
------------=_1126799631-21748-97
Content-Type: text/plain; name="message-footer.txt"
Content-Disposition: inline; filename="message-footer.txt"
Content-Transfer-Encoding: 8bit
--
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
------------=_1126799631-21748-97--