XML Viewer, Formatter & Validator · Tutorial

How to find and fix errors in invalid XML

6 min readbeginnerUpdated

An import fails with “XML is not well-formed”. You will paste the file into the XML formatter, fix each problem it reports in turn, and confirm the document passes.

What you need

Steps

  1. Load the broken order

    Load the example. The status bar under the box turns red and reports that </items> was found while <item> (opened on line 6) is still open. The second item never gets its closing tag. Press Go to error to jump to the line.

  2. Fix the unclosed tag

    Add </item> after “Ceramic Mug” on line 6. The check runs again as you type.

    <item sku="MUG-014" qty="1">Ceramic Mug</item>
  3. Fix the ampersand

    The next message points at line 8: “Gift wrap & ribbon” contains a lone &. Change it to &amp;.

  4. Confirm it passes

    The status turns green and shows the element and attribute counts. Copy the formatted result or fix the program that produced the file.

Try it yourself

Opens the XML Viewer, Formatter & Validator with this tutorial's sample loaded.

Try it now

Common mistakes

Fixing only the first error
Parsers stop at the first problem, so there may be more behind it. Keep going until the status bar turns green.
Using HTML entities
&nbsp; and &eacute; aren’t defined in XML. Use the character itself or a number reference such as &#160;.

Next steps

Go back to the XML Viewer, Formatter & Validator, or keep going with one of these:

Tutorial · 5 min · beginner

How to make XML from an API readable

Turn a one-line XML response into indented, readable XML, find the values you need, and keep the content exactly as it was.

Tutorial · 8 min · beginner

How to select XML elements with XPath

Learn the XPath expressions you will use most, from simple paths to filters on attributes and values, by trying them on a sample document.

FAQ

Where do these errors usually come from?

From code that builds XML by joining strings without escaping values. Use an XML library, or escape values with the XML Escape tool.