XML Formatter and Validator
Paste XML to indent it, minify it, and check that it is well-formed. If something is wrong, the tool shows the line and column and says what to fix, such as an unclosed tag, an undefined entity like or an unquoted attribute. The text inside your elements is never touched, only the whitespace between elements changes. Everything runs in your browser, so your XML is not uploaded.
Well-formed XML: 10 elements, 6 attributes, 4 levels deep.
<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns:dc="http://purl.org/dc/elements/1.1/">
<!-- two books -->
<book id="b1" lang="en">
<dc:title>Learning XML</dc:title>
<price currency="USD">29.99</price>
<note>Great for <em>beginners</em> & experts.</note>
</book>
<book id="b2">
<dc:title>XML in a Nutshell</dc:title>
<price currency="USD">39.95</price>
<stock/>
</book>
</catalog>
Related Tools
[4 suggestions]JSON Formatter
Validate, pretty-print, and minify JSON with clear error reporting for invalid input.
Developer & WebYAML to JSON Converter
Convert YAML configurations and documents into pretty-printed, valid JSON in real time with syntax validation.
Format ConversionHTML Entity Encoder / Decoder
Escape text as HTML entities, or turn named and numeric entities back into characters.
Format ConversionDiff Checker
Compare two blocks of text line by line and highlight additions, deletions, and changes.
Developer & WebAbout the XML Formatter and Validator
The XML formatter reads your document with a strict parser for XML 1.0 well-formedness and namespace prefixes, then writes it back with each nested element on its own line. Text, attribute values, CDATA sections, comments and processing instructions are kept exactly as typed. Only the whitespace between elements is re-indented, and only in elements that contain nothing but other elements, because whitespace inside text is part of the data. An element that mixes text and tags, like a paragraph with a bold word, is left as it is, and so is everything inside an element marked xml:space="preserve". Minify removes the same whitespace and leaves a single line. You can choose 2 spaces, 4 spaces or a tab, and remove comments. The validator reports the first error with its line and column: mismatched or unclosed tags, a duplicate attribute, an attribute without quotes, a stray ampersand or less-than sign, an entity that is not defined, a character XML does not allow, content after the root element, and a namespace prefix with no declaration. Only the five built-in entities and numeric references work unless the DOCTYPE declares more, so is reported, and   is the fix. Documents nested more than 257 levels deep are rejected, the same limit libxml2 uses. The tool does not validate against a DTD or an XSD schema. It was compared with libxml2, a widely used open source XML parser, on more than 42,000 documents, valid and broken: the verdict matched on all but about 140, where the tool follows a rule libxml2 relaxes or libxml2 checks an encoding name or a namespace address that the tool does not, and in every valid document the formatted and minified versions had exactly the same content as the original. Everything runs in your browser and nothing is uploaded.
How do I format XML?▾
Paste it into the tool and choose Format. Each nested element goes on its own line, indented by 2 spaces, 4 spaces or a tab. Text inside elements is left as you wrote it, so the data does not change.
What does well-formed XML mean?▾
It means the document follows the basic syntax rules: one root element, every opening tag closed in the right order, attribute values in quotes, no duplicate attributes, and special characters like & and < written as entities. A well-formed document can be read by any XML parser.
Why does give an error?▾
XML has only five built-in entities: <, >, &, " and '. belongs to HTML. Use the numeric reference   for a non-breaking space, or declare the entity in the DOCTYPE.
Does it validate against an XSD or DTD?▾
No. It checks well-formedness and namespace prefixes, not whether the elements match a schema. To validate against a schema you need a tool that has the schema file.
Does formatting change my data?▾
No. Only whitespace between elements is changed, and only where an element contains nothing but other elements. Text, attribute values, CDATA, comments and processing instructions stay exactly as you typed them, and an element that mixes text and tags is not touched.
Is my XML uploaded?▾
No. The checking and formatting run in your browser, and what you paste is not sent anywhere or stored.