XML Formatter Validator
Beautify, format, or minify XML markup.
Beautify, format, or minify XML markup. Enter your numbers and get an instant result.
Paste XML and this page re-indents it by tag depth, with two spaces, four spaces or a minified single line. It is a whitespace formatter for markup that is already well formed.
It does not validate the document and it does not repair it. An unclosed tag, a mismatched end tag or an attribute written without quotes passes through as text, because the page walks angle brackets rather than building a tree.
The formatting runs in the tab and nothing is submitted. There is no schema check and no namespace resolution.
What the formatter actually does
The input is split into tags and the text between them. Each opening tag raises the indent depth for what follows and each closing tag lowers it again, so nesting is reflected in the output.
Minify removes the whitespace between adjacent tags and trims the ends. Text inside an element is kept as written, because collapsing it would change the document's content.
- Self-closing tags such as <br /> and <?xml ... ?> do not raise the depth
- Whitespace between tags is discarded; whitespace inside text is kept
- A mismatched tag lowers the depth without an error message
When you need a real XML parser
If you need to know whether the document is valid, use a parser or a schema validator. This page will happily indent a broken document into a tidy shape, which can look like a repair it did not perform.
The same warning applies to mixed content: an element that holds both text and child elements is indented by tags, so its inline text can move onto its own line. When the whitespace is significant, keep the minified form or edit by hand.
How to use the format buttons
Paste the markup into the Raw XML pane and press Format (2 Space), Format (4 Space) or Minify XML; the Output pane shows the re-indented document. An opening tag raises the indent, a closing tag lowers it, and the void set br, hr, img, input, link and meta is left alone so a br never swallows what follows.
The page walks angle brackets rather than building a tree, so an unclosed tag shifts every line after it with no error, and minify trims the text inside elements. Indent that looks right is not evidence the document is well formed: validate with a real parser.
What to Expect
Best for
- Making an exported XML document readable
- Comparing two documents once their indentation matches
- Producing a single-line document to paste into a test
Not ideal for
- Checking that a document is well formed
- Validating against a DTD or an XSD
- Documents where whitespace between elements carries meaning
What this tool keeps
- Every tag and attribute exactly as written
- Text inside elements, including its spacing
- The document order of the elements
What may need cleanup
- Mismatched tags, which are indented rather than reported
- Mixed content, whose inline text may move onto its own line
- XML declarations and processing instructions, which are kept but not interpreted
Common errors
- Assuming a clean indent proves the document parses
- Formatting a document whose whitespace is significant
- Expecting attributes to be reordered or wrapped
Example use cases
- Reading a SOAP response that arrived on one line
- Preparing an XML fixture for a diff
- Re-indenting a Maven or Ant build file
Sample input
Paste <note><to>Tove</to><body>Do not forget me</body></note> and choose the two-space indent.
Sample output
The same document with each element on its own line and two spaces of indent per level.
Who this is for
- Developers reading a machine-generated document
- Anyone diffing two XML exports
- Test authors preparing a fixture
Frequently asked questions
Does this formatter check that my XML is well formed?
No. It re-indents markup that is already well formed; mismatched tags are indented rather than reported.
Can I format a document where whitespace between elements matters?
That is not a good fit. The formatter changes the whitespace between tags, which is meaningful in some documents.
What does it keep unchanged?
Every tag and attribute as written, the text inside elements, and the document order of the elements.
Build custom tools for your store
Join the SDK program to create useful ecommerce utilities for your store.