The processing instruction target matching "[xX][mM][lL]" is not allowed
An XML declaration (<?xml …?>) appears somewhere other than the very start.
The processing instruction target matching "[xX][mM][lL]" is not allowed.
Why it happens
- Whitespace or a blank line before
<?xml, often from a template, a script that prints a newline first, or a string built with a leading line break. - Two documents concatenated, so the second declaration lands in the middle.
- A byte order mark or other bytes before the declaration that the reader passed on as text.
How to fix it
Make <?xml the first characters of the input: trim the string before parsing, or remove the second declaration when documents are combined.
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 XML declaration allowed only at the start of the document. It checks the whole document in your browser and lists every schema error with its line and column, not only the first.
XML declaration allowed only at the start of the document
Example
<?xml version="1.0"?>
<note/>
<?xml version="1.0"?>
<note/>