Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

XML Formatter

Pretty-print or minify XML and find syntax errors by line and column.

Developer No upload Works offline Free, no sign-up

About the XML Formatter

Paste XML — a SOAP or API response, an Android layout, an RSS feed, a sitemap, a Maven pom.xml or an SVG file — and get it neatly indented, or minified onto one line. The formatter only changes the whitespace between tags: comments, CDATA sections, processing instructions, the DOCTYPE and every attribute value are kept exactly as written, and text is never trimmed.

As you type, the document is checked against the well-formedness rules of XML 1.0. Problems are reported with the exact line and column and a plain explanation — a closing tag that does not match, an unescaped &, an attribute without quotes — and your browser's own XML parser double-checks the result.

How to use it

  1. Paste XML into the input box, or use Open file for .xml, .svg, .rss and similar files.
  2. Choose the indentation (2 spaces, 4 spaces or tabs). Optionally put one attribute per line or remove comments.
  3. Press Format (or Ctrl/⌘ + Enter) to pretty-print, or Minify to remove the whitespace between tags.
  4. Copy or download the result. If the XML has an error, read the message and use Jump to error to go straight to it.

Examples

Pretty-print a compact document
Input
<note><to>Asha</to><body>See you at <b>5</b></body></note>
Result
<note>
  <to>Asha</to>
  <body>See you at <b>5</b></body>
</note>

<body> mixes text and a tag, so it stays on one line — adding line breaks there would change the text.

Find a mismatched tag
Input
<list>
  <item>One</item>
  <item>Two</itm>
</list>
Result
Line 3, column 12: Closing tag </itm> does not match <item> opened at line 3, column 3. Change it to </item>.
Escape a special character
Input
<p>Fish & chips</p>
Result
Line 1, column 9: A bare '&' is not allowed. Write &amp; for an ampersand…

In XML text, & must be written &amp; and < must be written &lt;.

Common uses

  • Reading minified API, SOAP or payment-gateway responses while debugging.
  • Tidying Android layouts, Maven and .NET project files, or SVG icons before committing them.
  • Checking an RSS feed or a sitemap for syntax errors before publishing it.
  • Minifying XML to make a payload or a config file smaller.

What well-formed XML means

A well-formed document follows the syntax rules of the XML 1.0 specification:

  • There is exactly one root element that contains everything else.
  • Every start tag has a matching end tag in the right order, or is self-closing like <br/>. Names are case-sensitive: <Item> is not closed by </item>.
  • Attribute values are always in quotes, and an attribute appears only once per element.
  • In text and attribute values, < must be written &lt; and & must be written &amp;. Only five entities are predefined: &lt; &gt; &amp; &apos; &quot;; others such as &nbsp; must be declared in a DOCTYPE.
  • The XML declaration <?xml version="1.0"?>, if present, must be the very first thing in the file.

What the formatter changes — and what it never touches

  • Changes: line breaks and indentation between tags, and the spacing between attributes.
  • Never changes: text content, attribute values and their quote style, comments, CDATA sections, processing instructions, the DOCTYPE and entity references.
  • Keeps on one line, exactly as written: elements that mix text and tags, elements with single spaces between tags (such as <b>a</b> <i>b</i>), and anything inside xml:space="preserve".
  • Whitespace-only content that contains a line break is treated as indentation and replaced.

Well-formed is not the same as valid

This tool checks that the document is well-formed. It does not validate it against a schema (DTD, XSD or RELAX NG) — for example it cannot tell you that <price> is required inside <product>. Namespace mistakes are reported as warnings, because most XML tools reject them: a prefix used without an xmlns: declaration, a name with more than one colon, the reserved xml and xmlns prefixes used wrongly, or one attribute written twice through two prefixes for the same namespace.

Limitations

  • No schema validation (DTD, XSD, RELAX NG). External DTDs are not loaded, so entities defined only there cannot be checked.
  • Whitespace-only text with a line break between tags is treated as formatting. Use xml:space="preserve" where such whitespace matters.
  • Documents are processed on your device; very large files (tens of megabytes) can take a few seconds on older phones. Files over 1 MB are formatted without being loaded into the editor, and only the first 400 KB of a large result is shown — Copy and Download always include everything.
  • Documents nested thousands of levels deep can be checked and minified but not indented, because the indentation alone would run to many megabytes.
  • XML 1.1 documents are checked with the XML 1.0 character rules.

Privacy

Everything happens in your browser. What you enter or open here is not uploaded or stored by MySmartCoPilot.

Frequently asked questions

Is my XML uploaded anywhere?

No. Checking and formatting happen in your browser, even offline. Your browser's built-in XML parser is used as a second check, and it does not load anything from the internet either.

Why is &nbsp; an error?

&nbsp; is an HTML entity. XML only predefines &lt;, &gt;, &amp;, &apos; and &quot;. Use the numeric reference &#160; (or the character itself) instead, or declare the entity in a DOCTYPE.

Will formatting change my data?

Only the whitespace between tags. Text, attribute values, comments and CDATA are copied exactly, and elements where whitespace might matter (mixed text and tags, single spaces between tags, xml:space="preserve") are left as they are.

Does it validate against an XSD or DTD?

No. It checks well-formedness — the rules every XML document must follow. Schema validation needs the schema files and a validating parser.

Can I format HTML with it?

Only XHTML that is also well-formed XML. Ordinary HTML allows unclosed tags such as <br>, which XML rejects; use the HTML formatter for that.

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.