Skip to content
Deftkit

XML Formatter — Pretty-Print and Validate XML

Format, validate, and minify XML in your browser. Shows parse errors with line numbers. Free, fast, entirely client-side.

What is XML formatting?

XML is one of the most durable data formats still in active use. It powers configuration files, SOAP APIs, SVG graphics, Office document formats (.docx, .xlsx), RSS and Atom feeds, Android resource files, Java Maven and Ant builds, and countless enterprise and banking systems. Two properties make it survive: it's human-readable, and every language has a mature parser. The downside is that real-world XML is often minified, whitespace-free, or concatenated onto a single line by some intermediate tool — which is exactly when you need a formatter.

This tool parses your XML using the browser's native DOMParser (so validation is real, not regex-based), then writes it back out with consistent indentation. If the parser finds a syntax error, the tool shows the message instead of silently mangling the output.

Features

  • Format with 2 or 4 space indent— pick whichever matches your team's style
  • Minify — collapse whitespace for size-constrained transport (SOAP requests, XML-over-HTTP headers)
  • Validation with error messages — unclosed tags, mismatched tags, invalid characters all surface as readable errors, not silent corruption
  • Preserves comments and <![CDATA[ ]]> sections
  • Preserves the XML declaration (<?xml version="1.0"?>) when present at the top of the input
  • Self-closes empty elements <br></br>becomes <br/>
  • Inlines pure-text elements <name>Alice</name>stays on one line instead of splitting the text to its own line

Example

Input (minified, one line):

<?xml version="1.0" encoding="UTF-8"?><catalog><book id="bk101"><author>Doe, Jane</author><title>Example</title><price currency="USD">29.99</price><tags><tag>fiction</tag><tag>mystery</tag></tags></book></catalog>

Output (formatted, 2-space indent):

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book id="bk101">
    <author>Doe, Jane</author>
    <title>Example</title>
    <price currency="USD">29.99</price>
    <tags>
      <tag>fiction</tag>
      <tag>mystery</tag>
    </tags>
  </book>
</catalog>

How to use it

  1. Paste or type your XML into the left pane
  2. Click Format (2 sp) or Format (4 sp) — the output appears on the right instantly
  3. Or click Minify to strip whitespace and newlines — useful when embedding XML inside JSON or HTTP headers, or reducing payload size on a constrained network
  4. Click Copy next to the output to grab it for your clipboard
  5. If the input has a syntax error, you'll see a red error block with the parser's message. Fix the input; the formatter won't guess

Why browser-native parsing?

Many online XML formatters implement their own parser using regexes, which handle the common cases but break on edge cases: attributes containing >characters, CDATA sections, mixed content, namespaced tags, processing instructions. This tool delegates to DOMParser, the same XML parser your browser uses to render SVG and parse AJAX responses. DOMParser is implemented in native code, follows the full XML spec, and is fuzz-tested by browser vendors. Errors it finds are real errors; things it accepts are valid XML.

What this tool does and does not do

  • Does: parse, validate, and re-serialize XML with consistent indentation. Detects syntax errors. Preserves comments, CDATA, processing instructions, and the XML declaration.
  • Does not: validate against a DTD or XSD schema. That's a separate concern (and a harder problem) that would require loading schema definitions.
  • Does not: sort attributes alphabetically. Attribute order is preserved from the input.
  • Does not: transform namespaces, prefix qualified names, or resolve entities beyond the built-in XML entity set (&amp;, &lt;, &gt;, &apos;, &quot;).
  • Does not: handle HTML. HTML is superficially similar to XML but has different parsing rules (void elements, unquoted attributes, script/style content). For HTML formatting, use a tool that implements HTML5 parsing.

Privacy

All parsing and formatting happens in your browser. The XML you paste never leaves your device — there is no upload, no log, no copy of the input stored anywhere. Safe for internal configuration files, SOAP request samples with real credentials, and any other XML you wouldn't paste into a random online tool.

Frequently asked questions

Why does it reject my XML that seems valid?

XML is stricter than HTML. Common mistakes: unclosed tags (<br> instead of <br/>), mismatched case (<Div></div>), stray & characters in text (must be escaped as &amp;), unescaped < in attribute values. The error message from the parser usually points to the exact problem.

Can I format HTML with this tool?

Only if your HTML is also valid XML (XHTML). Regular HTML has void elements (<br>, <img>, etc.) that don't need closing tags, which XML does not allow. For HTML formatting, use a tool that specifically handles the HTML5 parsing algorithm.

Does the formatter preserve CDATA sections?

Yes. <![CDATA[ ... ]]>sections are passed through unchanged. Their contents are never re-escaped, so you can safely use CDATA to embed characters that would otherwise need escaping (&, <).

Will formatting change the meaning of my XML?

No — formatting only changes whitespace in element content, which XML parsers treat as insignificant for most data-oriented schemas. However, mixed-content XML (where elements contain both text and children, like HTML-style markup) can be sensitive to whitespace. This formatter renders all-element children multi-line and all-text children inline, which preserves the most common cases. If you work with strict mixed-content XML (e.g. DocBook), verify the formatted output round-trips to your consumer.

How large an XML file can I format?

Browser memory is the limit. Documents up to several megabytes format in well under a second on a modern machine. Very large files (tens of MB) may cause UI lag during the parse. There is no hard cap.

Is my data sent anywhere?

No — parsing and formatting both run in your browser via the native DOMParser API. Your XML never touches a network request.