Skip to content
MoneyDeck

XML Formatter & Validator

Pretty-print or minify XML and pinpoint well-formedness errors

Updated · Free, no signup

Formatted XML

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book id="bk101" lang="en">
    <title>XML Developer's Guide</title>
    <price currency="USD">44.95</price>
    <tags>
      <tag>xml</tag>
      <tag>guide</tag>
    </tags>
  </book>
  <!-- more books -->
  <book id="bk102"/>
</catalog>

Validation

Well-formed XML

Error details

None

Error line

0

Error column

0

Root element

catalog

Elements

8

Attributes

4

Nesting depth

4

  • Well-formed means the syntax is correct; it does not check the document against a DTD or XML Schema.

About the XML Formatter & Validator

This XML formatter indents XML so its structure is easy to read, or minifies it to a single line for transport. Paste a SOAP response, an RSS or Atom feed, an Android layout, a Maven pom.xml, an SVG or a sitemap, pick 2 spaces, 4 spaces or tabs, and every nested element is placed on its own line. Elements that contain text keep that text exactly as written, so whitespace-sensitive content is never altered.

Before formatting, the input is checked for well-formedness — the rules every XML parser enforces. Mismatched or unclosed tags, a second root element, unquoted or duplicate attributes, a bare & or < in text, undefined entities such as &nbsp;, misplaced XML declarations and broken comments are reported with a plain-English message and the exact line and column, so you can go straight to the problem.

Note that well-formed is not the same as schema-valid: this tool checks XML syntax, not whether the document matches a particular DTD or XSD. All processing happens locally in your browser, so configuration files and API payloads stay on your device.

How to use the xml formatter & validator

  1. 1Paste your XML into the input box.
  2. 2Choose Pretty print or Minify and your indentation.
  3. 3Decide whether to keep comments.
  4. 4If the status is Invalid XML, fix the problem at the reported line and column.
  5. 5Copy the formatted XML.

Formula and method

The checker follows the well-formedness rules of the W3C XML 1.0 specification: exactly one root element; every start tag has a matching end tag with identical, case-sensitive spelling, properly nested; attribute values are quoted and each attribute appears once per element; < and & are escaped in text and attribute values; comments contain no “--”; and the <?xml ?> declaration, if present, is the very first thing in the file. The first violation found is reported with its line and column.

Pretty printing writes each element on its own line, indented one level per depth. Whitespace-only text between elements is treated as formatting and replaced; elements that contain real text or CDATA are written exactly as in the source so their content is preserved. Minify removes the same formatting whitespace. Entities are kept as written, not expanded.

Worked examples

Pretty-print a catalog

The sample has 8 elements (catalog, 2 books, title, price, tags and 2 tags) and 4 attributes (two id, lang and currency). The tag elements sit 4 levels deep: catalog › book › tags › tag.

Indent a small document

Each child of <note> goes on its own line indented by 4 spaces. Elements with text stay on one line, and the empty element keeps its explicit end tag.

Catch a mismatched tag

XML tag names are case-sensitive, so </B> does not close <b>. The closing tag starts at column 10 of line 2 (2 spaces + “<b>text” is 9 characters).

Minify while dropping comments

The line breaks and indentation between tags are formatting only, so they are removed together with the comment, leaving a 28-character single line.

Frequently asked questions

What is the difference between well-formed and valid XML?+

Well-formed XML follows the basic syntax rules: one root, matching and properly nested tags, quoted attributes, escaped special characters. Valid XML is also well-formed and additionally conforms to a DTD or XML Schema that defines which elements and attributes are allowed.

Why is & an error in my XML?+

In XML the ampersand starts an entity reference, so a bare & in text or an attribute must be written as &amp;. The same applies to < (&lt;). URLs with query strings are the usual culprit: ?a=1&b=2 must become ?a=1&amp;b=2.

Does pretty-printing change my XML data?+

Only whitespace between elements is changed. Elements containing text or CDATA are written exactly as they were, and entities are not expanded. Whitespace-only text between tags is technically data too, but almost every XML consumer treats it as insignificant formatting.

Can it format SVG, RSS, sitemaps and pom.xml files?+

Yes. They are all XML, so any well-formed SVG, RSS or Atom feed, sitemap, Maven pom.xml, Android layout, XAML or SOAP envelope can be formatted and checked here.

Is XML case-sensitive?+

Yes. <Item> and <item> are different elements, so <Item>…</item> is a mismatched-tag error. Attribute names are case-sensitive too, unlike HTML.

Related tools