XML error · entity
Unescaped ampersand (EntityRef: expecting ';')
A bare & appeared in content. XML reads it as the start of an entity reference and expects a name and a semicolon.
EntityRef: expecting ';' (line 2)What it means
The ampersand is the character that breaks real documents. XML treats & as the opening of an entity reference, so it must be written & whenever it means a literal ampersand.
This is the single most common failure in generated sitemaps and feeds, because URLs with query strings contain ampersands and string interpolation does not escape them. URL-encoding does not help: %26 is for URLs, & is for XML, and a URL inside XML needs both layers respected.
What usually causes it
- An unescaped & in a URL query string: ?a=1&b=2 instead of ?a=1&b=2.
- Company names and titles containing & written literally.
- HTML built by string concatenation and dropped into a feed without escaping.
- Double-escaping fixes applied on top of already-escaped output, then partially reverted.
How to fix it
- Escape the five predefined entities: & < > " '.
- Escape URLs when writing them into XML, even though they are already URL-encoded.
- Wrap HTML bodies in CDATA rather than escaping them character by character.
- Build XML with a serializer; every one of them escapes content for you.
The same error elsewhere
Different parsers, same defect. If you arrived with one of these messages, you are in the right place.
libxml2 (bare & with no name)
xmlParseEntityRef: no nameXerces (Java)
The reference to entity "page" must end with the ';' delimiter.expat (Python)
not well-formed (invalid token): line 2, column 40.NET System.Xml
An error occurred while parsing EntityName.
Before and after
Both snippets are re-checked by the test suite against the real parser: the first is confirmed to produce the exact error above, the second to parse cleanly.
<url>
<loc>https://example.com/search?q=xml&page=2</loc>
</url><url>
<loc>https://example.com/search?q=xml&page=2</loc>
</url>Where this bites most
Other XML errors
- Opening and ending tag mismatch
- Premature end of data in tag
- Extra content at the end of the document
- Entity is not defined
- Start tag expected
- XML declaration allowed only at the start of the document
- Unquoted attribute value (AttValue expected)
- Attribute redefined
- Attributes construct error (unterminated quote)
- Invalid element name
- Document is empty
- Unsupported encoding
- Sequence ']]>' not allowed in content
- Comment not terminated
- Detected an entity reference loop
- PCDATA invalid Char value (control character)
- Unescaped '<' in an attribute value
- Invalid numeric character reference
- Blank needed here
- Malformed declaration expecting version
- Unsupported XML version
- Processing instruction not terminated
- CData section not finished
- Error parsing attribute name
- Double hyphen within comment
- CharRef: invalid decimal value
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.