XML error · InvalidTag
Closing tag has not been opened
An end tag appeared with no matching start tag anywhere above it.
Closing tag 'url' has not been opened.What it means
The parser met a closing tag for an element that is not open. Usually the document is a fragment — the opening tags live in another file or another chunk of a stream — or a de-duplication step removed an opening tag and left its close behind.
It is also what you get from splitting a large XML file on line boundaries: each piece after the first begins mid-tree.
What usually causes it
- The input is a fragment, not a whole document.
- A file was split by size or line count rather than at element boundaries.
- A find-and-replace removed an opening tag but not its closing tag.
- Two documents were concatenated and the first was already truncated.
How to fix it
- Wrap a fragment in a single synthetic root element before parsing.
- Split large XML on element boundaries, never on lines or bytes.
- Check whether the first line of the file is where the real document starts.
The same error elsewhere
Different parsers, same defect. If you arrived with one of these messages, you are in the right place.
libxml2 (PHP, lxml, Nokogiri)
Extra content at the end of the documentXerces (Java)
Content is not allowed in prolog.expat (Python)
not well-formed (invalid token): line 1, column 4
Before and after
Both snippets are checked on every build: the first is confirmed to produce the error above, the second to parse cleanly.
<loc>https://example.com/</loc>
</url>
</urlset><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://example.com/</loc>
</url>
</urlset>Where this bites most
Other XML errors
- Expected closing tag
- Unclosed tag
- Character is not expected
- Start tag expected
- XML declaration allowed only at the start of the document
- Attribute is without value (unquoted attribute value)
- Attribute is repeated
- Attributes have open quote
- Tag is an invalid name
- Invalid tags found (open elements at end of input)
Get started
Bring order to the XML your team can't afford to ignore.
Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.