XML Prettifier

Paste minified, single-line, or inconsistently indented XML and get back a clean, readable document with consistent two- or four-space indentation, one tag per line. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-23

Overview

Introduction

XML is verbose by nature, and that verbosity becomes unreadable fast once a document arrives minified: a SOAP response logged on one line, an RSS feed fetched straight from an API, or a config export that stripped whitespace to save bytes. This prettifier takes any well-formed XML and re-lays it out with consistent indentation, so nested structure is visible at a glance.

It exists for the same reason a JSON formatter does: the tools and services that produce XML (APIs, build pipelines, legacy enterprise systems) optimize for transfer size or generation simplicity, not for how the document looks when a human opens it later to debug a failing request.

What Is XML Prettifier?

An XML prettifier (also called a formatter or pretty printer) parses a document into its underlying tree of elements, attributes, text, and comments, then re-serializes it with consistent spacing: one tag per line, indentation that reflects nesting depth, and text content kept inline for leaf elements.

Because whitespace between tags in XML is usually insignificant to whatever is consuming the document, reformatting it changes nothing about how the data is interpreted, only how it reads on screen.

How XML Prettifier Works

Your input is tokenized into tags, text, comments, CDATA sections, and processing instructions using a stack-based parser (not the browser's `DOMParser`, so it also works reliably during static-site prerendering), then walked recursively to produce indented output at your chosen width.

Everything happens client-side, so there's no upload step and no size limit beyond what your browser can hold in memory.

When To Use XML Prettifier

Use it after fetching a SOAP or REST response that returned XML on a single line, exporting a config from a legacy admin panel, or copying a fragment out of a log line where whitespace got collapsed.

It's also a good first step before manually editing a document, since consistent indentation makes it obvious which element a given line actually belongs to.

Features

Advantages

  • Runs entirely client-side, so documents with real customer or credential data never leave your browser.
  • Preserves comments, processing instructions, and attribute order exactly, unlike formatters that round-trip through a lossy data model.
  • Confirms the document is well-formed as a side effect of formatting.
  • Configurable indent width matches your project's existing style.

Limitations

  • Only re-lays out whitespace; it doesn't validate against a schema (XSD/DTD) or check semantic correctness beyond well-formedness.
  • Mixed content (text interleaved with child elements at the same level) is preserved but may read less cleanly once split across lines, since XML doesn't distinguish significant from insignificant whitespace on its own.
  • Very large files (tens of megabytes) may be slow, since the whole document is held in memory while parsing.

Examples

Minified XML expands to readable markup

Input

<user id="1"><name>Ada</name><roles><role>admin</role><role>editor</role></roles></user>

Output

<user id="1">
  <name>Ada</name>
  <roles>
    <role>admin</role>
    <role>editor</role>
  </roles>
</user>

Each element gets its own line, indented one level deeper than its parent.

A leaf element's text stays inline

Input

<config><debug>false</debug></config>

Output

<config>
  <debug>false</debug>
</config>

An element whose only child is text is kept on one line rather than splitting the text onto its own line.

A mismatched closing tag is reported, not guessed at

Invalid input

<a><b></a></b>

Parser error

Expected closing tag </b> but found </a>

The parser reports exactly which tag it expected instead of silently reordering the structure.

Corrected version

<a><b></b></a>

Best Practices & Notes

Best Practices

  • Prettify XML before committing sample fixtures or test payloads so diffs stay readable.
  • Match the indent width your team's editor config already uses.
  • Prettify immediately after copying a response out of a browser network tab or API client, since those often show XML minified.
  • Pair with the XML Validator first if you're not sure the document is well-formed, so a parse error doesn't surprise you mid-format.

Developer Notes

This implementation parses the document into an ordered tree of element/text/comment/CDATA/processing-instruction nodes using a regex-driven tokenizer and an explicit stack, not `DOMParser`, so it runs identically during server-side static generation and in the browser. Re-serialization walks that tree recursively, collapsing an element down to one line when its only meaningful child is text, and otherwise emitting one child per line at `depth + 1` indentation.

XML Prettifier Use Cases

  • Reading a minified SOAP or REST XML response in a browser network tab
  • Cleaning up an exported config or feed before checking it into version control
  • Reformatting a fragment pasted out of a log line for debugging
  • Preparing an XML sample for documentation or a bug report

Common Mistakes

  • Assuming prettifying will fix invalid XML, when it only reformats documents that are already well-formed.
  • Expecting schema-level validation (XSD/DTD) from a formatter; use a dedicated schema validator for that.
  • Losing track of significant whitespace inside elements like `<pre>`-style text content after reformatting a document that relies on it.

Tips

  • Use the reported line and column to jump straight to a well-formedness error.
  • Pair this with the XML Minifier when you need to go the other direction before sending a payload over the wire.
  • Upload a `.xml` file directly instead of copy-pasting if the document is large.

References

Frequently Asked Questions