Skip to content

XML Formatter

To format XML online, paste it here and choose Pretty with 2-space, 4-space, or Tab indent — or Minify for one compact line. XML Formatter parses locally with the browser's DOMParser, rejects malformed XML with an error instead of guessing a fix, and preserves attributes, namespaces, and CDATA. Nothing is uploaded or stored.

Updated

Paste an XML document or fragment and format it locally — pretty-print with 2-space, 4-space, or Tab indentation for reading and review, or minify to a single line. Closing the tab drops the workspace; we do not write it to localStorage or send it to a formatter API. This page is an XML beautifier / pretty-printer for text you already have, not an XSD/DTD validator and not a SOAP client.

Formatting runs against the browser's own DOMParser. If the document is not well-formed — an unclosed tag, a stray ampersand, mismatched namespaces — the page shows a parse error next to the input instead of guessing at a fix. Attributes, namespaces, and CDATA sections are preserved as written; this page reflows whitespace between elements, it does not rewrite your markup.

XML workspace

Pretty

Applies in Pretty mode. Minify ignores indent and collapses to one line.

Paste an XML document or fragment. Well-formedness only — not an XSD/DTD validator. Nothing is uploaded.

Output

Whitespace formatter only — not an XSD/DTD validator or SOAP client. Closing the tab drops the workspace.

How does the XML Formatter work?

  1. 1. Paste XML

    Drop in an XML document or fragment. An example (a tiny fictional book catalog) is available from Load example.

  2. 2. Parse locally

    The browser's DOMParser runs in this tab. Malformed XML — an unclosed tag, a stray ampersand, mismatched namespaces — gets an error next to the input; nothing is sent anywhere.

  3. 3. Pretty-print or minify

    Choose Pretty with 2 spaces, 4 spaces, or Tab per nesting level for reading and review, or Minify for a single compact line. Indent applies to Pretty only. Attributes, namespaces, and CDATA content are preserved as written; only inter-element whitespace changes.

  4. 4. Copy the result

    Copy the formatted XML. Closing the tab drops the workspace.

Questions about XML Formatter

What does this XML formatter do?
It pretty-prints or minifies XML in your browser. Paste an XML document or fragment, and it reformats the whitespace between elements — 2-space, 4-space, or Tab indentation for reading and review, or a single compact line. It parses your XML with the browser's DOMParser first, so anything that is not well-formed is rejected with an error rather than silently patched.
Does it upload my XML?
No. Parsing and formatting run entirely in the browser with DOMParser and XMLSerializer. There is no account, no server-side formatter, and no file upload. The text you paste stays in this tab until you clear it or close the page. We do not write it to localStorage. That is the same privacy rule as JSON Formatter and SQL Formatter on this hub.
What happens if my XML is invalid or malformed?
You get a short error next to the input — for example, an unclosed tag or an invalid character — and the output stays empty. The page does not guess at a fix, auto-close tags, or escape characters on your behalf. Correct the XML in an editor and paste again.
How is this different from JSON Formatter on this hub?
JSON Formatter parses and formats JSON with JSON.parse / JSON.stringify. This page parses and formats XML with the browser's DOMParser/XMLSerializer instead — a different language with different syntax rules (tags and attributes, not braces and colons). They do not convert between the two formats; each one only reads its own language.
What is the difference between Pretty and Minify?
Pretty adds indentation per nesting level so the structure is easy to read and diff — pick 2 spaces, 4 spaces, or Tab from the Indent menu. Minify ignores indent, strips whitespace-only text between elements, and collapses the document to a single line, which is useful for pasting into a config field or a compact log line. Neither mode changes element order, attribute values, or text content — only inter-element whitespace.
Can I indent XML with tabs or 4 spaces?
Yes. The Indent menu offers 2 spaces (the default), 4 spaces, or Tab — one tab character per nesting level in Pretty mode. Minify ignores the Indent control. Indent only changes leading whitespace; element order, attributes, namespaces, CDATA, and comments stay as written.
Can it handle very large XML files?
The page is meant for typical documents and config-sized fragments. Very large files (many megabytes) can strain browser memory and slow down the tab, because parsing builds a full DOM tree in memory. There is no upload size limit, because nothing is uploaded — the limit is your browser's memory and responsiveness. For multi-megabyte exports, prefer a local CLI formatter.
Does it change my attributes, namespaces, or CDATA sections?
No. Attribute order and values, namespace prefixes and URIs, and the content of CDATA sections and comments are preserved exactly as written. This page only reflows the whitespace between elements — it is a whitespace formatter, not a namespace normalizer or a content rewriter.
Is this an XML schema validator or a SOAP client?
No. It only checks that the XML is well-formed enough for the browser's parser to build a document — it does not validate against an XSD or DTD, does not resolve external entities or DOCTYPE references, and does not send or receive a SOAP request. If you need schema validation, use a dedicated XSD validator; this page stops at "is this well-formed XML."
How do I format XML from the command line instead?
On Linux or macOS, run xmllint --format file.xml to pretty-print an XML file in the terminal (xmllint ships with libxml2). Add --noblanks with no --format to get compact output. On Windows, PowerShell can load the file as [xml] and call .Save() to re-indent it. This browser page does the same whitespace-only reformat without installing anything.

These tools run in your browser. Page Utils does not store, upload, or write to localStorage the keys, tokens, or text you paste. Results are a convenience aid, not legal, tax, or security advice.