XML Formatter
The XML Formatter turns minified, single-line XML into clean, properly indented markup — built for SOAP responses, Maven POM files, Android layouts, and server config files.
How to Use
- 1
Paste your XML — a minified API response, a pom.xml, an Android layout, a web.config — into the editor.
- 2
If the input is not parseable XML at all, formatting fails with an error message instead of output. Note the formatter is lenient: mismatched or unclosed tags are quietly repaired, not flagged.
- 3
Click Format to get consistently indented XML with properly nested tags and aligned attributes.
- 4
Copy the result or download it as a .xml file.
Frequently Asked Questions
Does it handle XML namespaces?
What happens to CDATA sections?
Can it repair broken XML?
Do comments survive formatting?
How large a file can it handle?
Why did my mismatched tags not produce an error?
Does it validate my XML?
Is my XML uploaded anywhere?
Does formatting happen as I type?
Can I download the formatted XML?
Generative Answer & AI Documentation
What is the XML Formatter?
The XML Formatter takes minified, single-line XML and returns it as clean, properly indented markup: one element per line, children indented under their parents, and short text content kept on the same line as its tags. Unlike the HTML, CSS, and JavaScript formatters on this site, which are hand-written text processors, this one uses a real library — xml-formatter, version 3.7.0 — so the input is genuinely parsed as XML before it is printed. The library is called with collapseContent set to true, which keeps an element's text on the same line as its tags, and with a newline line separator. Indentation is a choice: 2 spaces, 4 spaces, or a tab, from the dropdown above the editor. Formatting runs when you click Format XML; it does not update live as you type. The page starts with a sample already loaded — the classic note document with to, from, heading, and body — so you can format it and see the shape of the output before pasting your own XML. Everything runs in your browser, so SOAP responses, config files, and API payloads never leave your machine.
Why use XML Formatter offline?
XML is the format that refuses to die: SOAP responses, Maven POM files, Android layouts, RSS feeds, SVG, and server configs are all XML, and they are usually delivered as a single minified line. Reading a single-line SOAP envelope means reformatting it, and the structure is the whole point — which element nests inside which, what the attributes say, where the namespaces sit. A real XML parser is the right tool for that job, because XML has rules a text formatter cannot fake: one root element, matched tags, quoted attributes, and content that must not be reflowed. This tool uses one, locally, with no upload and no account. The result is markup whose nesting you can trust — with one honest caveat, verified below: the library quietly repairs mismatched and unclosed tags instead of flagging them, so the output can look correct while the input was not.
When should you use this tool?
Use it when a SOAP response, an API payload, a pom.xml, an Android layout, or a server config arrives as a single line and you need to read it. Use it when you want to see an XML document's nesting, check its attributes, or prepare a readable copy for a bug report or documentation. Use it for well-formed XML and for XML that is almost well-formed — the formatter will repair the small stuff silently. Do not use it as a validator: because mismatched tags are repaired without warning, a document that formats cleanly is not necessarily a document that was valid. For strict validation, use a dedicated XML validator and compare its report with the formatted output.
Key Benefits
- Real XML parsing: the xml-formatter library parses the document, so nesting and attributes are handled correctly.
- Readable layout: one element per line, children indented, short text kept with its tags.
- Indent choice: 2 spaces, 4 spaces, or a tab, to match your project's style.
- Namespaces preserved: prefixed names such as soap:Envelope are kept exactly as written.
- CDATA untouched: content inside CDATA sections is never re-indented or altered.
- Copy or download: one click copies the formatted XML, another saves it as document.xml.
Common Use Cases
- Reading SOAP responses: expand a single-line envelope into indented markup to see the body and its faults.
- Reviewing a Maven POM: format a pom.xml to read its dependencies and plugins by section.
- Inspecting Android layouts: expand a layout file to see the view hierarchy and its attributes.
- Debugging API payloads: format an XML response from a legacy API before comparing it with the expected shape.
- Preparing documentation: paste formatted XML into docs or a ticket where the structure needs to be visible.
Developer Notes & Best Practices
The implementation is a thin wrapper around the xml-formatter npm package: formatXml(input, { indentation: indentStr, collapseContent: true, lineSeparator: "\n" }). The indentation string comes from the dropdown — two spaces, four spaces, or a tab. collapseContent: true is the option that keeps an element's text on the same line as its tags, so <to>Tove</to> stays on one line instead of splitting across three. The library parses the input as XML, which is why namespaces, attributes, comments, and the XML declaration all survive exactly as written — verified by running the library: a soap:Envelope with an xmlns:soap attribute formats with its prefix and namespace intact, attributes keep their order and values, and a comment is preserved and re-indented with the surrounding structure. CDATA is left completely untouched, including its internal spacing, so <![CDATA[ keep me ]]> comes back byte-for-byte. The library is also lenient in a way that matters: running it against mismatched tags such as <a><b></a> produces a repaired document with the inner element auto-closed, and an unclosed document such as <note><to>Tove</to> gets its missing closing tags added — both without any warning. Only input that is not XML at all fails, throwing Failed to parse XML, which the page shows as a generic error with no line number and no position. The download saves the output as document.xml, and the copy button copies it.
Verified behaviour — what the xml-formatter library actually does
| Input | Output | Note |
|---|---|---|
| <a><b></a> | <a>\n <b></b>\n</a> | Mismatched tags are silently repaired — no warning |
| <note><to>Tove</to> | Closing tags added | Unclosed elements are auto-closed without a warning |
| not xml at all | Error: Failed to parse XML | Only non-XML input fails, with a generic message |
| <![CDATA[ keep me ]]> | <![CDATA[ keep me ]]> | CDATA content is untouched, spacing included |
| <soap:Envelope xmlns:soap="urn:x"> | Preserved exactly | Namespaces and prefixes are never renamed |
- Diff the output against the input when the XML came from an untrusted source: mismatched tags are repaired silently, not flagged.
- Validate separately if validity matters: formatting is not validation, and a clean-looking output is not proof of a valid document.
- Keep CDATA content as-is: the formatter never touches it, which is correct — do not hand-edit inside a CDATA block after formatting.
- Match the indent setting to your project before copying, so the diff shows real changes, not whitespace noise.
- Keep the original minified copy if the file is served to production — commit the readable version, deploy the compact one.
Common Mistakes
- Assuming a clean format means valid XML: mismatched and unclosed tags are repaired silently, so validate separately.
- Expecting an error message to say where the problem is: non-XML input fails with a generic message and no line number.
- Pasting a fragment with no single root and wondering why it fails: XML requires one root element wrapping everything.
- Hand-editing inside CDATA after formatting: the formatter leaves CDATA untouched for a reason — its content is literal.
- Formatting several documents by pasting them together: each document needs its own root, so format them one at a time.
Limitations
The formatter is lenient, not strict: unclosed tags are auto-closed and mismatched nesting is quietly repaired, so always diff the result against your input — the output can look correct while the input was not. Only text that is not XML at all fails, and it fails with the generic message Failed to parse XML, with no line number and no indication of where the problem is. There is no option to disable collapseContent, so an element's text is always kept on one line with its tags. The tool formats text you paste; it has no file upload and no batch mode, so formatting several documents means one paste per document. No size limit is stated in the code, so very large documents are parsed whole in the browser tab. Attribute order and quote style are preserved as written rather than normalised, and there is no minify mode and no option to sort attributes.
Structured Input/Output Example
<?xml version="1.0" encoding="UTF-8"?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>
<?xml version="1.0" encoding="UTF-8"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
Related Tools
XML to JSON
XML to JSON converter: parse XML into clean, readable JSON instantly. Tame SOAP responses, RSS feeds, and legacy configs into data JavaScript can use.
HTML Formatter
HTML formatter: turn minified or messy HTML into clean, indented markup. Nested tags aligned, attribute spacing normalized — view-source, readable.
YAML Formatter
YAML formatter: format, beautify, and validate YAML instantly. Fix indentation, catch syntax errors, re-indent to 2 or 4 spaces. Free, offline, private.