Developer
XML Formatter
Pretty-print XML with a two-space indent so feeds and config files are easy to read, then minify or check the same document. Copy or download the result.
Paste XML and choose how you want to process it.
XML output
—
Output actions
Ready to copy output once your result appears.
Two-space indent, a one-line serialize, or a parse check
XML Formatter parses the document with the browser XML parser, then either reindents the serialized tree, returns that serialization as Minify, or stops after the parse. Format is selected when the page opens. The indent is always two spaces. A declaration at the top of the paste is not part of the serialized tree, so it does not come back. Copy output and Download output both read the latest success, and the download name is xml-formatter.txt.
How to format XML
- 1Paste into XML input. The placeholder is a root element with one item child. The box starts empty. Switching Format, Minify, or Validate does not rerun the previous paste.
- 2Leave Format selected, or press Minify or Validate. Format is the filled button on arrival. Then press Run.
- 3Read XML output, or Validation result when Validate is selected. A success under Format or Minify says XML processed successfully. Validate writes the words XML is valid. both as the status and as the result. A failure clears the result and puts the parser error text in the status.
What it is good for
- • Reading a one-line element tree with a two-space indent after the parser has rebuilt it.
- • Getting the serializer's compact form, including an empty element written as a single tag.
- • Checking that a paste has one root and closed tags before you hand it to another step.
Example
Input
<root><item>Hello</item></root>
Output
<root> <item>Hello</item> </root>
Format, then Run. Minify of the same paste is the original one line. Validate of the same paste replaces the result with XML is valid.
What the serializer writes
Run in Format mode parses the paste, serializes the document, then splits tags onto their own lines and indents with two spaces. A closing tag drops the indent before it is written. An opening tag raises the indent only when that line is a start tag, is not a comment or a processing instruction, does not end in a slash, and does not already contain its own closer. So a child that still holds its text, such as <item>Hello</item>, stays on one line at the current indent. The sample root is the only line at column zero. The item sits under two spaces. There is no menu for four spaces or a tab.
Minify is the serialization alone. It does not run the indent walk, and it does not strip spaces that the parser kept inside a text node. <item id="a"> text </item> comes back with the two spaces on each side of text still there, and the attribute is quoted with double quotes even if you typed single quotes. Validate does not rewrite the document at all. Its result pane is the sentence XML is valid. and nothing else. The result heading switches to Validation result for that mode and back to XML output for the other two.
Format, Minify, and Validate
The three mode buttons sit in a group labeled XML formatter mode. Exactly one is pressed. They only change which function Run will call. If you Format a document, then press Minify, the pane still shows the indented tree until you press Run again. The status line starts as Paste XML and choose how you want to process it. After a good Format or Minify it becomes XML processed successfully. After a good Validate it becomes XML is valid. and that same sentence is the copyable result.
Copy output copies the pane. Download output saves xml-formatter.txt, including when the pane is the validation sentence. Rename the file if you wanted .xml. An error clears the pane first, so a following copy reports that there is nothing to copy. The share row above the form shares this page's address, not the document you pasted.
When indented XML is the right view
Use Format when a feed, a config fragment, or a sitemap paste is one long line and you want the elements stacked. The XML sitemap generator builds a urlset from URL rows. This page does not. If you paste that urlset here, Format only reindents whatever the parser kept. It will not add lastmod, and a declaration you typed above the urlset is dropped on the way through the serializer.
A JSON view of the same tree is XML to JSON. That page turns repeated tags into arrays and attributes into @ keys. This page never does. A JSON object you want indented belongs on the JSON formatter. Markup that is HTML, with its own indent choices, belongs on the HTML beautifier. Do not expect this Run button to understand a style block or a missing HTML closer.
Declarations, empty tags, and failed parses
The parser builds a tree and the serializer writes that tree. <?xml version="1.0" encoding="UTF-8"?> is not an element, so Format and Minify both omit it. <root></root> is an empty element, and the serializer writes <root/>. <empty/> stays <empty/>. Whitespace that is a real text node is kept: <root> </root> stays a root with two spaces, not a self-closing tag. A comment and a processing instruction survive Format and Minify. They are not elements, so they do not change the indent depth. An attribute value that contained & is still escaped in the XML pane.
Failures are the parser's. An empty box, text with no root, two top-level elements, and an unclosed tag each clear the pane and show the parser error text. The page does not add its own sentence in front of that text. It also does not repair the paste. A document that parses is reported as valid even when a later consumer would reject the vocabulary. There is no schema check, no DTD fetch, and no network request.
Rules and limitations
Format reindents the serialized tree with two spaces. Minify is that serialization without the indent walk. Validate returns the sentence XML is valid. The XML declaration is dropped. Empty elements come back self-closing.
A parse failure clears the result and shows the parser error text. Copy output and Download output use the pane. The download name is xml-formatter.txt. Mode changes do not rerun.
Common problems
If the declaration disappeared, the serializer never writes it. Put it back after you copy, if the destination requires it. If <root></root> became <root/>, that is the empty-element form, not a deleted child.
If the pane is empty and the status is a parser sentence, the click failed. The previous success is gone. Fix the paste and press Run again. Switching mode does not restore the cleared pane.
Frequently asked questions
Can I pick a different indent?
No. Format always uses two spaces. There is no four-space option and no tab. Minify does not indent.
Why did the XML declaration vanish?
Format and Minify serialize the parsed tree. The declaration is not an element, so it is not in that serialization. Validate does not echo the original paste either. It only reports XML is valid.
Does Validate check a schema?
No. It only asks the browser parser whether the paste is a single well-formed document. A parsed document can still be the wrong vocabulary for a feed or a sitemap.
What does the download save?
xml-formatter.txt. The bytes are whatever the pane holds: indented XML, the compact serialization, or the validation sentence. Rename the file if you need an .xml suffix.
Is my input uploaded or saved?
This tool processes input in your browser and does not save its input or output to local storage. Copy and download are user actions. The site uses analytics for page and action metadata and may use ads and production error reporting; see the Privacy Policy for those services.
About this tool
Maintained by Toolbench. For large or deeply nested files, split the input into smaller batches and verify representative results before using them in an import or application. Report reproducible problems through Contact.
Next steps
Related tools
Continue the workflow with nearby tools for formatting, publishing, debugging, or follow-up checks.
XML to JSON
Convert XML documents into readable JSON.
Open XML to JSONXML Sitemap Generator
Turn absolute URL rows into a sitemap urlset.
Open XML Sitemap GeneratorJSON Formatter
Pretty-print JSON with 2 or 4 spaces, or minify it.
Open JSON FormatterHTML Beautifier
Reindent HTML with 2 spaces, 4 spaces, or a tab.
Open HTML BeautifierTrust
Policies, contact, and answers
Clear pages for how Toolbench works, what we collect, and how to reach us.