XML Formatter & Validator

Pretty-print or minify XML and check that it is well-formed. Works for SOAP, RSS, sitemaps and configuration files.

Runs 100% in your browser. Nothing you paste is uploaded or stored.
XML input
Result
Ready.

How to use the XML formatter

  1. Paste your XML into the input box: a SOAP envelope, an RSS feed, a sitemap, an SVG file or a configuration file.
  2. Click Format to pretty-print it with one element per line and consistent indentation.
  3. Click Minify to remove whitespace between tags and produce the most compact version.
  4. If the document is not well-formed, the checker reports what went wrong and where, so you can jump straight to the problem.
  5. Copy the result into your editor or request.

Parsing happens locally in your browser. The XML you paste is never uploaded or stored, so you can safely work with internal API payloads and configuration.

What is XML and why format it?

XML (Extensible Markup Language) is a W3C standard for representing structured data as nested, named elements with optional attributes. It is still everywhere: SOAP web services, RSS and Atom feeds, XML sitemaps, Microsoft Office files, Android layouts, Maven pom.xml files and SVG graphics are all XML.

XML generated by software is often written on a single line or with irregular indentation. Pretty-printing makes the hierarchy visible, so you can follow which element belongs to which parent and spot a value in the wrong place. Minifying is useful when you need to embed XML in another payload or reduce its size.

Well-formed vs valid XML

These two terms are often confused:

  • Well-formed XML follows the syntax rules of the XML specification: one root element, properly nested and closed tags, quoted attribute values and escaped special characters. Every XML parser requires this.
  • Valid XML is well-formed and conforms to a schema (a DTD, XSD or RELAX NG) that defines which elements and attributes are allowed.

This tool checks well-formedness. Schema validation needs the schema file and is usually done in your build tooling or IDE.

Common XML errors and how to fix them

More than one root element. An XML document must have exactly one top-level element:

<item>A</item>
<item>B</item>

Wrap the siblings in a single parent:

<items>
  <item>A</item>
  <item>B</item>
</items>

Mismatched or improperly nested tags. Tags must close in reverse order and names are case-sensitive, so <Name>…</name> is an error, as is <b><i>text</b></i>.

Unescaped special characters. A bare < or & inside text breaks parsing. Use the predefined entities:

CharacterEntityWhen required
<&lt;Always in text and attribute values
&&amp;Always in text and attribute values
>&gt;Recommended; required in the sequence ]]>
"&quot;Inside double-quoted attribute values
'&apos;Inside single-quoted attribute values

For example, a URL in a sitemap must be written as <loc>https://example.com/?a=1&amp;b=2</loc>. Alternatively, wrap large blocks of text in a <![CDATA[ … ]]> section, where markup characters are not interpreted.

Unquoted attributes. Unlike HTML, XML requires quotes around every attribute value: <user id="42">, not <user id=42>.

Content before the XML declaration. If present, <?xml version="1.0" encoding="UTF-8"?> must be the very first thing in the file. Even a single space or blank line before it makes the document malformed.

Tips and best practices

  • Declare the encoding and save files as UTF-8 to avoid problems with accented characters.
  • Be careful when pretty-printing documents where whitespace is meaningful, such as mixed content or elements using xml:space="preserve"; adding line breaks can change the text value.
  • Use namespaces consistently: a prefix like soap: must be declared with an xmlns:soap attribute on the element or an ancestor.
  • Need to embed XML in a URL or a JSON string? Encode it first with the URL encoder or Base64 encoder.
Tip: Sitemaps are XML too. After checking that yours is well-formed, run your site through the SEO checker.

Frequently asked questions

Is HTML the same as XML?

No. HTML is more forgiving: it allows unclosed elements like <br>, unquoted attributes and case-insensitive tag names. XHTML is the variant of HTML that follows XML rules. To tidy ordinary web pages, use the HTML formatter instead.

Does formatting change my data?

Pretty-printing adds whitespace between elements, and minifying removes it. Element names, attributes and text content stay the same, but in documents where whitespace inside text is significant the extra indentation can matter.

Does this tool validate against an XSD schema?

No. It checks that the document is well-formed. Validation against a DTD or XSD requires the schema and a validating parser.

Why does my XML fail on an ampersand?

In XML, & always starts an entity reference. A bare ampersand, common in URLs and company names, must be written as &amp; or placed inside a CDATA section.

Copied to clipboard