# The markup in the document following the root element must be well-formed

Source: https://xmlvalid.com/errors/markup-following-the-root-element-must-be-well-formed

> Something follows the root element: an XML document has exactly one.

The message, as Java reports it: `The markup in the document following the root element must be well-formed.`

## Why it happens

- Two root elements: several documents concatenated, or a list of records without a wrapper.
- An end tag for the root that comes too early, so what follows is outside it.
- Data appended to a file that was already complete, such as a log of XML messages.

## How to fix it

- Wrap the elements in one root element, or parse each document separately. Comments and processing instructions may follow the root; elements and text may not.
- 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

libxml2, which xmlvalid validates with, reports it as [Extra content at the end of the document](https://xmlvalid.com/errors/extra-content-at-the-end-of-the-document): `Extra content at the end of the document`

## Example that fails

```xml
<note/>
<note/>
```

## Fixed

```xml
<notes>
  <note/>
  <note/>
</notes>
```
