Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 06:50 PM
Randy Webb
Guest
 
Posts: n/a
Default & in XHTML

In trying to validate a document as XHTML Strict, and using < and
&gt; to display < and >, I get this message from the validator:

character "&" is the first character of a delimiter but occurred as data

1) What exactly does that mean?
2) How can I display < and > without using < and > and not get the
messages from the validator? It still validates, but I would like for it
not to have those "warnings" (Not sure thats the right term).

The lines are lines of script code that look something like this:

this.ie4=(document.all && !this.dom && !this.opera5)?1:0;<br />

And its the && that is causing the problems. :-(

Thanks in advance.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

  #2  
Old July 20th, 2005, 06:50 PM
Bertilo Wennergren
Guest
 
Posts: n/a
Default Re: & in XHTML

Randy Webb:
[color=blue]
> In trying to validate a document as XHTML Strict, and using &lt; and
> &gt; to display < and >, I get this message from the validator:[/color]
[color=blue]
> character "&" is the first character of a delimiter but occurred as data[/color]
[color=blue]
> The lines are lines of script code that look something like this:[/color]
[color=blue]
> this.ie4=(document.all && !this.dom && !this.opera5)?1:0;<br />[/color]
[color=blue]
> And its the && that is causing the problems. :-([/color]

You're using "&" (in "&&") inside your script. The script is part of a
HTML page, and (as always) "&" has to be written as "&amp;".

It's always better to put script in external js files. Then you can
write like you did.

(I kind of wonder about the "<br />" at the end of the line...)

--
Bertilo Wennergren <bertilow@gmx.net> <http://www.bertilow.com>
  #3  
Old July 20th, 2005, 06:50 PM
Steve Pugh
Guest
 
Posts: n/a
Default Re: & in XHTML

Randy Webb <hikksnotathome@aol.com> wrote:
[color=blue]
>In trying to validate a document as XHTML Strict, and using &lt; and
>&gt; to display < and >, I get this message from the validator:
>
>character "&" is the first character of a delimiter but occurred as data[/color]

Are yiu sure you're getting that message in relation to &gt; or &lt;?
They both validate under XHTML 1.0 Strict.
[color=blue]
>1) What exactly does that mean?[/color]

The code contains an & that is not the start of a recognised entity.
[color=blue]
>2) How can I display < and > without using < and > and not get the
>messages from the validator?[/color]

&lt; &gt; < > &#x3c; &#x3e;
[color=blue]
>The lines are lines of script code that look something like this:
>
>this.ie4=(document.all && !this.dom && !this.opera5)?1:0;<br />
>
>And its the && that is causing the problems. :-([/color]

So nothing to do with &gt; or &lt; after all?

Move the JavaScript to an external .js file. XHTML has different rules
on embedding scripts and whilst in theory you can mark the script
content as CDATA it's usually easier to just put it all in an external
file.

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <steve@pugh.net> <http://steve.pugh.net/>
  #4  
Old July 20th, 2005, 06:50 PM
Randy Webb
Guest
 
Posts: n/a
Default Re: & in XHTML

Bertilo Wennergren wrote:[color=blue]
> Randy Webb:
>
>[color=green]
>>In trying to validate a document as XHTML Strict, and using &lt; and
>>&gt; to display < and >, I get this message from the validator:[/color]
>
>[color=green]
>>character "&" is the first character of a delimiter but occurred as data[/color]
>
>[color=green]
>>The lines are lines of script code that look something like this:[/color]
>
>[color=green]
>>this.ie4=(document.all && !this.dom && !this.opera5)?1:0;<br />[/color]
>
>[color=green]
>>And its the && that is causing the problems. :-([/color]
>
>
> You're using "&" (in "&&") inside your script. The script is part of a
> HTML page, and (as always) "&" has to be written as "&amp;".[/color]

Thank you. I feel really stupid now. I should have known that :-(
[color=blue]
> It's always better to put script in external js files. Then you can
> write like you did.
> (I kind of wonder about the "<br />" at the end of the line...)[/color]

The script is to be displayed on the page, for commenting, not executing
.. So, the <br /> was to maintain my line breaks. I considered a pre or
code block (something to keep my line breaks) but in the end I just used
div tags and <br /> tags to maintain structure and to allow me to color
the components. Its not finished but you can see it at
http://www.hikksworld.com/critique/page2.html

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

  #5  
Old July 20th, 2005, 06:50 PM
Andrew Urquhart
Guest
 
Posts: n/a
Default Re: & in XHTML

"Randy Webb" <hikksnotathome@aol.com> wrote in message
news:69WdnX8xEK5Rd6DdRVn-jA@comcast.com...
<snip />[color=blue]
> The script is to be displayed on the page, for commenting, not[/color]
executing[color=blue]
> . So, the <br /> was to maintain my line breaks. I considered a pre or
> code block (something to keep my line breaks) but in the end I just[/color]
used[color=blue]
> div tags and <br /> tags to maintain structure and to allow me to[/color]
color[color=blue]
> the components. Its not finished but you can see it at
> http://www.hikksworld.com/critique/page2.html[/color]

This is important info that is missing from the original post, if you're
displaying the raw script and not executing it then run it through ASPs
Server.HTMLEncode (or equivalent), or at least convert all <, > and &
into their entity equivalents:

indexOf("MSIE 6")>-1 && this.dom

vs.

indexOf("MSIE 6")&gt;-1 &amp;&amp; this.dom
--
Andrew Urquhart
Reply: http://www.andrewu.co.uk/about/conta...ct=Re%3A+ciwah


 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles