DevToolbox

XML Formatter

Beautify and validate XML documents

Input

Paste or type XML
Loading...

Output

Output will appear here

Related tools

What is XML formatting?

XML formatting adds indentation and line breaks to XML documents, making them human-readable. This tool also checks well-formedness with a standards-compliant XML 1.0 parser — every tag closed and correctly nested, one root element, quoted and unique attributes, and escaped & and < characters — and reports the first error with its line and column. All processing happens in your browser.

Formatting and well-formedness

An XML formatter parses your document and re-indents it so each nested element sits one level deeper than its parent. Because XML must be well-formed — every element closed, correctly nested, and with a single root — the document is parsed first, and a structural error such as a missing closing tag or overlapping elements is reported instead of producing broken output.

Only whitespace between elements changes. Tags, attributes, text, CDATA sections, comments, processing instructions, and the DOCTYPE are copied exactly as written. Elements that mix text with child elements, such as <p>Hello <b>world</b></p>, are kept on one line exactly as they are, and so is everything inside an element marked xml:space="preserve".

Format to read, minify to transmit

Indented XML is easy to inspect; minified XML is compact for storage and transport. Minifying removes comments, the whitespace between elements, and extra spaces inside tags to reduce size, which matters for SOAP messages, RSS feeds, and configuration files sent over the network. Text, attribute values, and CDATA are kept exactly, and the size before and after is shown. Validation confirms the document is well-formed before you rely on it.

Working with feeds and config

Much of the XML developers meet is machine-generated — RSS and Atom feeds, SOAP messages, and app configuration. Those arrive as a single unbroken line, so formatting is often the first step to understanding them, and validation confirms the document is well-formed before you parse it in code.

How to format XML

  1. 1Paste your XML. Paste a document, feed, or configuration snippet into the input.
  2. 2Click Format. The document is re-indented by nesting depth, with 2 or 4 spaces. Use Minify to compress it or Validate to check well-formedness. If the XML isn't well-formed, the first error is shown with its line and column; Go to error jumps to it.
  3. 3Copy the result. Copy the formatted or minified XML into your project.

Examples

Format a compact document

Input

<note><to>Ada</to><body>Hi</body></note>

Output

<note>
  <to>Ada</to>
  <body>Hi</body>
</note>

Well-formedness error

Every element must be closed and nested correctly.

Input

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

Output

Line 1, column 7: Expected </b> but found </a>.

Minify a document

Comments and the whitespace between elements are removed; text is kept exactly.

Input

<note>
  <!-- draft -->
  <to>Ada</to>
  <body>Hi  there</body>
</note>

Output

<note><to>Ada</to><body>Hi  there</body></note>

XML building blocks

The parts of an XML document.

PartExample
Prolog<?xml version="1.0" encoding="UTF-8"?>
Element<title>Hello</title>
Attribute<book id="42">
Comment<!-- note -->
CDATA<![CDATA[ raw <text> ]]>
Root elementexactly one per document

Frequently asked questions

What does well-formed XML mean?

Well-formed XML has exactly one root element, every tag closed and properly nested, attribute values quoted and not repeated on the same element, and & and < written as &amp; and &lt; in text. Format, Minify, and Validate all check these rules and show the first one broken, with its line and column.

Does formatting validate against a schema?

It checks well-formedness (correct syntax and nesting), not validity against a specific DTD or XSD schema. Those are separate, stricter checks.

Will formatting change my data?

Only whitespace between elements changes. Text, attributes, CDATA sections, comments, and processing instructions are copied exactly, and elements that mix text and child elements, or are marked xml:space="preserve", are left as they are. Whitespace-only text between child elements, as in <p><b>a</b> <i>b</i></p>, is treated as formatting; mark the element xml:space="preserve" if that space matters.

Why minify XML?

Minified XML is smaller, which reduces bandwidth for feeds, SOAP requests, and stored documents. Minify removes comments and the whitespace between elements; text, attribute values, and CDATA are unchanged.

Is my XML uploaded?

No. Parsing, formatting, and validation happen locally in your browser. The only exception is the Share link button, which uploads the current output (and your indentation setting) when you click it.

Is it free?

Yes — free and unlimited.

What is the XML prolog?

The optional first line, such as <?xml version="1.0" encoding="UTF-8"?>, that declares the XML version and character encoding. The formatter preserves it.