What the error means
XML is strict about structure in a way HTML is not: every element that is opened must be closed, either with a matching end tag (<server>...</server>) or by self-closing the start tag (<server/>). Unclosed tag means the parser reached the end of an enclosing element, or the end of the document, with at least one start tag still waiting for its end tag.
In the example, <server host="db.internal"> is never closed. The parser reads <timeout>30</timeout> as a child of server, then meets </config> while server is still open. Depending on the parser, the error is reported either at </config> or at the end of the file, and it names the element that was left open.
Why it happens
- HTML habits. Elements like
<br>,<img>, and<input>need no closing tag in HTML. In XML they do, or they must be written<br/>. - An attribute-only element written like an opening tag. The author meant
<server host="db.internal"/>— an empty element with attributes — and dropped the slash. - A deleted line. Removing an element's content by hand and taking its end tag with it.
- Generated XML where a template writes the start tag in one branch and the end tag in another, and the branches disagree.
How to fix it
- Paste the document into the formatter above. The error card names the unclosed element and gives a line number.
- Find that element's start tag. If it was meant to contain the elements that follow, add
</server>after its last child. If it was meant to be empty, change the start tag to end with/>. - Format again. The indented output makes the nesting visible, so a child that ended up inside the wrong parent is obvious.
Two valid corrections of the example, depending on intent:
<config>
<server host="db.internal"/>
<timeout>30</timeout>
</config>
<config>
<server host="db.internal">
<timeout>30</timeout>
</server>
</config>
If it still fails
- If the element name in the message is not one you recognise, look for a stray
<in text content —if a < binside an element starts a tag that never closes. Write it as<or wrap the text in<![CDATA[ ... ]]>. - XML Validator reports the same failure with an error code and an excerpt, which helps when the document is large and the formatter's first error is far from the cause.
- A document that ends in the middle of a start tag (
<server host="db) is truncated rather than unclosed; recover it from the source.
Related errors
Mismatched closing tag
Close elements in the reverse order they were opened, and make the closing name match the opening name exactly, including case.
XML declaration after content
Move the <?xml ?> declaration to the first byte of the document, remove anything before it (including a byte-order mark), and keep only one declaration per file.