Skip to main content

XML Parsing Error: not well-formed

Paste your XML and click Validate to find the line and column where it breaks

14
Loading editor…

What the error means

Unlike HTML, XML is parsed strictly: a single violation stops the parser, and the browser then shows the error instead of the page. "Not well-formed" means the document breaks a basic syntax rule, such as an unescaped & or a tag that is not closed. It does not mean the content is wrong for an application; that is a separate check against a schema.

The editor above opens on XML with an unescaped ampersand, the most common cause. Click Validate to see the position it reports.

Causes and fixes

The messages are what Chrome reports for each example.

Unescaped ampersand

Error: error on line 1 at column 13: xmlParseEntityRef: no name

Invalid

<title>Tom & Jerry</title>

Fixed

<title>Tom &amp; Jerry</title>

A bare & starts an entity reference, so the parser expects a name after it. Write & as &amp; and < as &lt; in text and attribute values.

HTML entity such as &nbsp;

Error: error on line 1 at column 10: Entity 'nbsp' not defined

Invalid

<a>Hello&nbsp;world</a>

Fixed

<a>Hello&#160;world</a>

XML defines only five named entities: &amp; &lt; &gt; &quot; and &apos;. Use a numeric reference (&#160; for a non-breaking space) or the character itself.

Mismatched tag

Error: error on line 2 at column 17: Opening and ending tag mismatch: to line 2 and from

Invalid

<note>
  <to>Ada</from>
</note>

Fixed

<note>
  <to>Ada</to>
</note>

The closing tag must match the opening tag exactly, including case. Firefox words this "mismatched tag. Expected: </to>".

Extra content after the root element

Error: error on line 1 at column 9: Extra content at the end of the document

Invalid

<a>1</a><b>2</b>

Fixed

<root><a>1</a><b>2</b></root>

A document has exactly one top-level element. Wrap the pieces in a parent element. Firefox words this "junk after document element".

Unquoted attribute value

Error: error on line 1 at column 10: AttValue: " or ' expected

Invalid

<book id=bk101/>

Fixed

<book id="bk101"/>

Every attribute value must be in single or double quotes, unlike in HTML.

Invalid control character

Error: error on line 1 at column 4: PCDATA invalid Char value 1

Invalid

<a>[U+0001]</a>   (an invisible control character between the tags)

Fixed

<a></a>

Most control characters below U+0020 are not allowed in XML at all, even escaped. Remove them from the data; they often come from copying text out of a binary or log file.

Browsers show this when XML breaks the language's syntax rules. Firefox words it "XML Parsing Error: not well-formed" or "mismatched tag"; Chrome says "This page contains the following errors: error on line N at column M". Either way the line and column point at the first problem.

Frequently Asked Questions

What does 'not well-formed' mean?

The document breaks XML's syntax rules, for example an unescaped &, a missing closing tag or two root elements. A well-formed document may still be invalid against a schema, which is a different check.

Why did my HTML-looking text fail as XML?

HTML tolerates unclosed tags, unquoted attributes and entities such as &nbsp;, and XML does not. Close every tag, quote every attribute and replace named entities with numeric ones.

Where do I see this in my own code?

In browsers when an .xml or SVG file is opened directly, and in parsers such as DOMParser, Python's xml.etree (ParseError: not well-formed (invalid token)) and Java's SAXParseException. The cause and the fixes are the same.

Is my XML uploaded?

No. The check uses your browser's built-in XML parser, so the text never leaves your device.

Have suggestions or feedback? We're constantly improving FormatChamp based on your comments.