About XML Formatter / Validator
The XML Formatter / Validator pretty-prints compact XML into readable, indented markup, or checks whether an XML document is well-formed and reports exactly where it breaks. It's the XML equivalent of a JSON formatter, for the file format still underneath countless config files, SOAP APIs, RSS/Atom feeds, Android layouts and enterprise data exchanges.
Formatting is useful whenever XML arrives compacted onto one line — an API response, a minified config, or a feed pulled from a script — and needs indentation restored to actually review its structure. Validation is useful before that XML gets consumed by something stricter than a browser: confirming a hand-edited config file has matching tags before deploying it, or checking that generated XML from a script is well-formed before it's sent to an API that will reject anything malformed.
Formatting works by tokenizing on tag boundaries and indenting by nesting depth — a lightweight, dependency-light approach rather than a full DOM parse-and-rebuild, which means mixed content on a single line (like `<p>Hello <b>world</b>!</p>`) is kept together rather than split awkwardly across lines. Validation uses a dedicated XML parser to check well-formedness — matching tags, valid attribute syntax, a single root element — and reports the exact line and column of the first error found, the same class of check an XML parser in any programming language would perform before accepting the document.
One limitation worth knowing: because formatting works by splitting on `><` boundaries rather than fully parsing the document, a CDATA section that itself contains literal `><` sequences can format unexpectedly — if that happens, validate first to confirm the XML is well-formed, then review the formatted CDATA content manually. For everyday structured XML — nested elements, attributes, simple text content — both modes handle the common cases cleanly and run entirely in your browser.
How to Use the XML Formatter / Validator
- Paste XML into the input box.
- Choose Format to indent it, or Validate to check it's well-formed.
- Pick an indent size for Format mode.
- Fix any reported errors and copy the result.
Features
- Pretty-print XML with configurable indent size
- Validate well-formedness with exact line/column error reporting
- Handles self-closing tags, comments and declarations
- Fast, dependency-light structural formatting
Examples
Formatting a compact XML document
Input
<catalog><book id="1"><title>XML Basics</title><price>9.99</price></book></catalog>
Output
<catalog>
<book id="1">
<title>XML Basics</title>
<price>9.99</price>
</book>
</catalog>Catching a mismatched closing tag
Input
<root><a>1</b></root>
Output
Error — closing tag mismatch (line 1, column 15).
Frequently Asked Questions
What does 'well-formed' mean for XML?
It means every tag is properly opened and closed (or self-closed), attributes are correctly quoted, and there's exactly one root element — the baseline structural rules any XML parser enforces before even checking against a schema.
Does this validate against a schema (XSD/DTD)?
No — it checks structural well-formedness only (matching tags, valid syntax), not conformance to a specific schema. For schema-level structural checks on JSON data, see the JSON Schema Validator.
Can formatting break CDATA sections?
In most cases no, but a CDATA section containing literal `><` characters can format unexpectedly, since the formatter tokenizes on tag boundaries rather than fully parsing the document. Validate first if you're unsure, then spot-check any CDATA content after formatting.
Is the XML Formatter / Validator free?
Yes, the XML Formatter / Validator is completely free with no usage limits. No signup, no account and no installation required.
Is my data safe?
Yes. All processing happens locally in your browser using JavaScript — nothing you type is uploaded or stored on our servers.
Related Tools
JSON to XML Converter
Convert JSON to XML or XML back to JSON, with attributes preserved. Free online JSON ↔ XML converter, no signup required.
JSON Formatter
Format, validate and beautify JSON online. Free JSON formatter with indentation options and key sorting — runs entirely in your browser.
YAML Formatter
Format and validate YAML, or convert between YAML and JSON. Free online YAML formatter for configs, pipelines and Kubernetes files.
JSON Schema Validator
Validate JSON data against a JSON Schema and see exactly which fields fail, and why. Free online JSON Schema validator, runs client-side.
CSV to JSON
Convert CSV data to JSON online with header detection, custom delimiters and quoted-field support. Fast, free and private.
JavaScript Beautifier / Minifier
Beautify minified JavaScript into readable code, or minify it to shrink file size. Free online JS formatter — runs entirely in your browser.
HTML Formatter / Minifier
Beautify HTML into readable, indented markup or minify it to shrink file size. Free online HTML formatter, no upload required.
Mock Data Generator
Generate realistic fake names, emails, addresses and more as JSON or CSV — perfect for testing and demos. Free online mock data generator.