SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Sep 2008
    Location
    Rudgwick, UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to stop w3 Complaining?

    Hi,

    I'm trying to get my pages to "validate", but keep getting annoying errors like:

    Line 116, Column 66: cannot generate system identifier for general entity "BID"

    …ateshop.com/public/AIDLink?AID=107078&BID=13266" target="_blank">Mexico Golf P…

    An entity reference was found in the document, but there is no reference by that name defined. Often this is caused by misspelling the reference name, unencoded ampersands, or by leaving off the trailing semicolon (. The most common cause of this error is unencoded ampersands in URLs as described by the WDG in "Ampersands in URLs".

    Entity references start with an ampersand (&) and end with a semicolon (. If you want to use a literal ampersand in your document you must encode it as "&" (even inside URLs!). Be careful to end entity references with a semicolon or your entity reference may get interpreted in connection with the following text. Also keep in mind that named entity references are case-sensitive; &Aelig; and æ are different characters.

    If this error appears in some markup generated by PHP's session handling code, this article has explanations and solutions to your problem.

    Note that in most documents, errors related to entity references will trigger up to 5 separate messages from the Validator. Usually these will all disappear when the original problem is fixed.
    ..with this line:

    Code:
    <a href="http://edge.affiliateshop.com/public/AIDLink?AID=107078&BID=13266" target="_blank">Mexico Golf Passport.com</a> <br />
    Is the ONLY way to fix this, to change & with &amp; in ALL my URLs??

    Also getting the same problem with some Javascript, which is getting annoying:

    Line 67, Column 149: character "&" is the first character of a delimiter but occurred as data

    …nel(title,url,"")}else if(window.opera&&window.print){var elem=document.create…



    This message may appear in several cases:

    You tried to include the "<" character in your page: you should escape it as "&lt;"
    You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&amp;", which is always safe.
    Another possibility is that you forgot to close quotes in a previous tag.
    ..which is related to this code:

    Code:
    function bookmark_us(){var url=this.location;var title=document.title;if(window.sidebar){window.sidebar.addPanel(title,url,"")}else if(window.opera&&window.print){var elem=document.createElement('a');elem.setAttribute('href',url);elem.setAttribute('title',title);elem.setAttribute('rel','sidebar');elem.click()}else if(document.all){window.external.AddFavorite(url,title)}}
    Is there a simpler way to fix these up? (its showing over 600 "errors" just on one page atm - and all of them seem to be related to this "issue" !)

    BTW, the page doctype is set as:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    TIA

    Andy

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,870
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    An & needs to be codes as &amp; when you include it in HTML. It is one of the two characters in HTML that have special meanings - the other being < (which you would write as &lt; if you want it in your content)
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Addict
    Join Date
    Sep 2008
    Location
    Rudgwick, UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for the reply - but why does it also moan about stuff like:

    Code:
    if (var == "something" && foo = "bar") {
    
    }
    (in Javascript)

    Surely it must just "ignore" JS codes? (cos you have > < & etc in the basic javascript syntax - which you obviously can't encode )

    TIA

    Andy

  4. #4
    Sploghm bronze trophy Victorinox's Avatar
    Join Date
    Nov 2008
    Posts
    749
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Use CDATA to indicate that the code is not to be parsed as html.

    Code JavaScript:
    //<![CDATA[
    	if (var == "something" && foo = "bar") {
    }
    //]]>

  5. #5
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    Alternately use externally linked scripts. Though like was mentioned above Script is non HTML data. Therefore needs to be treated carefully so that the HTML parser doesn't interpret the certain characters or sequences like; && or -- that are legal in JS. As HTML markup, or start mistaking & as start of a character entity reference, etc.

  6. #6
    SitePoint Addict
    Join Date
    Sep 2008
    Location
    Rudgwick, UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Victorinox View Post
    Use CDATA to indicate that the code is not to be parsed as html.

    Code JavaScript:
    //<![CDATA[
    	if (var == "something" && foo = "bar") {
    }
    //]]>
    You legend - works a charm

    xhtmlcoder - thanks for the reply. For the most of our JS, we DO have them in a seperate .js file.. but for some functions (which are only used on a small number of pages), we have them included directly into the HTML - cos having a seperate .js file for them would increase the page load-time (as it would have to make another 1, or 2 seperate requests to get the file)

    Thanks!

    Andy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •