XML error · syntax
Comment not terminated
A comment was opened with <!-- and never closed, so the rest of the file is swallowed as comment text and the reported line is the end, not the fault.
Comment not terminated (line 3)What it means
Once the parser sees <!-- it consumes everything until -->. If that never arrives, the rest of the document — including its closing tags — disappears into the comment and the parser reaches the end still inside it.
The line number therefore points at the end of the document rather than at the unclosed comment. Search backwards from it for the last <!-- that has no matching -->.
What usually causes it
- A typo in the terminator: --> written as --> with a missing angle bracket, or as -- >.
- A double hyphen inside the comment body, which XML forbids and some editors silently produce.
- Commenting out a block that itself contained a comment — XML comments do not nest.
- A template that emits a comment opener conditionally but its closer unconditionally, or the reverse.
How to fix it
- Find the last unmatched <!-- and close it with exactly -->.
- Remove any -- inside the comment text; XML does not allow it even in a well-formed comment.
- Never comment out a region that already contains a comment — delete the block instead.
- Fold long commented-out blocks behind a build flag rather than shipping them in the document.
The same error elsewhere
Different parsers, same defect. If you arrived with one of these messages, you are in the right place.
Xerces (Java)
XML document structures must start and end within the same entity.expat (Python)
unclosed token: line 2, column 6.NET System.Xml
Unexpected end of file while parsing Comment has occurred.
Before and after
Both snippets are re-checked by the test suite against the real parser: the first is confirmed to produce the exact error above, the second to parse cleanly.
<?xml version="1.0"?>
<root><!-- note
</root><?xml version="1.0"?>
<root><!-- note -->
</root>Where this bites most
Other XML errors
- Opening and ending tag mismatch
- Premature end of data in tag
- Extra content at the end of the document
- Unescaped ampersand (EntityRef: expecting ';')
- Entity is not defined
- Start tag expected
- XML declaration allowed only at the start of the document
- Unquoted attribute value (AttValue expected)
- Attribute redefined
- Attributes construct error (unterminated quote)
- Invalid element name
- Document is empty
- Unsupported encoding
- Sequence ']]>' not allowed in content
- Detected an entity reference loop
- PCDATA invalid Char value (control character)
- Unescaped '<' in an attribute value
- Invalid numeric character reference
- Blank needed here
- Malformed declaration expecting version
- Unsupported XML version
- Processing instruction not terminated
- CData section not finished
- Error parsing attribute name
- Double hyphen within comment
- CharRef: invalid decimal value
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.