XML formatter and validator
Paste XML to indent it and check that it is well formed. If something is wrong you get the line and column of the problem. Free, and your XML never leaves your browser.
How to use it
- Paste your XML in the Your XML box.
- Choose the style in Indentation: 2 spaces, 4 spaces or Tab.
- Read the Validation result, then click Copy or Download to use the Formatted XML.
Complete guide to formatting and validating XML
What an XML formatter does
XML is the format behind sitemaps, RSS feeds, SVG images, Office documents, configuration files and many data exchanges between companies. It is often delivered as one long line with no line breaks, which is impossible to read and hard to debug. This tool indents the document so the structure becomes visible, and at the same time checks that the XML is well formed. If something is broken, it tells you the line and column of the first problem instead of leaving you to hunt for a missing tag.
What counts as well-formed XML
The validator applies the basic rules of the XML specification. It is a syntax check, not a check against a schema (XSD or DTD), so it cannot tell you whether an element is allowed in a given place, only that the document can be parsed.
- There is exactly one root element, and no text outside it.
- Every opening tag has a matching closing tag, in the right order (
<a><b></a>is an error). - Attribute values are in single or double quotes, an attribute name is not repeated in the same tag, and values do not contain a bare
<. - A literal ampersand is written
&. Only& < > " 'and numeric references are accepted. A name such as is rejected unless the document declares it in a DOCTYPE. - The XML declaration (
<?xml ... ?>) can only appear at the very start, and a DOCTYPE must come before the root element.
How the formatting works
The tool reads the document, builds a tree and prints it again with one element per line. Elements that contain only text stay on one line, so <title>XML Basics</title> is not split. Comments, processing instructions, the DOCTYPE and CDATA sections are kept exactly as written. Only the whitespace between elements changes. In elements that mix text and child tags, such as a paragraph with a bold word, the text is placed on its own lines and spacing is normalized, so avoid reformatting documents where exact whitespace inside such elements matters.
Worked example
- Paste
<?xml version="1.0"?><catalog><book id="1"><title>XML Basics</title></book><book id="2"/></catalog>in Your XML. - Leave Indentation on 2 spaces. The Formatted XML box shows:
<?xml version="1.0"?>
<catalog>
<book id="1">
<title>XML Basics</title>
</book>
<book id="2"/>
</catalog> - Validation reports Valid XML, Elements 4, Attributes 2 and Maximum depth 3. A self-closing tag such as
<book id="2"/>counts as an element. - Now paste a broken document with a wrong closing tag: three lines
<a>,<b>and</a>. The result is:Line 3, column 1: Closing tag </a> does not match <b> opened on line 2.
Indentation choices
| Option | Result | When to use it |
|---|---|---|
| 2 spaces | Compact, deep documents stay readable | Most web and config files |
| 4 spaces | Wider, clearer levels | Teams that follow a 4-space style guide |
| Tab | One tab character per level | Projects that indent with tabs |
Tips and common mistakes
- An unescaped
&in a URL inside an attribute or text, such as?a=1&b=2, is the most common error. Write it as&. - Tag names are case sensitive:
<Item>and<item>are different elements. - The tool reports the first error only. Fix it and run again to find the next one.
- If a document is valid but a system still rejects it, the cause is probably the schema or the required namespaces, which this tool does not check.
Related tools
To build a valid sitemap use the sitemap XML generator. For HTML markup use the HTML beautifier, and to show markup as visible text use the HTML entities encoder. Everything runs in your browser and nothing is uploaded.
Questions
What does the validator check?
That the XML is well formed: tags are opened and closed in the right order, attributes are quoted and not repeated, there is a single root element and ampersands are escaped. It does not validate against an XSD or DTD schema.
Can it fix invalid XML?
No. It points to the line and column of the first error so you can fix it, then format again.
Does formatting change my data?
Only whitespace between elements changes. Text inside elements, attributes, comments and CDATA are kept. In elements that mix text and tags, spacing is normalized.
Is my XML uploaded anywhere?
No. Everything runs in your browser and nothing is sent or stored.