XML Formatter & Validator
Paste XML to check that it is well-formed and get it neatly indented, or minify it to one line. Errors are shown with the line and column.
Checked by your browser's own XML parser; nothing is uploaded.
This XML formatter indents XML so its structure is easy to read, and checks at the same time that it is well-formed. It is useful for API responses and SOAP messages that arrive on a single line, for exported data and feeds, and for configuration files you need to edit by hand. Minify does the reverse, removing the whitespace between tags to make files smaller.
XML Syntax Rules
| Rule | Wrong | Right |
|---|---|---|
| Exactly one root element | <a/><b/> | <root><a/><b/></root> |
| Every tag is closed | <br> | <br/> |
| Tags close in reverse order | <b><i>x</b></i> | <b><i>x</i></b> |
| Names are case-sensitive | <Name>x</name> | <name>x</name> |
| Attribute values in quotes | <a id=7> | <a id="7"> |
| Escape & and < in text | Tom & Jerry | Tom & Jerry |
Special Characters
Five characters have a predefined escape (entity) in XML:
| Character | Write | Needed |
|---|---|---|
& | & | Always |
< | < | Always |
> | > | Only after ]], but often escaped anyway |
" | " | Inside an attribute in double quotes |
' | ' | Inside an attribute in single quotes |
For a block of text full of special characters, such as code or HTML, a CDATA section avoids escaping: <![CDATA[ if (a < b && c) ]]>. HTML names such as are not defined in XML; use the numeric form   instead.
Related Tools
Turn the XML into JSON for JavaScript with the XML to JSON converter, compare two versions of an XML file with the diff checker, or format JSON with the JSON formatter.
Frequently Asked Questions
How do I format XML?
Paste the XML, open a file or load one from a URL, and the indented version appears on the right as you type. Choose 2 spaces, 4 spaces or tabs, then copy the result or download it as an .xml file. Minify does the opposite and puts everything on as few lines as possible.
How do I check whether XML is valid?
The tool checks every input with your browser's built-in XML parser. Green means the XML is well-formed; otherwise you get the first error with its line and column and the line itself with a marker. This checks well-formedness (the syntax rules every XML file must follow); it does not check the file against an XSD or DTD schema.
What is the difference between well-formed and valid XML?
Well-formed XML follows the syntax rules: one root element, every tag closed and correctly nested, attribute values in quotes, and & and < escaped. Valid XML is well-formed and also matches a schema (an XSD or DTD) that says which elements and attributes are allowed. Any XML parser needs the first; only some programs check the second.
Will formatting change my data?
No. Only whitespace between tags changes. Text inside elements, attribute values, CDATA sections and comments are kept exactly. Elements that mix text and child elements, such as <p>Some <b>bold</b> text</p>, and elements with xml:space="preserve" are left as they are, because there the whitespace can be part of the content.
What are the most common XML errors?
A tag that is not closed or closed in the wrong order (<b><i></b></i>); an unescaped & in text or a URL, which must be written &; a missing quote around an attribute value; more than one root element; and text or whitespace before the <?xml ?> declaration, which must be the very first thing in the file.
Can it format SVG, RSS feeds and config files?
Yes, all of these are XML: SVG images, RSS and Atom feeds, sitemap.xml, Android layouts, Maven pom.xml, .NET .csproj and web.config files, Office document parts and KML or GPX maps. Open the file directly with Open file.