XML Formatter

Format, validate, and beautify XML documents

By

Developer tools

XML Formatter

Format and beautify XML strings with proper indentation.

Runs in your browser. No signup required.

Parse as XML, then indent two spaces

Beautify parses the box with DOMParser in application/xml mode. If the document contains a parsererror element, the page stops with “Invalid XML format” and clears the output. A document that parses is serialized and run through an indenter that puts a newline between tags and indents with two spaces, increasing the indent on an opening tag and decreasing it on a closing tag.

A tag that opens and closes on the same line stays at the current indent. The sample <root><item id="1">A</item><item id="2">B</item></root> is enough to see each item on its own line. Attributes stay on the opening tag. The tool does not wrap long attribute lists or sort attributes.

Reading a feed or a config

Paste a sitemap, an RSS item, or a Maven POM when it arrived as one line. Check that the output still has the same text nodes. The indenter is for people, not a canonical XML signer. If you need the document minified again, this page has no minify button. The HTML encoder is the right neighbor when the problem is entities, not structure.

HTML is not XML. An unclosed <br> or a bare & in text can fail the XML parser even though a browser would show the page. Do not use a failed format as proof the HTML is broken for the web. Use the HTML mode of the combined minifier only if you wanted whitespace collapsed, which is a different job.

What “valid” means here

There is no XSD or DTD check. A document can format and still violate the schema your API requires. Namespaces are preserved when the parser keeps them. The error string does not include the line the browser’s parsererror node might have carried; open the source in an editor if you need the row.

The formatted text can be copied. It is not pretty-printed with a schema-aware formatter, and it is not sent to a server. Large documents are limited by the tab’s memory, the same as any textarea.

Parse first, then indent what the serializer returns

Beautify parses the box with DOMParser in application/xml mode. A document that contains a parsererror element stops with “Invalid XML format” and clears the output. A document that parses is serialized and then split so that every boundary between > and < starts a new line. Indent is two spaces. An opening tag increases the indent for the following line. A closing tag decreases it before that line is written.

The one-line sample <root><item id="1">A</item><item id="2">B</item></root> comes back with root on the first line, then a line of two spaces plus <item id="1">A</item>, then the same indent for item 2, then the closing root tag. A tag that opens and closes on one line does not add an extra indent level. Attributes stay on the opening tag, in the order the serializer returned.

What the indenter will not repair

There is no schema check. A file can indent cleanly and still violate the XSD or the API your reader expects. Namespaces survive only when the browser’s parser keeps them. The error string does not include a line number from the parsererror node. If you need the row, open the source in an editor.

HTML habits fail here. An unclosed break tag or a bare ampersand in text can be rejected even though a browser would show the page. Do not treat that rejection as a verdict on the HTML. The HTML encoder is the neighbor for entities. This page has no minify button, so the indented copy is for a person reading the file.

Use it on a feed or a config that arrived as one line

A sitemap, an RSS item, or a short config is the right size. Paste, beautify, and compare a text node you care about with the original. The indenter is not a canonical XML canonicalizer, and a signature over the original bytes will not match the indented copy. Copy the output if you want to keep it. The box is not uploaded.

Very large documents are limited by the tab. If the parser accepts the file and the indent looks wrong, look for a tag that the line rule treated as both open and closed. The sample’s items stay on one line each because the opening and closing tags share that line. The joiner between those lines is a carriage return followed by a line feed. A diff that expected Unix newlines can mark every line even though the tags did not change. Show hidden characters in your editor if you need to confirm those carriage returns.

How to use XML Formatter

  1. 1

    Paste your XML into the Raw XML box.

  2. 2

    Press Beautify.

  3. 3

    Read the indented result in Formatted Output.

  4. 4

    Press Copy above Formatted Output to copy the indented XML.

FAQ

What does the formatter do?

It indents tags so a single-line or messy XML string is easier to read. It is a formatter, not a schema validator.

Will broken XML still format?

It can still insert line breaks around tags, but it will not repair missing closers or illegal characters.

Does it upload the document?

No. Formatting runs in the browser.

Can I use it on HTML?

You can paste markup, but the indenter expects XML-style tags. For HTML entities, use the HTML encoder. For a full page minify, use the HTML/CSS/JS minifier.

Does formatting mean the XML matches my schema?

No. The page only checks that the browser’s XML parser accepts the text, then indents it. There is no XSD validation.

Why did my HTML fail?

The parser is in XML mode. Unclosed tags and bare ampersands that a browser would forgive in HTML can be rejected here.

How is the sample root indented?

The one-line root with two items is split so each item is on its own line, indented two spaces: <item id="1">A</item> and then <item id="2">B</item>. The closing root tag returns to the left margin.

Does a successful format mean the XML matches a schema?

No. The page checks that the browser’s XML parser accepts the text, then indents the serializer’s output. There is no XSD or DTD check.