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:
was creating an error in the XML file. The ampersands had to be encoded, which solved the error:
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
'' 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.