Skip to content
SmaftyTools

XML Formatter / Validator

Format XML into readable, indented markup or validate it for structural errors. Free online XML formatter and validator.

About XML Formatter / Validator

The XML Formatter / Validator pretty-prints compact XML into readable, indented markup, or checks whether an XML document is well-formed and reports exactly where it breaks. It's the XML equivalent of a JSON formatter, for the file format still underneath countless config files, SOAP APIs, RSS/Atom feeds, Android layouts and enterprise data exchanges.

Formatting is useful whenever XML arrives compacted onto one line — an API response, a minified config, or a feed pulled from a script — and needs indentation restored to actually review its structure. Validation is useful before that XML gets consumed by something stricter than a browser: confirming a hand-edited config file has matching tags before deploying it, or checking that generated XML from a script is well-formed before it's sent to an API that will reject anything malformed.

Formatting works by tokenizing on tag boundaries and indenting by nesting depth — a lightweight, dependency-light approach rather than a full DOM parse-and-rebuild, which means mixed content on a single line (like `<p>Hello <b>world</b>!</p>`) is kept together rather than split awkwardly across lines. Validation uses a dedicated XML parser to check well-formedness — matching tags, valid attribute syntax, a single root element — and reports the exact line and column of the first error found, the same class of check an XML parser in any programming language would perform before accepting the document.

One limitation worth knowing: because formatting works by splitting on `><` boundaries rather than fully parsing the document, a CDATA section that itself contains literal `><` sequences can format unexpectedly — if that happens, validate first to confirm the XML is well-formed, then review the formatted CDATA content manually. For everyday structured XML — nested elements, attributes, simple text content — both modes handle the common cases cleanly and run entirely in your browser.

How to Use the XML Formatter / Validator

  1. Paste XML into the input box.
  2. Choose Format to indent it, or Validate to check it's well-formed.
  3. Pick an indent size for Format mode.
  4. Fix any reported errors and copy the result.

Features

  • Pretty-print XML with configurable indent size
  • Validate well-formedness with exact line/column error reporting
  • Handles self-closing tags, comments and declarations
  • Fast, dependency-light structural formatting

Examples

Formatting a compact XML document

Input

<catalog><book id="1"><title>XML Basics</title><price>9.99</price></book></catalog>

Output

<catalog>
  <book id="1">
    <title>XML Basics</title>
    <price>9.99</price>
  </book>
</catalog>

Catching a mismatched closing tag

Input

<root><a>1</b></root>

Output

Error — closing tag mismatch (line 1, column 15).

Frequently Asked Questions

What does 'well-formed' mean for XML?

It means every tag is properly opened and closed (or self-closed), attributes are correctly quoted, and there's exactly one root element — the baseline structural rules any XML parser enforces before even checking against a schema.

Does this validate against a schema (XSD/DTD)?

No — it checks structural well-formedness only (matching tags, valid syntax), not conformance to a specific schema. For schema-level structural checks on JSON data, see the JSON Schema Validator.

Can formatting break CDATA sections?

In most cases no, but a CDATA section containing literal `><` characters can format unexpectedly, since the formatter tokenizes on tag boundaries rather than fully parsing the document. Validate first if you're unsure, then spot-check any CDATA content after formatting.

Is the XML Formatter / Validator free?

Yes, the XML Formatter / Validator is completely free with no usage limits. No signup, no account and no installation required.

Is my data safe?

Yes. All processing happens locally in your browser using JavaScript — nothing you type is uploaded or stored on our servers.