Search This Blog

Wednesday, July 08, 2009

"EntityRef: expecting ';' at line 1": XML Error SOLVED


"EntityRef: expecting ';' at line 1"

I was using the Uber Uploader script for a project, and ran into the error above in the Firebug console. In my case, I had been passing a URL with a query string that needed to have HTML entities for the ampersands.

In other words, the following URL:
http://somesite.com/file.php?c=1&d=2&e=3
was creating an error in the XML file. The ampersands had to be encoded, which solved the error:
http://somesite.com/file.php?c=1&d=2&e=3
Wikipedia has a list of all the characters that must be encoded when using XML. I list them below with the symbol followed by the HTML entity you will need to use to replace it with. If you are receiving the same error (or the error "Reserved XML Name"), you most likely need to make sure that these symbols are encoded (and with the latter error, watch out for deadly white space and newline characters).
Symbol:HTML Entity:Description:
""(double) quotation mark
&&ampersand
'' or "apostrophe (= apostrophe-quote)
<&lt;less-than sign
> &gt;greater-than sign

Note that if you are using PHP, htmlspecialchars and htmlspecialchars_decode should give you everything you need for XML; for JavaScript, you'll want a custom solution such as this one.

10 comments:

  1. Wow, it took me so long to get this figured out. Thank you for sharing, this helps me out so much!

    ReplyDelete
  2. vapor4less.com/index.php?route=feed/google_sitemap
    Plz help

    ReplyDelete
  3. Don't know how your site feed setup works, so will only be of limited help.

    First, here's the error you're getting for everyone else to view:

    This page contains the following errors:

    error on line 1 at column 2396: EntityRef: expecting ';'
    Below is a rendering of the page up to the first error.

    Your error only means one thing: the XML interpreter has encountered invalid syntax for one of these five symbols: ", &, ', <, or >.

    In your case, the "&"s in your URLs are primary suspects., beginning at column 2396 where the error occurred.

    ReplyDelete
  4. Thank you! It's valid now!

    ReplyDelete
  5. What if it says
    This page contains the following errors:
    error on line 61 at column 187: EntityRef: expecting ';'
    Below is a rendering of the page up to the first error.
    ??

    ReplyDelete
  6. Thanks. Great Help. :)

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. How to remove remove entity error in hyper link Part Time jobs in Tamilnadu

    ReplyDelete