Skip to content

XML Formatter and Validator

Format, minify and check XML for well-formedness, with the exact line and column of any error. Text and mixed content are never changed.

XML

Checked for well-formedness as you type

Formatted

The formatted XML appears here. Text, attribute values, CDATA and mixed content are kept exactly as written.

—

Runs in your browser — nothing you enter leaves this device.

About this tool

What it does

XML from APIs, SOAP services, sitemaps, RSS feeds and config files often arrives as one long line. This tool lays it out with one element per line and consistent indentation, or does the reverse and minifies it, and checks as you type that the document is well-formed — one root element, tags that close in the right order, quoted attributes, and no bare & or < characters. When something is wrong it gives the line and column and says what to change. Formatting only moves whitespace between elements: the text inside an element, attribute values, CDATA sections and comments come out exactly as they went in, and elements that mix text with tags (as in XHTML) are left alone, because there the spaces are part of the content.

How to use it
  1. Paste XML, or press “Try an example”.
  2. Choose Format or Minify. For formatting, choose 2 spaces, 4 spaces or tabs.
  3. Turn “Keep comments” off to strip comments, and turn on one attribute per line for tags with many attributes.
  4. If the document isn’t well-formed, read the line and column in the message, fix it in the input, and the result updates.
  5. Copy the formatted or minified XML.
Limits and your data
  • It checks well-formedness, not validity: it does not load a DTD or XML Schema (XSD) to check which elements and attributes are allowed.
  • Entities other than &amp; &lt; &gt; &quot; &apos; and numeric references are accepted only when the document has a DOCTYPE declaring entities. Their replacement text is not expanded or checked.
  • Namespace prefixes are kept as written; it does not check that each prefix is declared.
  • Whitespace-only text between elements is treated as layout and re-indented. If your format gives that whitespace meaning, mark the element xml:space="preserve" and it will be left alone.
  • Input is limited to 5 MB.
  • The checking and formatting are done by code in this page, in your browser. The XML you paste — which may contain customer records, credentials in a SOAP header or internal URLs — is never uploaded, logged or stored.

Questions

What does “well-formed” mean?

It means the document follows XML’s own grammar: exactly one root element, every tag closed and nested properly, names that match exactly (XML is case-sensitive), attributes quoted and not repeated, and special characters escaped. Any XML parser must reject a document that is not well-formed — unlike HTML, there is no error recovery.

Why is &nbsp; an error?

XML defines only five named entities: &amp;, &lt;, &gt;, &quot; and &apos;. &nbsp; and the other HTML names are not part of XML unless a DOCTYPE declares them. Use the numeric reference &#160; for a no-break space instead.

How do I put a “<” or “&” in text?

Write &lt; for < and &amp; for &. For a block of code or text with many of them, wrap it in a CDATA section — <![CDATA[ … ]]> — where they can appear as they are.

Why didn’t some elements get re-indented?

Elements that contain both text and child elements, such as <p>Hello <b>world</b></p>, are kept on one line exactly as written, because adding line breaks there would add spaces to the text. The same goes for anything under xml:space="preserve".

Does minifying change the data?

No. Minifying removes only the whitespace between elements. Text inside elements, attribute values and CDATA sections are untouched, so a program reading the XML gets the same data — unless it treats that layout whitespace as meaningful, which is rare.