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
- The XML Viewer, Formatter & Validator
- The XML file that fails
Steps
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.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>Fix the ampersand
The next message points at line 8: “Gift wrap & ribbon” contains a lone
&. Change it to&.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.
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
andéaren’t defined in XML. Use the character itself or a number reference such as .
Next steps
Go back to the XML Viewer, Formatter & Validator, or keep going with one of these:
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.