XML Formatter & Validator

Check XML is well formed, get the failing line when it is not, and see it re-indented with consistent structure.

Parsing and formatting run entirely in your browser. Comments are not preserved in the formatted output, since formatting works by parsing and re-emitting the document.

What It Does

Paste XML and this tells you whether it is well formed, points at the line if it is not, and shows it re-indented so the structure is actually readable. Well-formedness is a narrow but essential bar: balanced and properly nested tags, exactly one root element, quoted attribute values, and the five special characters escaped. Most XML that fails in production fails one of those, and the commonest culprit by a wide margin is a bare ampersand from a URL that was pasted into an attribute without escaping. Alongside the verdict the tool reports what the document actually contains — how many elements, how deep it nests, whether namespaces or CDATA are in play — because that is usually the context you need before deciding what to do about an error.

When to Use It

  • An API returned XML on one enormous line and you need to see its structure before you can work out what it contains.
  • A feed or configuration file is being rejected as malformed and you need the line number rather than a generic parse failure.
  • You are debugging a SOAP payload and want the nesting laid out clearly to find the element you actually care about.
  • A document was assembled by string concatenation and you suspect an unescaped character from a URL has broken it.
  • You want to check the depth and element count of a document before writing code that walks it.

Worked Examples

<catalog><book id="1"><title>XML Basics</title><author>Jane Doe</author></book></catalog>

Valid but unreadable on one line, which is how XML usually arrives from an API. Formatting reveals the nesting and the tool reports the element count and depth.

<link href="https://example.com/page?a=1&b=2"/>

The classic failure. The bare ampersand joining the query parameters starts an entity reference that never terminates, so the document is not well formed — it needs to be written as &amp;.

<root><Item>one</item></root>

A case mismatch. XML is entirely case-sensitive, so <Item> and </item> are different names and the document is malformed even though it looks fine at a glance.

Features

Well-formedness checking with the failing line reported
Consistent re-indentation at your chosen width
Unescaped ampersand and entity errors identified
Element
attribute and text node counts
Maximum nesting depth reported
Namespace prefixes detected
CDATA sections detected and flagged
Handles documents arriving on a single line
One-click copy of the formatted result
Runs entirely in your browser

How to Use

1. Paste your XML into the input box. 2. The verdict appears immediately, with the line number if it is malformed. 3. The formatted version appears below with consistent indentation. 4. Adjust the indent width to match your project's style. 5. Copy the result, noting that comments are not carried through.

Common Mistakes

  • Leaving an ampersand unescaped. A URL in an attribute is the usual source, and a bare & is invalid XML no matter how obviously it was meant literally.
  • Assuming tag names are case-insensitive. They are not, and a mismatch is often reported at the closing tag far from where the real mistake is.
  • Building XML by concatenating strings. Any value containing a special character breaks the document, which is exactly why every language ships an XML writer.
  • Confusing well-formed with valid. Passing here means the syntax is correct; it says nothing about whether the document matches the schema a consumer expects.
  • Pasting formatted output back over a source file with comments. Structural reformatting parses and re-emits, so comments do not survive.

Frequently Asked Questions

Explore related topics

#Formatter #Validator