# Root element is missing

Source: https://xmlvalid.com/errors/root-element-is-missing

> The input has no element at all.

The message, as .NET reports it: `Root element is missing.`

## Why it happens

- An empty file, string or response.
- A `Stream` whose position is at its end: written to a `MemoryStream` and read back without `Position = 0`.

## How to fix it

- Check the length of the input; for a stream you have just written, set `stream.Position = 0` before loading it.
- .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 [Document is empty](https://xmlvalid.com/errors/document-is-empty): `Document is empty`

## Example that fails

```xml

```

## Fixed

```xml
<note/>
```
