XML Formatter
Paste minified or messy XML and get clean, consistently indented markup you can actually read.
- Free
- No sign-up
- Runs in your browser
What is an XML Formatter?
An XML formatter takes XML that's crammed onto one line or indented inconsistently and rewrites it so each element sits on its own line, nested one level deeper than its parent. The data doesn't change: the same tags, attributes and text values come out the other side, just laid out so the structure is visible at a glance.
It's built for anyone who has to read XML rather than just pass it along: developers debugging a SOAP response or an API payload, SEOs checking an XML sitemap or a product feed, and anyone opening a config file (Maven pom.xml, Android layouts, RSS feeds, SVG) that a tool has squashed into a single line. Elements that hold only text, like <title>XML</title>, stay on one line, so the output stays compact instead of exploding every value onto three lines.
This formatter runs entirely in your browser. Nothing you paste is uploaded, which matters when the XML contains API keys, customer records or internal endpoints. You choose 2-space or 4-space indentation to match your project's style, and existing line breaks and stray whitespace between tags are cleaned up, so already-messy files come out consistent.
How to use the XML Formatter
- 1
Paste your XML
Copy the XML from your API response, sitemap, feed or file and paste it into the input box. One-line minified XML and partially indented XML both work.
- 2
Pick an indent size
Choose 2 spaces for compact output or 4 spaces if your codebase or team style guide uses wider indentation.
- 3
Format
Run the formatter. Each child element moves onto its own line and is indented one level deeper than its parent.
- 4
Check for errors
If the input isn't well-formed XML, such as a missing closing tag or mismatched tag names, fix the problem in your source and format again.
- 5
Copy the result
Copy the formatted XML back into your editor, a ticket, documentation or a code review.
When to use an XML formatter
Debugging SOAP and REST responses
Turn a one-line SOAP envelope or XML API response into a readable tree so you can find the fault element or the field that's missing.
Reviewing XML sitemaps
Format a sitemap.xml to check <loc>, <lastmod> and hreflang entries line by line instead of scrolling across one enormous line.
Inspecting product and RSS feeds
Make Google Merchant, RSS or Atom feeds readable before you hunt for a broken item, an empty field or a wrong price.
Cleaning up config files
Normalize indentation in pom.xml, web.config, Android layouts or SVG files before committing, so diffs show real changes rather than whitespace noise.
Sharing XML in tickets and docs
Paste neatly indented XML into bug reports, Slack or documentation so teammates can follow the structure.
Worked example
Say an API returns this single line: <note><to>Tove</to><from>Jani</from></note>. It's short, but real responses run to hundreds of elements on one line, and the pattern is the same.
With the default 2-space indent, the formatter puts the root element <note> on the first line, moves each child onto its own line indented by two spaces, and closes the root on the last line:
<note> / <to>Tove</to> / <from>Jani</from> / </note> — four lines in total. Because <to> and <from> contain only text, they stay on one line each. Switch to 4-space indentation and the two child lines simply start with four spaces instead of two; nothing else changes.
Frequently asked questions
Does formatting change my XML data?
No. Tags, attributes and text values stay the same. The formatter only adds or removes whitespace between elements. Whitespace that sits purely between tags isn't meaningful in most XML, but if your format depends on it (rare, and usually marked with xml:space="preserve"), check the output before using it.
Should I use 2 or 4 spaces?
Either is valid XML. Two spaces keeps deeply nested files narrower; four spaces is common in Java and .NET projects. Match whatever your existing files or style guide use so diffs stay clean.
Why are some elements still on one line?
Elements that contain only text, such as <price>9.99</price>, are kept on a single line on purpose. Splitting them would add lines without making the structure any clearer, and it could add unwanted whitespace to the value.
What happens if my XML is invalid?
The formatter needs well-formed XML: every opening tag closed, tags properly nested, and a single root element. Common culprits are a missing closing tag, mismatched case (<Item> vs </item>) and unescaped & characters, which must be written as &.
Is my XML sent to a server?
No. Formatting happens in your browser, so the XML never leaves your device. That makes it safe to use with responses that contain tokens, personal data or internal URLs.
How is this different from a JSON formatter?
XML has attributes, namespaces, a required single root element and paired closing tags, none of which exist in JSON. This tool understands that structure. If you need to switch formats rather than just tidy one, use a dedicated XML-to-JSON converter instead.
Related tools
More Developer tools →JSON Formatter & Validator
Format, validate and minify JSON with exact error locations and a collapsible tree view.
Developer · In-browser
Base64 Encoder & Decoder
Encode or decode Base64 text and files — UTF-8 safe, URL-safe variant and data URIs.
Developer · In-browser
URL Encoder & Decoder
Percent-encode or decode URLs and inspect every part — host, path and query parameters.
Developer · In-browser
Redirect Generator
Turn old → new URL lists into redirect rules for Apache, Nginx, Cloudflare, Vercel and more.
Developer · In-browser