XML error · syntax
Double hyphen within comment
XML forbids -- inside a comment's body, even when the comment is otherwise closed properly. It is one of the specification's genuinely surprising rules.
Double hyphen within comment: <!-- a (line 2)What it means
A comment runs from <!-- to the first -->. To keep that unambiguous, the specification bans the sequence -- anywhere inside, so a comment cannot contain a double hyphen even far from its end.
This catches people out because HTML tolerates it and because -- reads as a natural separator. libxml2 quotes the start of the offending comment back to you, which is how you find it in a long file.
What usually causes it
- Using -- as a visual rule or separator inside a comment block.
- Commenting out a region that already contained a comment, leaving its -- behind.
- A commented-out command line or diff that legitimately contains --flag or ---.
- Auto-generated comment banners drawn with hyphens.
How to fix it
- Replace -- with a single hyphen, an em dash, or =.
- Split one comment into two rather than nesting them; XML comments do not nest.
- Move long commented-out material out of the document entirely — into source control, where it belongs.
The same error elsewhere
Different parsers, same defect. If you arrived with one of these messages, you are in the right place.
Xerces (Java)
The string "--" is not permitted within comments.expat (Python)
not well-formed (invalid token): line 2, column 12.NET System.Xml
An XML comment cannot contain '--', and '-' cannot be the last character.
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><!-- a -- b --></root><?xml version="1.0"?>
<root><!-- a - b --></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
- Comment not terminated
- 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
- 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.