homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

XHTML, CDATA and embedded javascript
Avoiding XHTML javascript errors by using CDATA

 8:04 pm on May 26, 2002 (gmt 0)

Avoiding XHTML javascript errors by using CDATA: Using embedded javascript in XHTML documents requires special attention to avoid parsing errors. An earlier thread dealt with this problem. [webmasterworld.com...]

The WC3 provides instruction on how to wrap javascript functions to avoid misinterpretation by the XML processor. Review section: 4.8 Script and Style elements [w3.org...]

The solution is simple, it only requires the script be wrapped within a CDATA marked section.

... unescaped script content ...

Wrapping your script with CDATA is only needed for embedded (page) scripts, not for externally referenced instances. Heads up!

Thanks to madcat, Nick_W and tedster for bringing this to light.



 7:01 am on May 27, 2002 (gmt 0)

Thanks for the tip, papabaer ;)

Q: Using CDATA won't cause any problems in older browsers?


 2:24 pm on May 27, 2002 (gmt 0)

That's what I thought Papabaer but then I found this:
Unfortunately, most browsers do not support CDATA sections (the standard XML method for including text containing special characters) so the safest option is to move your client-side scripts out to separate files and include them using the script element's src attribute.
- from O'Reilly - [xml.com...]

Granted this was published over a year ago but how do the browsers stack up now??


 4:00 am on May 28, 2002 (gmt 0)

Hi Lorax-

I have a keen interest in knowing what other browsers recognize CDATA as well. For now I can provide only a few that do for sure, and maybe when people start using this tag in their sites a bit more they can add on...




 1:45 pm on May 28, 2002 (gmt 0)

Good idea Madcat, then at least we'll have a comprehensive list to look to should we need it.

How did you perform your tests? It might be good to have a standard benchmark for testing other browsers as well.


 4:29 pm on May 28, 2002 (gmt 0)

Check out the section:

Q: I want the value of an element to be passed to the HTML result from an XSLT transformation as is (including special characters: >, <, &, etc.). How do I do that?

[xml.com ]

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved