How to use XML Formatter
The XML Formatter beautifies raw or minified XML with proper indentation and line breaks, and can also minify formatted XML back to a compact single-line form for production use. Well-formatted XML is essential for readability when working with SOAP APIs, RSS/Atom feeds, SVG files, Android manifests, Maven POM files, and configuration formats like Spring XML. Validation catches malformed markup before it causes parser errors. All processing is client-side.
- Paste your raw, minified, or malformed XML into the input area, or upload an .xml file.
- Click Format to apply indentation (default: 2 spaces) and line breaks — the output is a human-readable version of the input.
- Alternatively, click Minify to strip all insignificant whitespace for a compact production payload.
- If the XML is not well-formed, the tool highlights the first error with a line number and description.
- Use the indent size selector to switch between 2-space, 4-space, or tab indentation.
- Copy the formatted output or download it as an .xml file.
Your data never leaves your device — 100% private processing.
XML structure rules and well-formedness
XML has strict well-formedness requirements defined by the W3C XML 1.0 specification. Every document must have exactly one root element. All elements must be properly nested — overlapping tags like <a><b></a></b> are illegal. Attribute values must be quoted (single or double). The characters <, >, and & must be escaped as <, >, and & in text content; single and double quotes inside attribute values must be escaped as ' and " respectively. Element and attribute names are case-sensitive and must start with a letter or underscore. XML is distinct from HTML in that it has no predefined tags and is used as a generic data serialisation format.
| Feature | XML | JSON |
|---|---|---|
| Human readability | Moderate (verbose) | High (compact) |
| Data types | Strings only (schema adds types) | Native number, boolean, null |
| Attributes | Yes (key="value" on elements) | No — all data in values |
| Comments | Yes (<!-- ... -->) | No |
| Namespaces | Yes (xmlns:prefix="uri") | No |
| Schema standard | XSD, DTD, RELAX NG | JSON Schema |
| Common use | SOAP, RSS, SVG, config files | REST APIs, config, data exchange |
XML namespaces and CDATA sections
XML namespaces (xmlns) prevent element name collisions when combining vocabularies from different specifications in a single document — for example, combining XHTML and MathML. A namespace is declared as xmlns:prefix="http://uri" and then applied by prefixing element names: <math:math>. The default namespace (xmlns="...") applies to all unprefixed elements within its scope. CDATA sections (<![CDATA[ ... ]]>) let you embed text containing < and & without escaping, which is useful for embedding HTML or JavaScript inside XML without a cascade of entity references. CDATA is a text node and carries no structural meaning — parsers strip the delimiters and return the raw text.
Worked examples
Pretty-print minified XML
Inputs: <a><b>1</b></a>
Result: indented, each element on its own line
Minify XML
Inputs: formatted multi-line XML
Result: single line, insignificant whitespace removed
Not well-formed
Inputs: <a><b></a></b>
Result: error: improperly nested tags (line 1)
Glossary
- Well-formed XML
- XML that satisfies all syntactic rules: single root, properly nested tags, quoted attributes, and escaped special characters.
- XML namespace
- A URI-identified scope declared with xmlns that qualifies element and attribute names to prevent collisions.
- CDATA section
- An XML construct (<![CDATA[ ... ]]>) that wraps text containing characters that would otherwise need escaping.
- XSD
- XML Schema Definition — a W3C standard for defining the structure and data types of XML documents.
- XPath
- A query language for selecting nodes from an XML document tree, used in XSLT transforms and XML validators.
Related reading
Frequently Asked Questions
Why use XML Formatter?
- Beautify raw or minified XML with configurable indentation for human-readable output
- Minify well-formed XML to a compact single-line payload for production transmission
- Validate XML well-formedness and report the first error with its line number
- Choose 2-space, 4-space, or tab indentation to match your project's style conventions
Common use cases
- Format a minified SOAP response to locate a specific element during API debugging
- Beautify an Android manifest or Spring XML config file before a code review
- Validate a Maven POM file for well-formedness after manually editing a dependency block
- Minify an SVG file's embedded XML to reduce its inline size in an HTML document
- Format a raw RSS feed response to check the channel and item element structure
Get weekly tool tips & updates
New tools, power-user tips, and productivity hacks — delivered free every Friday.
No spam, ever. Unsubscribe with one click.
Related Developer Tools
JSON Formatter & Validator
Format, validate, and minify JSON instantly. Includes syntax highlighting, error detection, and a collapsible tree view — free, private, in-browser.
YAML ↔ JSON Converter
Convert YAML to JSON and JSON to YAML online. Validate syntax instantly with error messages. Free, private converter that runs in your browser.
SQL Formatter
Format and beautify SQL queries online. Adds line breaks, indentation, and keyword casing for readable queries. Free SQL beautifier in your browser.
JSON to TypeScript Types
Convert JSON to TypeScript interfaces online. Infers types, nested objects, and arrays automatically. Free, private JSON-to-TS generator in your browser.
Cron Expression Generator
Build and decode cron expressions online. Get a plain-English description of any crontab schedule and a field-by-field breakdown. Free cron generator.
Regex Tester
Test and debug regular expressions online. See live matches, capture groups, and replace output. Free, private, instant.
Explore all Developer Tools.