XML Formatter
Format, indent, and validate XML documents.
Client-Side Execution & Privacy Guarantee
This utility executes 100% locally in your web browser. Your inputs, tokens, queries, and data payloads are never transmitted to any external server or backend.
XML remains common in configuration files, SOAP payloads, and data exports. When the markup arrives minified or inconsistently indented, nested elements become difficult to trace. This formatter checks that the document is well-formed, then rewrites it with uniform indentation so every element’s parent-child relationship is obvious.
Everything runs locally. Sensitive documents such as signed requests or internal configuration can be examined without leaving the machine. The same pass that beautifies the XML also surfaces the first well-formedness violation with a clear location.
Well-formedness checks
A well-formed XML document must have a single root element, properly matched start and end tags, correctly quoted attributes, and no illegal characters in names. The formatter reports the first violation it encounters, including the approximate line and the nature of the problem.
Common issues include mismatched tags, unescaped < or & inside text, and attributes that lack quotes. Fixing the reported location usually allows the remainder of the document to parse.
Indentation and whitespace
Each child element is placed on its own line and indented one level relative to its parent. Text nodes that contain only whitespace are normalized; significant text content stays intact and is not wrapped unless it is extremely long.
Empty elements may be written in the short form (<tag/>) or the long form according to a simple preference. Processing instructions and comments are preserved and indented to the same level as neighboring elements.
XML exported from a service or log is often compacted into one line; pretty-printing restores element hierarchy so you can inspect namespaces, attributes, and nested records without guessing at structure.
What the tool leaves alone
The formatter does not alter element or attribute names, namespace declarations, or text content. CDATA sections are kept exactly as written so that embedded markup or scripts remain valid.
It does not perform schema validation against an XSD or DTD; it only confirms well-formedness. For structural conformance you can copy the formatted result into a dedicated schema validator.
The formatter does not interpret schemas or resolve entities; it only rewrites whitespace and indentation. Feeding the same document through it twice yields identical bytes, which makes the result safe to use as a normalized snapshot in reviews or tests.
These choices keep the output predictable and suitable for both human review and automated pipelines that expect stable formatting.
When to use this tool
- Inspecting a minified SOAP or configuration payload
- Cleaning XML before committing it to version control
- Making nested data exports readable for analysis
- Verifying that generated XML is well-formed
- Preparing XML examples for documentation
How to use the XML Formatter
- Paste the XML document into the input area.
- Choose the indent size (2 or 4 spaces).
- Click Format. Errors appear immediately if the document is not well-formed.
- Correct any reported problems and re-run.
- Copy the indented result or download it as an .xml file.
- If namespaces or CDATA are present, verify they remain intact.
- Clear the input when finished.
Worked examples
Simple nested document
<catalog><book id="1"><title>XML Guide</title><author>Ada</author></book></catalog>
<catalog>
<book id="1">
<title>XML Guide</title>
<author>Ada</author>
</book>
</catalog>
Each element indented according to its nesting depth.
Empty element and attribute
<config><setting name="debug" value="true"/></config>
<config> <setting name="debug" value="true"/> </config>
Empty element kept in short form; attributes remain on the same line.
Common mistakes and tips
- Fix the first well-formedness error before looking for others; later errors are often consequences.
- Preserve CDATA sections exactly; the formatter will not escape or unescape them.
- Namespace prefixes are left unchanged so that qualified names continue to resolve.
- Very deep documents still format quickly, but extremely large text nodes may need manual review.
- After formatting, re-validate against your schema if structural rules matter.
- When the formatted result is copied back into an editor that uses different default indentation, the visual structure remains clear and the document stays valid.
Frequently asked questions
Does it validate against an XSD?
No. It only checks that the XML is well-formed. Schema validation requires a separate tool.
How are CDATA sections treated?
They are preserved exactly, including any internal whitespace or markup.
Can it handle documents with multiple roots?
No. XML requires a single root element. Documents with more than one root are reported as not well-formed.
Are processing instructions kept?
Yes. They are indented to the same level as surrounding elements.
Does formatting change the infoset?
Only insignificant whitespace between elements is adjusted. Element structure, attributes, and text content remain the same.