Expecting an element, got nothing

A required element is missing at the end of its parent.

The message, as the validator reports it
Expecting an element , got nothing

Why it happens

  • The last required child is not there.

How to fix it

Look at what the schema requires after the element's last child and add it. libxml2 does not always print the expected name, so compare with the schema.

Example

Validated against book.rng, below.

Reports the error
<book isbn="1">
  <title>T</title>
</book>
Fixed
<book isbn="1">
  <title>T</title>
  <year>2020</year>
</book>
book.rng
<element name="book" xmlns="http://relaxng.org/ns/structure/1.0"
         datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  <attribute name="isbn"><data type="string"/></attribute>
  <element name="title"><text/></element>
  <element name="year"><data type="gYear"/></element>
</element>