Trexmi
Developer Ready

XML Formatter

Format and pretty-print XML online with two-space indentation. Invalid XML is rejected with the line and column of the first error.

Parses the XML before formatting Two-space indentation Reports the line and column of the first syntax error Does not fetch external resources
INPUT XML document to format *
0 chars0 words0 lines
Paste a complete XML document, including its single root element. Example: <catalog><tool id="1">Formatter</tool></catalog>
Ctrl / ⌘ + Enter
Formatted XML Formatted XML ready to review and copy.
About the tool

What XML Formatter does

The XML formatter turns compact or messy XML into indented, readable markup. Paste an API response, a SOAP message, an RSS feed, an SVG, a sitemap or a configuration file, and the tool parses it and prints it with each nested element on its own line, indented by two spaces.

Because the input is parsed first, the formatter doubles as a quick well-formedness check: if the XML is broken, you get an error with the line and column instead of a half-formatted result. To check a document without changing it, use the XML Validator.

xml formatter turning one-line XML into an indented tree
One-line XML on the left, indented tree on the right.

How to use

  1. Paste the XML. Include the whole document with its root element.
  2. Run the formatter. The document is parsed and re-printed with indentation.
  3. Read the result or the error. A syntax error is reported with its line and column.
  4. Copy the formatted XML. Use it in your editor, ticket or documentation.
Built for the task

Why use XML Formatter?

Focused controls, predictable output, and a workflow designed around this exact transformation.

01

Parsed, not guessed

The formatter works on the real XML tree, so structure and attribute values are preserved.

02

Precise errors

Broken XML is rejected with the position of the first problem.

03

No external fetching

Network access for external entities is disabled while parsing.

04

Readable output

Consistent two-space indentation makes diffs and reviews easier.

Useful answers

Questions about XML Formatter

Practical details about input, output, privacy, limits, and the best way to use this tool.

01 What is the difference between formatting and validating XML?

Formatting changes only whitespace between elements. Validation only reports whether the document is well-formed. The formatter does both in one step, because it must parse the XML first. For a pure check, use the XML Validator.

02 Does it keep the XML declaration and comments?

The output starts at the root element. The <?xml ... ?> declaration, a DOCTYPE and comments placed before or after the root element are not included. Comments inside the root element are kept. Add the declaration back if your system requires it.

03 Does formatting change the meaning of the XML?

Not for data-oriented XML: whitespace-only text between elements is dropped and replaced by indentation. If your format treats such whitespace as significant, compare the result with the original before using it.

04 Why do I get an error for XML that opens in a browser?

Browsers are often forgiving with HTML-like markup. This tool requires well-formed XML: one root element, matching tags, quoted attributes and escaped special characters such as &amp;.

05 Can I format a very large file?

Large documents work, but they depend on your browser and the server limits. For multi-megabyte files, a local tool such as xmllint is more practical.

06 Does the tool load external DTDs or entities?

No. Network access is disabled during parsing, so external references are not fetched.

07 How do I make the XML compact again?

Use the XML Minifier to remove the indentation.

Learn XML

Read the complete XML Guide

Understand XML syntax, elements, attributes, namespaces, validation, formatting, parsing, security, and common errors.

  • Elements, attributes, and namespaces
  • Formatting and validation
  • Parsing, security, and debugging
Read guide Practical explanations and examples

What an XML formatter does

XML ignores most whitespace between elements, so the same document can be written on one line or spread over hundreds. The formatter parses the text into a tree and prints it again with one element per line and two spaces per level. That makes the nesting visible and lets you scan a response, compare two versions or spot a missing element at a glance.

Where formatted XML helps

  • API and SOAP debugging: read a request or response copied from a log.
  • RSS, Atom and sitemaps: check that every entry has the elements you expect.
  • SVG and configuration files: review a minified export or a one-line config.
  • Code review: format both sides before comparing two XML documents.

Common reasons XML is rejected

  • More than one root element, or text before the root.
  • A closing tag that does not match the opening tag, or a missing closing tag.
  • Attribute values without quotes.
  • Unescaped special characters: write &amp; for an ampersand and &lt; for a less-than sign in text.
  • Undeclared namespace prefixes, such as soap:Envelope without an xmlns:soap declaration.

Limits to keep in mind

The tool formats the document tree and does not validate it against an XSD or DTD. The declaration, DOCTYPE and comments outside the root are not part of the output. Always test the formatted result in the application that will consume it.

Related tools

Check a document with the XML Validator, shrink it with the XML Minifier, convert it with XML to JSON, or format JSON with the JSON Formatter.

External reference

The syntax rules are defined in the W3C Extensible Markup Language (XML) 1.0 specification.