Skip to content
Convert Filez
Developer ToolsRuns in your browser5 min read

XML Formatter

This XML formatter takes a document that arrived as one unreadable line and gives it consistent indentation, one element per line, in the browser you already have open. Paste the markup or drop a file, choose an indent width, and read the result instead of squinting at it.

Loading the tool interface
Files never leave your deviceNo upload wait and no queueNo signup, watermark or file limit

Machine generated XML almost never ships formatted. SOAP envelopes, RSS feeds and configuration exports are written by code that has no reason to add whitespace, so a document with forty nested elements arrives as a single 12 kilobyte line.

Nothing leaves your machine. This XML formatter parses the document with the browser's own XML parser and re serialises it locally, so a config file full of internal hostnames or a customer record from an API response stays on your device. There is no upload request, no queue and no size cap beyond the memory of the tab.

When you need to format XML online

The obvious case is reading something a machine wrote. The less obvious case is diffing: two versions of a minified file produce a diff that is one enormous changed line. Run both through an XML formatter first and the diff collapses to the elements that actually moved.

Formatting also finds structural mistakes quickly, because a document that will not parse fails at a specific line and column and the error names the construct that broke.

  • Reading an API response, a SOAP envelope or a webhook payload that arrived on one line.
  • Preparing two revisions of a config file so a diff shows real changes rather than line noise.
  • Checking that a sitemap, RSS feed or manifest is well formed before you publish it.
  • Normalising indentation across a repository so editors stop fighting each other.
  • Making a generated SVG readable before you hand edit the path data.

Well formed is not the same as valid

This tool checks that a document is well formed: every element closed, no overlapping nesting, quoted attribute values and exactly one root element. A document failing any of those tests cannot be parsed at all, so the error is reported before formatting is attempted.

Validity is a stronger and separate claim. A valid document is well formed and also obeys a schema, a DTD or an XSD saying which elements may appear where. Browsers do not run schema validation, so this tool does not claim to. A sitemap nesting a url element inside another url element is well formed and completely invalid.

What the indent setting changes

Indent width is the only stylistic choice that matters. Two spaces suits deeply nested documents such as Android layouts and Maven build files, where four spaces push content off the screen by the sixth level. Tabs suit a repository that already uses them.

One rule applies regardless: an element whose only child is text stays on a single line. Splitting a title element across three lines to hold six words makes a document longer without making it clearer.

Whitespace between elements is not significant in most XML vocabularies, which is what makes reindentation safe. It is significant inside an element carrying mixed content or with xml:space set to preserve, so this pretty print xml step leaves text nodes untouched.

How this XML formatter works in your browser

Two standard browser interfaces do the work. DOMParser turns your text into a document tree, and if the text is not well formed it returns a parsererror element instead, which is where the reported line and column come from. The tree is then walked and written back out with your indentation.

Because the parser is the browser's own, this XML formatter behaves like the parser that would load the document in a real application. Namespaces, CDATA sections, processing instructions and comments all survive the round trip rather than being approximated by a regular expression guessing where tags begin.

The privacy consequence is simple. There is no server in the path, so there is nothing to intercept and no retention policy to trust.

Entities, CDATA and the parts people get wrong

Five character entities are predefined and need no declaration: amp, lt, gt, quot and apos. Everything else, including names familiar from HTML such as nbsp, must be declared in a DTD first. A file using a bare nbsp entity is not well formed, which confuses people arriving from HTML every day.

A CDATA section lets text contain angle brackets without escaping each one, which is why embedded scripts and SQL fragments are wrapped in one. Its content is text rather than markup, so this XML beautifier keeps the section intact instead of reindenting it.

Formatting SVG, RSS and configuration files

SVG is XML, so an exported icon drops straight into the XML formatter. Design tools emit paths with hundreds of coordinates and no line breaks, and reformatting shows which group holds which shape before you edit by hand.

Feeds benefit for a different reason. An RSS file a reader silently rejects usually has one unescaped ampersand in a title, and the parse error points at that character. The same applies to build files, Spring configuration and anything else that is XML underneath.

What the parser accepts and what it rejects
ConstructAcceptedNote
Unclosed elementNoXML has no optional end tags, unlike HTML
Overlapping elementsNoNesting must be strict at every level
Two root elementsNoExactly one document element is allowed
Undeclared named entityNoOnly amp, lt, gt, quot and apos are predefined
CDATA sectionYesContents kept verbatim, never reindented
Namespaces and prefixesYesPreserved exactly through the round trip

How to format XML

  1. 1

    Add your XML

    Paste the markup into the input box or drop an XML, SVG, RSS or config file onto the drop area. The file is read locally.

  2. 2

    Pick an indent width

    Choose two spaces, four spaces or a tab. Two suits deeply nested documents, tabs suit repositories that already use them.

  3. 3

    Format the document

    Press the format button and the XML formatter reindents the tree. If the document is not well formed, the error names the line and column where it broke.

  4. 4

    Copy or download the result

    Copy the formatted markup to your clipboard, or download it as an XML file with the indentation applied.

Related tools worth bookmarking

Sources and further reading

Frequently asked questions

Common questions about the xml formatter.

No. Only whitespace between elements is adjusted, and that whitespace is not significant in ordinary XML content. Element order, attributes, namespaces, comments, CDATA sections and text content all survive the round trip exactly as they were written.

No. This XML formatter parses and serialises entirely in your browser. The document never crosses the network, so internal hostnames, tokens and customer data in a payload stay on your own machine and no copy exists anywhere else.

No. It checks that the document is well formed, meaning tags are closed and nested correctly with a single root element. Checking a document against an XSD, a DTD or a RELAX NG schema needs a validating parser, which browsers do not provide.

XML predefines only amp, lt, gt, quot and apos. Named entities inherited from HTML such as nbsp or copy must be declared in a DTD first, so a document using one without declaring it is genuinely not well formed and no parser will accept it.

No limit is imposed by this xml indent tool. The practical ceiling is the memory available to the browser tab, since the whole document tree has to be held at once. Files of several tens of megabytes format without trouble on a normal laptop.

Keep going

More developer tools

View the full category