XML Formatter

Indent and validate XML documents.

Code Formatters Free, no sign-up Runs in your browser

XML Formatter tool

About the XML Formatter

XML Formatter indents an XML document so its structure is visible, and tells you plainly when the document will not parse. Both halves matter: XML is strict, and a single unclosed tag or stray ampersand makes the whole file unusable to anything that reads it.

Parsing uses the browser's own XML parser, which means the validation is the real thing rather than an approximation. When a document fails, you get the parser's own message naming the line and the problem, which is normally enough to find it immediately.

The formatter handles the parts of XML that trip simpler tools: namespace prefixes are preserved, CDATA sections are passed through exactly, comments and processing instructions stay where they were, and attribute values are left untouched. A minify mode collapses the document back to one line when you need it compact.

How to use the XML Formatter

  1. Paste your XMLA feed, a sitemap, a configuration file or any document.
  2. Choose an indentTwo spaces, four spaces or a tab.
  3. Press FormatValid XML is indented; invalid XML produces a specific error.
  4. Copy or downloadTake the formatted document.

Features

  • Validates with the browser's own XML parser
  • Clear errors naming the line and the problem
  • Preserves namespaces, CDATA, comments and processing instructions
  • Choice of indentation
  • Minify mode to collapse back to one line
  • Reports element count and nesting depth
  • Copy or download the result

Who uses this tool

The xml formatter is used by writers, developers, students, marketers and anyone else who needs the job done once without installing software. Common cases include:

  • Reading an RSS or Atom feed
  • Checking a sitemap before uploading it
  • Tidying a configuration file
  • Finding the unclosed tag in a broken document
  • Inspecting an XML API response

Frequently asked questions

Why does my XML fail to parse?

Usually an unclosed tag, a stray ampersand that should be &, mismatched case in a tag name, or more than one root element. XML is case-sensitive and has exactly one root, both of which catch people used to HTML.

Is XML the same as HTML?

No. XML is strict: every tag must close, attribute values must be quoted, and there is one root element. HTML browsers are forgiving of all three, which is why markup that renders fine fails as XML.

Are CDATA sections preserved?

Yes, exactly as written. Their whole purpose is to hold content that must not be parsed, so a formatter that indented inside them would corrupt the data.

Does it validate against a schema?

No. It checks that the document is well-formed, which is the structural question. Validating against a DTD or XSD is a separate step that needs the schema itself.

Can I format a very large file?

Documents of a few megabytes format fine. Very large ones may be slow, since the whole document is parsed into memory in the tab.

Is my document uploaded?

No. Parsing and formatting happen in your browser.

If the xml formatter is not quite what you need, these other free tools solve closely related problems.

JSON Formatter

Pretty-print and validate JSON, with the exact line and column of any error.

Developer Tools Use tool

XML Sitemap Generator

Build sitemap.xml from your URL list, with lastmod, changefreq and priority.

SEO Tools Use tool

HTML Formatter

Pretty-print HTML with consistent indentation, or collapse it back down.

Code Formatters Use tool

YAML to JSON Converter

Translate between YAML and JSON, with clear errors on invalid indentation.

Developer Tools Use tool

CSV Viewer

View CSV data as a proper table you can sort, search and page through.

Developer Tools Use tool