b2KIT

XML Validator & Formatter

Validate XML documents for well-formedness and format with configurable indentation.

Tested tool guide Tested browser tools Checked August 16, 2026

What XML Validator & Formatter does, with a checked example

This tool parses an XML document the way a strict XML reader would, checks it against the well-formedness rules of the XML 1.0 specification, and re-emits it with uniform indentation at a width you choose, in spaces or tabs. Paste a document and the result is either a formatted copy or an error naming the line and column of the first violation. The surprise most users hit: 'well-formed' is not the same as 'valid'. This tool checks syntax only. It cannot tell you whether your document conforms to a DTD or XSD schema, which is what schema-validating systems often mean by 'valid XML'.

Worked example

A concrete input and expected output from the current implementation.

Input

<library><book id="1"><title>XML in Action</title><author>Doe</author></book><book id="2"><title>Data on the Web</title></book></library>

Expected output

<library>
  <book id="1">
    <title>XML in Action</title>
    <author>Doe</author>
  </book>
  <book id="2">
    <title>Data on the Web</title>
  </book>
</library>

The document is well-formed, so the tool re-emits it: each nesting level adds two spaces of indent, and elements containing only other elements are split across lines. A malformed document such as <note>10 & 20</note> would instead return an error pointing at the '&', which must be written as &amp; in XML.

How the result is produced

1

Well-formedness check

Validated against the XML well-formedness constraints: one root element, matching start and end tags in correct order, quoted attribute values, no duplicate attributes, escaped reserved characters, and valid names. A document with no XML declaration is read as UTF-8, the specification's default. Checking stops at the first fatal error, so a single reported failure does not mean the rest of the document is correct; fix and re-run.

2

Formatting pass

When the document parses, the tool rebuilds it from its structure rather than editing the text. Indentation is applied from nesting depth at the width you choose, in spaces or tabs. Text content inside elements is kept as-is; whitespace that exists only between tags is replaced by the new indentation, which is why a reformatted document is not byte-identical to the original.

Good uses

  • Pasting a feed, config export, or API response that another system refuses to load, to find the malformed tag instead of debugging blind.
  • Re-indenting minified, single-line XML, common from build tools and generators, so a human can review the structure before commit or hand-off.
  • Checking XML assembled by string concatenation or templating before it is shipped, since hand-built XML is where unescaped ampersands and mismatched tags actually appear.

Limits and checks

  • Passing here does not mean 'valid' in the schema sense. There is no DTD, XSD, or Relax NG validation, so a document that passes can still be rejected by a validating consumer.
  • Only the first error is reported. Errors later in the document are masked until the earlier one is fixed, so expect to iterate.
  • Reformatting rewrites whitespace between tags. Where the consumer treats that whitespace as significant (some text-oriented pipelines and xml:space usage do), a formatted copy is not a safe drop-in replacement.

Common questions

Why does it accept my document when my own program rejects it?

The two likely differ in what they check. This tool verifies well-formedness: syntax, nesting, and quoting. Your program may additionally enforce a schema (DTD or XSD), namespace rules, or constraints such as unique IDs. Well-formed is necessary for valid but not sufficient, so compare against the schema your program uses rather than against this tool's answer.

Can it fix the errors it finds?

No. The formatter re-indents a document only after it parses; it never rewrites invalid syntax. An unescaped ampersand, a missing closing tag, or a duplicate attribute must be corrected in the source and the document re-submitted. The reported line and column point at where parsing stopped, which is usually close to the defect, but the fix is yours.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools