Jan C. Faerber wrote:
Quote:
I read that in XML you can use CDATA sections to show code in a
browser. |
You misread, more or less. CDATA sections are for inserting character data
(C = character) to be treated as such, even if it contains constructs that
would normally be taken as tags or entity or character references in XML. It
has nothing particular to do with "code", whatever that means, though of
course computer code often contains "<" or "&".
XML as such is virtually useless on the Web.
Quote:
When you use HTML you can use the <pre> tag. |
That's preformatted text. It does not have anything particular to do with
"code" or with CDATA. It just means that whitespace is preserved.
For some values of "work" and "fine", yes.
Quote:
I think <code> makes just the font style. |
The <code> markup indicates that the content is computer code. It does not
override normal HTML or XML rules for "<" or "&" in any way. On graphic
browsers, the content is typically rendered in a monospace font by default,
but that's coincidental.
Quote:
But when I use <script language="[...] in the <pre> section
and when I don't change <table> into <table> and so on
(well, I forgot at the moment what exactly prevents the browser
to use the code as usual) the <pre> tag becomes useless. |
The description is confused but sufficient for indicating that you expected
<pre> to have a meaning different from its defined meaning. It is indeed
useless or worse then.
Quote:
Is there a stronger tag than the <pre> tag to present code? |
The robust approach is to "escape" the characters "&" and "<" as required by
HTML rules. It's easy, and if you need to do it often, you can surely create
a macro or a program for the purpose, if you are qualified enough to give
advice to others in matters of programming.
But since you asked, there's a "stronger" tag, still supported by browsers,
<xmp>, though it has been deprecated since its origin, through millennia.,
and isn't even part of any comtemporary HTML specification.
--
Yucca, http://www.cs.tut.fi/~jkorpela/