Forum Moderators: open

Message Too Old, No Replies

Converting to xhtml

What does /*<![CDATA[*/ mean?

         

Mohamed_E

2:29 pm on Mar 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am using html-tidy to convert html to xhtml, and it is inserting a couple of strange lines in my code:
<link rel="StyleSheet" href="main.css" type="text/css" />
<link rel="StyleSheet" href="nn4_layout.css" type="text/css" />
<style type="text/css">
/*<![CDATA[*/
@import url(real_layout.css);
/*]]>*/
</style>

The two lines in C-style comments mystify me, clearly they "work" (the converted code validates) but what do they mean?

Thanks, I hope to update you on the conversion saga later today!

choster

2:48 pm on Mar 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



XHTML is an XML language, and CDATA is simply a shorthand to indicate text that is to be passed through without being processed. This is important because scripts often rely on characters such as the ampersand or less-than symbol which are reserved in XML, and which will prevent the document's correct processing if they are encountered. Here, I think the trigger was the @ symbol, which is XPath shorthand for an attribute.

But the concept of CDATA is meaningless in CSS (as in HTML). Thus, to preserve operability when this XHTML file is viewed as HTML and when it is processed as XML, the opening (<![CDATA[) and closing (]]>) tags are "hidden" inside CSS comments.

Similarly, an inline Javascript would be marked up as

<script type="text/javascript">
//<![CDATA[
... script here ...
//]]>
</script>

The necessity of adding these commented CDATA tags is an additional reason why scripts and stylesheets should be externalized as much as possible in XHTML.

[edited by: choster at 2:52 pm (utc) on Mar. 16, 2004]

Mohamed_E

2:51 pm on Mar 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks!

Mohamed_E

10:29 pm on Mar 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Rather than start a new thread, let me ask for more help here.

Just for fun, I want to make my xhtml pages "real" on my workstation (not on the server!) by serving them as application/xhtml+xml. Easy enough to do this with:

<meta http-equiv="Content-Type" content="application/xhtml+xml" />
Works fine with NN7.1. But when I go to validate I am told that there is no encoding, in spite of:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
This is lifted from the code given on w3c.org under Strictly Conforming Documents [w3.org]. Once I tell the validator what encoding I have used it finds no errors, so I am assuming that the syntax of my XML declaration is correct (or is it?).

Almost certainly a very basic mistake; I am still struggling to understand what is going on!

g1smd

9:07 pm on Mar 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



<meta http-equiv="Content-Type" content="application/xhtml+xml" /> is incomplete, or incorrect.

For HTML something like this <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> would be OK, you'll see that it includes the Character Set declaration too.