The entity name must immediately follow the '&' in the entity reference
A bare ampersand (&) in text or in an attribute.
The entity name must immediately follow the '&' in the entity reference.
Why it happens
- An unescaped
&in text, such as a company name (Smith & Sons) or a URL query string. - XML built by string concatenation instead of an XML writer, which would escape it.
How to fix it
Write & for every literal ampersand, or put the text in a CDATA section. Build XML with an XML API (DOM, StAX, JAXB) and the escaping is done for you.
Java's schema validation (javax.xml.validation.Validator, and JAXB or Spring on top of it) throws at the first error unless you set an ErrorHandler whose error() records the SAXParseException and carries on; each one has getLineNumber() and getColumnNumber(). A well-formedness error ends parsing whatever the handler does.
The same problem in xmlvalid
xmlvalid validates with libxml2, which reports it as xmlParseEntityRef: no name. It checks the whole document in your browser and lists every schema error with its line and column, not only the first.
xmlParseEntityRef: no name
Example
<company>Smith & Sons</company>
<company>Smith & Sons</company>