XML Formatter & Validator
Indent, minify or check XML without disturbing the text inside it.
Drop your file hereTap to choose a file
or click to browse, or paste from the clipboard
Format or minify
Select Format to indent nested elements by two or four spaces, or Minify to strip the line breaks and indentation between them. Comments and processing instructions are kept.
Text is left alone
Only whitespace between elements is touched. Blocks that mix text with elements, CDATA sections and anything under xml:space="preserve" are left as written, so the formatted document carries the same data as the original.
Syntax check with a reason
Validate reports whether the document is well formed. When it is not, you see the message from your browser's XML parser, which normally names the line and column of the first problem.
How to format and validate XML
- 1
Paste your XML into the XML input box. It needs a single root element and no DOCTYPE.
- 2
Choose 2 spaces or 4 spaces, then select Format. Select Minify for a compact copy, or Validate to check the syntax only.
- 3
If an error appears, go to the line and column it names, fix the markup and run it again.
- 4
Copy the result or download it as document.xml.
What people use this tool for
- Read a minified API or SOAP response by indenting it.
- Find the unclosed tag or stray ampersand that stops a sitemap, RSS feed or config file from loading.
- Minify an XML payload before pasting it into a test, an environment variable or a single-line field.
- Tidy a hand-edited pom.xml, .csproj or Android layout before sharing it.
Frequently Asked Questions
How do I format or pretty-print XML?
Paste the document into the XML input box, choose 2 spaces or 4 spaces under Indentation and select Format. The indented document appears in the Result box, where you can copy it or download it as document.xml. Select Minify instead for a compact version without indentation.
Does this validate against an XSD or DTD?
No. Validate checks that the document is well formed: one root element, every tag closed and correctly nested, attribute values quoted and special characters escaped. It does not check element names, order or data types against an XSD, DTD or RELAX NG schema. Documents that contain a DOCTYPE declaration are rejected, so remove the DOCTYPE before pasting.
Why does my XML fail the check?
The usual causes are a tag that is never closed, opening and closing names that differ in case, an unescaped ampersand or less-than sign inside text, an attribute value without quotes, or a second root element. HTML entities such as nbsp are not defined in XML, and a namespace prefix must be declared before it is used. Anything in front of the XML declaration, even a blank line, is also an error.
What exactly changes when I format?
Line breaks and indentation between elements. The browser's serializer may also write attribute values with double quotes, collapse an empty open-and-close pair into one self-closing tag and replace numeric character references with the characters they stand for. An XML declaration is kept, with its encoding changed to UTF-8 to match the downloaded file. Names, namespaces, text and comments are not altered.
How is whitespace inside text handled?
It is preserved. An element is reindented only when it contains other elements and no text of its own. If an element mixes words with child elements, holds a CDATA section or has xml:space="preserve", the formatter leaves that element and everything inside it untouched. That keeps inline markup, such as a bold or link element inside a sentence, from gaining stray spaces.
Can I format HTML, SVG, RSS or a sitemap?
Any well-formed XML works: sitemaps, RSS and Atom feeds, SOAP messages, Maven and Android files, and SVG. An SVG or XHTML file that starts with a DOCTYPE needs that declaration removed first. Ordinary HTML is usually not well-formed XML, because tags such as br and img are left unclosed, so it is reported as invalid.
What are the size limits?
Input can be up to 524,288 characters. Formatting stops at 128 levels of nesting, and when the indentation it adds would pass four million characters. In that case try two-space indentation or Minify, which adds none.
Is my XML uploaded anywhere?
No. Parsing, formatting and validation use the XML parser built into your browser, and the download is created on your device. No request carries your document, and external DTDs or entities are never fetched, because documents with a DOCTYPE are refused.