XML Formatter - Beautify, Minify, and Check Syntax
Beautify or minify XML, catch syntax errors, format empty tags, sort attributes, and strip comments.
Working with REST API payloads in JSON format instead? Switch to our JSON Formatter.
🔒 Data Safety: We process everything securely and never store or share it.
How to Use
- Paste raw XML into the input box above, or open or drop a local file.
- Pick your indentation and empty-tag style, and toggle attribute sorting or comment removal below.
- Click "Format" to check tag syntax and generate indented or single-line XML output.
- Use "Copy" to copy the formatted XML or "Download" to save an .xml file.
Options Explained
- Indentation: Indent nested elements with "2 Spaces", "4 Spaces", or "1 Tab (\t)" while keeping inline mixed text intact. Choose "Minify (1 Line)" to strip inter-tag whitespace into a compact single-line XML string.
- Empty Tags: Collapse empty elements into "Self-Closing (<tag/>)" or "Spaced (<tag />)" tags for SVG and XHTML. Pick "Keep Original" to preserve explicit <tag></tag> pairs separately from self-closing tags in SOAP payloads.
- Sort Attributes: Place xmlns declarations first and sort remaining attributes from A to Z on each tag. Leave it unchecked to keep your exact original attribute order and quote styles.
- Strip Comments: Delete <!-- ... --> comment blocks across the document before formatting or minifying. XML declarations, DOCTYPE subsets, processing instructions, and CDATA sections remain untouched.
Key Features
- Indent nested XML, RSS, SVG, and SOAP tags with spaces or tabs, or minify into one line.
- Pinpoint exact line and column numbers for mismatched tags, unclosed quotes, duplicate attributes, or bare ampersands.
- Keep inline mixed content and xml:space="preserve" blocks intact without inserting unwanted line breaks.
- Preserve XML declarations, DOCTYPE internal subsets, CDATA sections, numeric character references, and custom DTD entities.
- Format empty elements as <tag/> or <tag />, or keep explicit <tag></tag> pairs for SOAP parsers.
- Sort attributes with xmlns prefixes first, strip leading UTF-8 BOM markers, and download clean .xml files.
About This Online XML Formatter
Built on W3C XML 1.0 well-formedness rules, this XML formatter indents, minifies, and checks structured XML markup. Unlike standard browser XML parsers, token scanning in browser memory preserves DTD entities, numeric references, and mixed text.
Developed and maintained by the PU Tools team, this tool gives you fast, accurate, safe, and easy results in just a few clicks.
Common Use Cases
- SOAP and Webhook Debugging: Expand single-line SOAP envelopes or XML webhook payloads to inspect nested headers, body faults, and namespaces.
- SVG and Android Layout Diffs: Sort xmlns declarations and element attributes alphabetically before committing .svg graphics or Android layout files to Git.
- RSS, Atom, and Sitemap Checks: Catch unclosed tags, bare ampersands, or broken CDATA blocks in RSS feeds and XML sitemaps before publishing.
- Maven and Config Minification: Remove XML comments and collapse whitespace in Maven pom.xml or Spring configuration files for compact transfer.
Example Input and Output
Example Input
<?xml version="1.0" encoding="UTF-8"?><!-- Geneva Feed --><catalog shop="Maison Genève" currency="EUR"><product id="101" stock="in"><name>Édition Limitée</name><price>24.50</price><badge/><note><![CDATA[ Ships <24h & tracked 🚀 ]]></note></product></catalog>
Options used: Indentation: 2 Spaces | Empty Tags: Self-Closing (<tag/>) | Sort Attributes: OFF | Strip Comments: OFF
Example Output
<?xml version="1.0" encoding="UTF-8"?>
<!-- Geneva Feed -->
<catalog shop="Maison Genève" currency="EUR">
<product id="101" stock="in">
<name>Édition Limitée</name>
<price>24.50</price>
<badge/>
<note><![CDATA[ Ships <24h & tracked 🚀 ]]></note>
</product>
</catalog>
Two-space indentation aligns nested tags while keeping the XML comment, accented text, self-closing badge, and CDATA intact.
Frequently Asked Questions
Does this XML formatter validate files against an XSD or DTD schema?
No, it checks W3C XML 1.0 syntax and well-formedness rather than external XSD or DTD schemas. The parser pinpoints unclosed tags, mismatched names, duplicate attributes, unescaped ampersands, and invalid characters by line and column.
Will beautifying XML insert unwanted spaces inside mixed text elements?
No, elements that mix text and child tags stay inline so word spacing never changes. Blocks marked with xml:space="preserve" also keep their exact whitespace and line breaks during indentation or minification.
Why does this formatter keep custom DTD entities and numeric references intact?
Standard browser XML parsers often reject undeclared entities like © or expand numeric character references into raw text. Our token scanner preserves custom entity names, DOCTYPE internal subsets, processing instructions, and CDATA blocks as written.
When should I choose "Keep Original" instead of self-closing empty tags?
Select "Keep Original" when legacy SOAP services or strict XML parsers treat <tag></tag> differently from <tag/>. For SVG graphics or XHTML templates, choose "Self-Closing (<tag/>)" or "Spaced (<tag />)" to normalize empty elements.
Does this formatter convert between data formats or decode Base64 tags?
No, this utility formats, minifies, and checks existing XML, RSS, Atom, SVG, or SOAP documents only. Use our JSON Formatter for REST payloads, or Base64 Decoder to inspect Base64-encoded text payloads inside SOAP tags.
Do my XML documents or SOAP payloads leave my browser during formatting?
No, every XML syntax check, indentation pass, and minification step executes inside your browser using client-side JavaScript. Sensitive SOAP envelopes, Maven configs, and feed files stay on your computer with zero server transmission.