# There are multiple root elements

Source: https://xmlvalid.com/errors/there-are-multiple-root-elements

> More than one element at the top level: an XML document has exactly one root.

The message, as .NET reports it: `There are multiple root elements. Line 2, position 2.`

## Why it happens

- Several documents or records concatenated without a wrapping element.
- An end tag for the root that comes too early.

## How to fix it

- Wrap the elements in one root element. To read a stream of fragments on purpose, set `XmlReaderSettings.ConformanceLevel = ConformanceLevel.Fragment`.
- .NET throws an `XmlSchemaValidationException` at the first schema error unless `XmlReaderSettings.ValidationEventHandler` is set, which then receives every one with its line and position. A well-formedness error is an `XmlException` and ends reading whatever the settings.

## 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>
```
