Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > javascript in xhtml files: avoid errors with characters > < & ' " ??

Reply
Thread Tools

javascript in xhtml files: avoid errors with characters > < & ' " ??

 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      01-08-2008
David Dorward wrote:
> On Jan 8, 11:41 am, "mark4asp" <(E-Mail Removed)> wrote:
>> What is the best way to avoid errors with characters > < & " ' using
>> javascript in xhtml files?
>>
>> Does it depent upon the type of xhtml?

>
> Not really.


Yes, it does.

>> So for each of xhtml 1.0 transitional, xhtml 1.0 strict, xhtml 1.1
>> strict. How should I tell the browser that the special xml characters>
>> < & " ' (for which xml mandates the use of entity values when they
>>
>> appear as values) are to treated literally?

>
> For XHTML 1.0 served as text/html, the spec says:
>
> Use external style sheets if your style sheet uses < or & or ]]> or --.


Quotations from third-party resources (that are not source code) should be
marked with more than an indentation. It is common to use a leading `|'
character or to use single or double quotes.

> This may or may not be a requirement as the spec is badly written.


It is not a requirement as that would be indicated by the verb `MUST'
(which may be written in capital letters).

> Postal's Law says to treat it as a requirement if you are authoring
> XHTML.


Whatever that is, it does not apply here.

>> For instance is this (below) correct for all of xhtml 1.0 transitional,
>> xhtml 1.0 strict, xhtml 1.1 strict, or is it correct for only some of
>> them? [...]
>> <script type="text/javascript"> // <![CDATA[
>>
>> var x = (z>0 && z<10) ? "blah" : "blah blah"
>>
>> // ]]> </script>

>
> The JavaScript comments there are pointless and a waste of bytes, but
> that is otherwise fine for any type of XHTML that is not served as
> text/html.


Whereas the latter would apply to XHTML 1.0 that is not written (seemingly)
HTML-compatible according to XHTML 1.0 Appendix C and to XHTML 1.1 (Basic);
those SHOULD NOT be served as text/html:

http://www.w3.org/TR/xhtml-media-types/#summary

So they are _not_ pointless at all.

> You could also use &amp; et al, but that reduces readability.


True.

>> When I use an external javascript file:
>> <script type="text/javascript"
>> src="js/browser.js"></script>, presumably I can dispense with the
>> <![CDATA[ ... ]]> ?

>
> More than that, you must dispense with it. It is meaningless in JS.


To be precise, it actually *means* a syntax error there.


Your signature delimiter is broken which is because of a bug in Google
Groups; I suggest not to use your usual signature when using GG.


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      01-08-2008
VK wrote:
> On Jan 8, 2:41 pm, "mark4asp" <(E-Mail Removed)> wrote:
>> What is the best way to avoid errors with characters > < & " ' using
>> javascript in xhtml files?

>
> Besides other helpful responses you may look at my post of 2006:
>
> http://groups.google.com/group/comp....c6c90a43d9910f


As your posting is merely displaying your own misconceptions about the
matter, your posting would not be helpful at all but deepen the OPs
confusion about the matter instead. Please leave those postings disproved
and buried in old threads where they belong.


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
 
Reply With Quote
 
 
 
 
David Dorward
Guest
Posts: n/a
 
      01-09-2008
On Jan 8, 8:02*pm, David Mark <(E-Mail Removed)> wrote:

> > (IE 6 nor 7 recognize xhtml, rendering it as malformed html anyways


As will any other browser when the XHTML is served as text/html

> > and will revert to operating in Quirks mode.)


> They revert to quirks mode only if the optional XML preamble is used.


IE6 will. IE7 can go into standards mode when an XML prolog is
present.

--
David Dorward
http://dorward.me.uk/
http://blog.dorward.me.uk/
 
Reply With Quote
 
David Dorward
Guest
Posts: n/a
 
      01-09-2008
On Jan 8, 10:26*pm, Thomas 'PointedEars' Lahn <(E-Mail Removed)>
wrote:
>>> Does it depent upon the type of xhtml?


>> Not really.


> Yes, it does.


Not in the sense that the OP appeared to be using the term "type",
although it does in other senses.

> > Postal's Law says to treat it as a requirement if you are authoring
> > XHTML.

>
> Whatever that is, it does not apply here.


Postel's Law (I misspelt the name the first time around) is the
Robustness Principle.

"Be conservative in what you do; be liberal in what you accept from
others."

In this case, "If you are writing a user agent, have it cope with the
more liberal interpretation of the specification, if you are writing
XHTML, have it conform to the more conservative interpretation".

When you hit specs which only bless Appendix C conformant markup to be
served as text/html while Appendix C is an *informative* section of
the spec, you are running into very wooly territory and Postel's Law
is the best stick we have if we're forced to deal with those specs.

> >> For instance is this (below) correct for all of xhtml 1.0 transitional,
> >> *xhtml 1.0 strict, xhtml 1.1 strict, or is it correct for only some of
> >> them? [...]
> >> <script type="text/javascript"> // <![CDATA[

>
> >> var x = (z>0 && z<10) ? "blah" : "blah blah"

>
> >> // ]]> </script>

>
> > The JavaScript comments there are pointless and a waste of bytes, but
> > that is otherwise fine for any type of XHTML that is not served as
> > text/html.

>
> Whereas the latter


What is the latter in this case? I can't see distinct entities there.

If the XHTML conforms to Appendix C, then there will be no characters
that require the presence of CDATA markers.

If the XHTML doesn't conform to Appendix C, then tag soup slurpers
shouldn't be presented with the code, so they won't pass the contents
of the script block (CDATA markers and all) to the JavaScript
interpreter. (So the CDATA markers don't need JS comments to hide them
from said interpreter).

The comments are pointless in both cases.

--
David Dorward
http://dorward.me.uk/
http://blog.dorward.me.uk/
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      01-09-2008
David Dorward wrote:
> [...] Thomas 'PointedEars' Lahn [...] wrote:
>>>> Does it depent upon the type of xhtml?

>
>>> Not really.

>
>> Yes, it does.

>
> Not in the sense that the OP appeared to be using the term "type", [...]


Yes, it does, because there is a strong recommendation in favor and against
serving the markup with a certain MIME media type that depends on what the
OP apparently understood as "type":

| Does it depent upon the type of xhtml?
|
| So for each of xhtml 1.0 transitional, xhtml 1.0 strict, xhtml 1.1
| strict. [...]

And that media type plays an important part in defining the parser that is
eventually used to parse the markup.

> [Postel's Law]


(May he R.I.P.)

> When you hit specs which only bless Appendix C conformant markup to be
> served as text/html while Appendix C is an *informative* section of
> the spec, you are running into very wooly territory and Postel's Law
> is the best stick we have if we're forced to deal with those specs.


The point you are raising is generally a good one (in fact, it is exactly
one of mine on other occasions), but it does not apply here. Yes, Appendix
C *is* informative, but that does not matter: iff XHTML is used, it does
exactly *no* harm to add those four to six bytes, and it will do some good.

So I really don't see why you would recommend against the script-commented
declaration, in favor of an additional script resource and therefore an
additional request when that would not be *necessary*.

>>>> For instance is this (below) correct for all of xhtml 1.0 transitional,
>>>> xhtml 1.0 strict, xhtml 1.1 strict, or is it correct for only some of
>>>> them? [...]
>>>> <script type="text/javascript"> // <![CDATA[
>>>> var x = (z>0 && z<10) ? "blah" : "blah blah"
>>>> // ]]> </script>
>>> The JavaScript comments there are pointless and a waste of bytes, but
>>> that is otherwise fine for any type of XHTML that is not served as
>>> text/html.

>> Whereas the latter

>
> What is the latter in this case? I can't see distinct entities there.


Any "type" of XHTML that is not served as text/html.

> If the XHTML conforms to Appendix C, then there will be no characters
> that require the presence of CDATA markers.
>
> If the XHTML doesn't conform to Appendix C, then tag soup slurpers
> shouldn't be presented with the code, so they won't pass the contents
> of the script block (CDATA markers and all) to the JavaScript
> interpreter. (So the CDATA markers don't need JS comments to hide them
> from said interpreter).
>
> The comments are pointless in both cases.


Yes, but Appendix C does not enter into it. Unfortunately, the W3C made it
no *requirement* to serve XHTML, "HTML-compatible" or not, with the proper
media type; it is not even forbidden to serve XHTML Basic/1.1 as text/html,
there is only a strong recommendation against it ("SHOULD NOT"). It is not
conformance or non-conformance to XHTML 1.0 Appendix C that determines which
parser is used, but the Content-Type header, and in some cases even the
resource name suffix.


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Should I Convert Site To XHTML or XHTML mobile? chronos3d HTML 9 12-05-2006 04:46 PM
Avoid having a SQL express for web parts and avoid personalization Roger23 ASP .Net 2 10-12-2006 10:54 PM
parse URL (href) from xhtml, xhtml -> text, for data hawat.thufir@gmail.com XML 7 02-08-2006 07:39 PM
Avoid wasting time or how to avoid initialization Alexander Malkis C++ 8 04-13-2004 11:23 PM
Errors, errors, errors Mark Goldin ASP .Net 2 01-17-2004 08:05 PM



Advertisments