473,385 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

scriptalicious documentation suggests wrapping code in CDATA blocks - why?

I'm reading over this page:

http://wiki.script.aculo.us/scriptaculous/show/Usage

I'm struck by this code example
+++++++++++++++++++++++++++++++
3. Use

To call upon the functions, use HTML script tags. The best way is to
define them like this:

<script type="text/javascript" language="javascript">
// <![CDATA[
Effect.Appear('element_id');
// ]]>
</script>

+++++++++++++++++++++++++++++++
For god's sake, what are the CDATA blocks for? I've never seen that
before.

Jan 7 '06 #1
4 1987
"Jake Barnes" <lk******@geocities.com> wrote:
I'm reading over this page:

http://wiki.script.aculo.us/scriptaculous/show/Usage

I'm struck by this code example
+++++++++++++++++++++++++++++++
3. Use

To call upon the functions, use HTML script tags. The best way is to
define them like this:

<script type="text/javascript" language="javascript">
// <![CDATA[
Effect.Appear('element_id');
// ]]>
</script>

+++++++++++++++++++++++++++++++
For god's sake, what are the CDATA blocks for? I've never seen that
before.


All HTML(ish things) in the CDATA should be ignored.

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Jan 7 '06 #2

Jake Barnes wrote:
I'm reading over this page:

http://wiki.script.aculo.us/scriptaculous/show/Usage

I'm struck by this code example
+++++++++++++++++++++++++++++++
3. Use

To call upon the functions, use HTML script tags. The best way is to
define them like this:

<script type="text/javascript" language="javascript">
// <![CDATA[
Effect.Appear('element_id');
// ]]>
</script>

+++++++++++++++++++++++++++++++
For god's sake, what are the CDATA blocks for? I've never seen that
before.


The CDATA tag, which also has a close tag, is an XML tag. When you
write a true xhtml page using the correct mime type
application/xhtml+xml, you often have to enclose everything after the
script tag up to the close script tag in CDATA tags. The CDATA tags
tell an xml parser that the contents within them are not part of the
xml(script in this case) and should not be parsed as xml. Some
characters often used in script code are forbidden in xml and, if the
parser detects them, the page may not be displayed and just gives you a
report of an xml error. You can avoid all of this by using the script
as an external script in the usual way. Unfortunately many current
browsers do not understand CDATA tags, and if you use them the script
does not work. This is solved by making the CDATA tags JS comments.
Besides the // in your example, the multi-line JS comments often are
used instead such as /* <![CDATA[ */ and /* ]]> */ . XML aware browsers
and servers, including the W3C validator see right through the JS
comment tags, find the CDATA tags, and are happy. The many browsers
that are not properly xml aware see the CDATA tags as just ordinary JS
comments, and they are happy and your script works.

Jan 7 '06 #3
On 07/01/2006 02:25, cw******@yahoo.com wrote:
Jake Barnes wrote:
[snip]
<script type="text/javascript" language="javascript">
The recommendation of the language attribute is a bad start.
// <![CDATA[


Suggesting CDATA Sections in what is conspicuously HTML is not a good
sign, either.

If you are serving HTML (including XHTML served as HTML, which you
shouldn't bother doing), then use:

<script type="text/javascript">
Effect.Appear('element_id');
</script>

If you are serving XHTML (with an application/xhtml+xml MIME type), then
use:

<script type="text/javascript">
<![CDATA[
Effect.Appear('element_id');
]]>
</script>

Don't mix them. See <http://www.hixie.ch/advocacy/xhtml>.

[snip]
The CDATA tag, which also has a close tag, is an XML tag.


CDATA Sections are a feature of SGML, and therefore HTML, too (see B.3.5
Marked Sections in the HTML Specification). Browsers don't recognise
them though as no common browser parses HTML as an application of SGML.
XML is an application profile of SGML, so therefore it features CDATA
Sections as well.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Jan 7 '06 #4
Michael Winter wrote:
On 07/01/2006 02:25, cw******@yahoo.com wrote:
The CDATA tag, which also has a close tag, is an XML tag.
CDATA Sections are a feature of SGML, and therefore HTML, too (see B.3.5
Marked Sections in the HTML Specification).


In the HTML 4.01 Specification, to be precise:

<URL:http://www.w3.org/TR/html4/appendix/notes.html#h-B.3.5>
Browsers don't recognise them though as no common browser parses HTML as
an application of SGML. XML is an application profile of SGML, so
therefore it features CDATA Sections as well.


Thank you for pointing this out. I thought that marked sections were only
defined by XML (and for XML applications) before.
Regards,
PointedEars
Jan 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Isaac Councill | last post by:
Hello, This seems like a newbie question, but I couldn't find the answer on google. I've been using xsl to transform rdf files into runnable programs in another (non-markup) language. It's...
0
by: Dimitre Novatchev | last post by:
You seem to be unaware of the xslt processing which uses the built-in rules in the absence of templates that match some selected node. http://www.w3.org/TR/xslt#built-in-rule According to the...
5
by: But I Haven't Eaten Any Sweetcorn! | last post by:
Hi all, I have two XML DOMs and I am trying to insert one into another, so that <?xml = ....> <Body> <Head> </Head> </Body> and
2
by: Jimmy zhang | last post by:
Are they teh same thing in xml 1.0?
6
by: Cade Perkins | last post by:
How can the CDATA ending delimiter "]]>" be represented within a CDATA section itself? Consider an XML document that is intended to contain an embedded, uninterpreted XML example. Generally,...
2
by: Damon | last post by:
I'm getting errors using XML deserialisation and CDATA sections when there are hexidecimal characters involved. If the CDATA section does not contain a hexidecimal values everything is fine....
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
1
by: s123 | last post by:
Hi, while invoking a web service, if in xml request message i wrap the extended ASCII characters with CDATA it is not returning the desired result, while this is not the case if i do not wrap...
7
by: Silfheed | last post by:
Heyas So first off I know that CDATA is generally hated and just shouldn't be done, but I'm simply required to parse it and spit it back out. Parsing is pretty easy with lxml, but it's the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.