# XML declaration allowed only at the start of the document

Source: https://xmlvalid.com/errors/xml-declaration-allowed-only-at-the-start

> Something comes before …?, or there are two declarations.

Example message: `XML declaration allowed only at the start of the document`

## Why it happens

- An empty line or spaces before `<?xml`, often printed by a PHP file or a template before the output starts.
- Two documents joined into one file, each with its own declaration.

## How to fix it

- Make `<?xml version="1.0"?>` the very first characters of the file, with nothing before it, not even a newline. Remove a second declaration.

## Example that fails

```xml

<?xml version="1.0"?>
<note/>
```

## Fixed

```xml
<?xml version="1.0"?>
<note/>
```
