XML Formatter & Validator

Pretty-print, indent, validate and minify XML online. Detects malformed tags, unclosed elements and mismatched quotes, with DTD support. No upload.

Input XML
Output

How it works

Parsing and validation

Parsing uses the browser's native `DOMParser` with the `application/xml` MIME type, which performs real namespace-aware parsing rather than pattern matching. Malformed markup, unclosed elements, and mismatched attribute quotes are caught by the parser itself, and the resulting `parsererror` node is surfaced with the browser's own message text.

That message format is engine-specific — Firefox includes line and column numbers, other engines phrase it differently — so do not build tooling on the exact wording. Treat it as a human-readable diagnostic. The formatter is strict about well-formedness but does not validate against a DTD or an XSD, so content that is document-valid but schema-invalid passes silently.

How elements are re-serialised

The pretty-printer walks the DOM directly rather than calling `XMLSerializer`. Elements are emitted with their attributes in document order, an element with no meaningful children collapses to a self-closing tag, and an element whose only meaningful child is text stays on one line — which keeps leaf content compact instead of spreading it across three lines.

CDATA sections, processing instructions, and comments are each preserved by node type. The important rule is that whitespace-only text nodes are dropped before printing, which is what stops indentation already present in the source from accumulating on every pass — reformatting an already-formatted document is therefore stable rather than progressively indented.

Losses worth knowing about

Only the document element is walked, so the XML declaration and any DOCTYPE are absent from the output. A document carrying a DTD with entity declarations, or an encoding declaration, will not survive a round trip. Minify mode additionally discards comments, while pretty mode keeps them.

Escaping is applied only where the printer itself builds attribute values, replacing a double quote with `"`. Character data is emitted as trimmed text content, so an entity reference such as `&` in the source arrives from the parser as a literal `&` and is written back unescaped — the result is well-formed-looking output that will not re-parse cleanly.

Mixed content is reshaped for a related reason: in `<p>Hello <b>name</b></p>` the text between the tags keeps its content but the surrounding whitespace is normalised to fit the chosen indent, so rendered spacing can differ from the original even though no characters are lost. Formatting is therefore lossy for any document where whitespace carries meaning.

Frequently Asked Questions

How do I format XML?
Paste your XML into the input and click Format. The tool parses the XML and re-serializes it with consistent indentation. It handles namespaced elements, attributes, CDATA sections, and XML declarations.
Does the XML formatter validate my XML?
Yes. Invalid XML produces a clear error message showing the line and column of the problem. Common issues like unclosed tags, invalid attribute syntax, and malformed entity references are all caught.
Is my data sent to a server?
No. Every tool on jsonversal runs entirely in your browser using the Web Crypto API, File API, and Clipboard API. Nothing is ever uploaded — not even the JSON you paste in.
Do I need an account or API key?
No signup, no email, no API key. All tools are free to use with no signup required.
Can I use these tools offline?
Yes. Once the page loads, all tools work offline. There are no external API calls or CDN dependencies at runtime.
🔒
Your data never leaves your device

All processing happens in your browser. No uploads, no tracking, no servers. Your API keys, configs, and private payloads stay private — 100% client-side.

esc
↑↓ navigate ↵ open esc close