& in XHTML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Randy Webb

    & 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=(docum ent.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.javas cript FAQ - http://jibbering.com/faq/

  • Bertilo Wennergren

    #2
    Re: &amp; 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=(docum ent.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.n et> <http://www.bertilow.co m>

    Comment

    • Steve Pugh

      #3
      Re: &amp; 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; &#60; &#62; &#x3c; &#x3e;
      [color=blue]
      >The lines are lines of script code that look something like this:
      >
      >this.ie4=(docu ment.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/>

      Comment

      • Randy Webb

        #4
        Re: &amp; 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=(doc ument.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


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

        Comment

        • Andrew Urquhart

          #5
          Re: &amp; in XHTML

          "Randy Webb" <hikksnotathome @aol.com> wrote in message
          news:69WdnX8xEK 5Rd6DdRVn-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.HTMLEnco de (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: https://www.andrewu.co.uk/about/cont...ct=Re%3A+ciwah


          Comment

          Working...