XML Formatter

Validate, beautify or minify XML — comments and CDATA preserved.

Runs in your browser Instant No sign-up
Indent
XML
Formatted XML

Paste, type or drop a file — output appears as you type.

Waiting for input
Processed locally · nothing is uploadedProcessed locally

How to use the XML formatter

  1. Paste, drop or open an XML document in the left pane.
  2. Choose Indent: 2 spaces, 4 spaces, Tabs or Minify.
  3. If the document is well-formed, the formatted XML appears on the right and the status bar shows the number of elements. If not, the error and its line and column are shown instead.

Example

<?xml version="1.0"?><!-- feed --><root a="1"><item id="1">A &amp; B</item><item id="2"/></root>

becomes

<?xml version="1.0"?>
<!-- feed -->
<root a="1">
  <item id="1">A &amp; B</item>
  <item id="2"/>
</root>

The declaration, the comment, the attribute order and the &amp; entity are all kept. Empty elements are written in self-closing form, so <empty></empty> becomes <empty/>.

Well-formedness errors

The document is checked before formatting, and the first problem is reported with its position:

Input Error
<root><a></b></root> Expected closing tag 'a' (opened in line 1, col 7) instead of closing tag 'b'.
<root><a>1</a> Unclosed tag 'root'.

Click Jump to error to move the cursor to the reported line.

Common causes of well-formedness errors:

  • A raw & in text or attributes, as in Tom & Jerry. Write it as &amp;.
  • A raw < in text, as in 1 < 2. Write &lt; or wrap the text in a CDATA section.
  • HTML habits such as <br> or <img src="x"> without a closing slash. In XML they must be <br/> and <img src="x"/>.
  • Unquoted attribute values, such as id=1 instead of id="1".
  • Text before the first element, such as a stray word pasted above the document.
  • More than one top-level element, such as <a/><b/>. A document has exactly one root element (XML must have exactly one root element; found 2.).
  • A bare & inside an attribute value, such as title="R&D" — write R&amp;D.

What changes and what doesn’t

Kept as written Normalized
Comments, CDATA, processing instructions, DOCTYPE Indentation and line breaks between elements
Attribute order and values Empty elements become self-closing
Entities such as &amp; and &#169; Whitespace-only text between elements
Mixed content, such as <p>Hello <b>world</b> again</p>

Elements that mix text with child elements are written on one line exactly as they appear, because whitespace inside them is significant — <p>Hello <b>world</b> again</p> keeps its spaces. Elements that contain only child elements are indented one level per depth, and an element with a single text or CDATA child stays on one line.

Doing it locally

xmllint --format feed.xml        # libxml2: validate and pretty-print
xmllint --noblanks feed.xml      # remove ignorable whitespace

Frequently asked questions

Is my XML uploaded?

No. Validation and formatting run in your browser and nothing is uploaded, so SOAP payloads, configs and feeds stay private.

Does it validate against a schema (XSD or DTD)?

No. It checks that the document is well-formed: every tag is closed, tags nest correctly and attributes are quoted. Validating against an XSD or DTD needs a schema-aware validator.

Are comments and CDATA kept?

Yes. Comments, CDATA sections, processing instructions and the XML declaration are preserved, and attributes keep their original order.

Are entities like &amp; decoded?

No. Entities and character references are kept exactly as written, so A &amp; B stays A &amp; B and the document means the same thing after formatting.

What does Minify do?

It removes the indentation and line breaks between elements and writes the whole document on one line, which is useful before embedding XML in a request or a string.

Last updated