JSON

XML Formatter & Validator

Indent XML and check whether it is well-formed, directly in your browser.

Ctrl/Cmd+Enter to format

XML input

Result

Paste or type some XML to begin

Namespaces, comments, CDATA and mixed content are preserved. This checks well-formedness only — it does not validate against a schema.

XML is checked and formatted locally in your browser. Input and output are not uploaded, saved to browser storage, or included in analytics events. Documents containing a DOCTYPE or ENTITY declaration are rejected without being parsed.

Your data stays private

This tool runs directly in your browser. The content you enter is processed locally and is not sent to TechFixGen servers. No account or signup is required.

XML Formatter & Validator, explained

What does the XML Formatter do?

XML is the markup behind RSS and Atom feeds, SVG icons, sitemaps, configuration files and countless document exchange formats. Hand-edited XML quickly becomes a wall of lines with no consistent indentation, which makes a structural mistake hard to spot.

This tool parses your XML with your own browser’s parser and prints it back with clean indentation. Validation runs live as you type, and Format rewrites the document on demand. Both happen entirely in your browser.

How to format XML

  1. Paste or type the XML you want to tidy up, or press Load sample.
  2. Choose an indentation width: 2 spaces or 4 spaces.
  3. Press Format (or Ctrl/Cmd + Enter) to rewrite it.
  4. Read the result in the output panel and press Copy.
  5. If the document is malformed, the error alert quotes what your browser’s parser reported and gives the line and column when it supplied one.

What formatting preserves

  • The XML declaration, copied from your source exactly as you wrote it rather than regenerated.
  • Namespace prefixes and declarations, including prefixed attributes such as xsi:type, in their original order.
  • Comments, CDATA sections and processing instructions such as <?xml-stylesheet?>.
  • Self-closing tags, which stay self-closing.
  • Mixed content — an element that mixes text with child elements is left on one line so its text is never reflowed.

What formatting changes

XML treats whitespace between tags as character data, which has one consequence worth understanding before you run Format on a document that has no indentation at all:

Indenting <a><b>x</b></a> puts <b> on its own line, indented beneath <a>, and that new whitespace becomes part of the element’s text content. That is what “format” means here, and it is safe for documents that already use whitespace between elements. If yours does not — a feed squeezed onto one line, for example — check that nothing depends on the exact text content before formatting.

What never changes is your visible text. Every text node that is not formatting whitespace is printed back character for character, and two smaller normalisations are applied on the way:

  • References are re-escaped canonically, so A prints as A and &apos; prints as a plain apostrophe. The characters are the same.
  • An empty element is printed self-closed, so <b></b> becomes <b/>. Both mean the same thing.

Attributes always stay on the same line as their element, because XML itself does not define where the whitespace inside a tag belongs.

What validation checks — well-formedness only

Validation checks that the document is well-formed: one root element, every tag closed and matched, every attribute quoted, every entity declared, every character legal. That is a structural check of the text itself.

It is not a schema check. There is no XSD validation, no DTD validation and no namespace validation, so a document can be reported as well-formed while still being wrong for your particular schema — a missing required field, a misspelled element name or an unexpected value will all pass. For that, convert the document with the XML to JSON converter and validate the result against a schema.

The wording and the position in the error alert come from your own browser, so they can differ between Chrome, Edge, Firefox and Safari, and some reports omit a position entirely. Nothing is sent anywhere to produce them.

Why DOCTYPE and ENTITY are rejected

A document type declaration can define entities, and an entity can point at a URL. That is the same mechanism behind the billion-laughs and XXE attacks, so a document containing <!DOCTYPE> or <!ENTITY> is refused outright: this tool never parses it, never expands an entity and never opens a network request. If your feed or config genuinely needs a DTD, keep it and validate it with a tool you control.

Common XML errors

  • Mismatched or unclosed tags

    A closing tag does not match the element it is meant to close, or a tag is opened and never closed. XML has no optional end tags.

    Fix: Check the exact spelling and case of both tags. <Item> and </item> are different tags.

  • Unquoted attribute value

    An attribute value is written bare, such as href=/docs, so the parser reads / as the end of the value.

    Fix: Quote every attribute value: href="/docs".

  • More than one root element

    Two top-level elements were written side by side. A document must contain exactly one root element.

    Fix: Wrap them in a single parent element, or split them into separate documents.

  • Undeclared or unescaped entity

    A bare & or an entity such as &nbsp; appears in text. XML only predefines &amp; &lt; &gt; &quot; and &apos; — anything else must come from a DTD.

    Fix: Escape it as &amp;, or use a numeric reference such as &#160;.

  • Invalid character in the document

    A control character that XML forbids, or a raw character such as a curly quote copied from a word processor.

    Fix: Remove control characters. Replace smart quotes and dashes with plain ASCII, or encode them as numeric character references.

Privacy

Parsing and formatting run locally in your browser. The XML you paste is never uploaded to TechFixGen servers, is not written to browser storage, and is not included in analytics events — no account or signup is required.

Frequently asked questions

Does this validate against an XSD?

No. This tool performs a well-formedness check only. There is no XSD validation, no DTD validation and no namespace validation. A document can be reported as well-formed and still be wrong for your schema, because a missing required field, a misspelled element name or an unexpected value are all structurally legal XML. Convert the document to JSON and validate it against a schema if you need that level of checking.

What does well-formed actually mean?

It means the text is readable as XML: exactly one root element, every start tag closed by a matching end tag with the same name and case, every attribute value quoted, every entity declared, and every character legal. That is a check of the markup itself, not of whether your data makes sense.

Does this upload my XML?

No. Parsing, validation and formatting all run locally in your browser. Your XML is never uploaded to TechFixGen servers, is not saved to browser storage, and is not included in analytics events.

Will formatting change my text content?

Whitespace between elements is character data in XML, so indenting a document that has no inter-element whitespace does add whitespace to its text content. That is what formatting means here. No visible text is ever altered, reordered or reflowed: every text node that is not formatting whitespace comes back character for character.

Are comments, CDATA and processing instructions preserved?

Yes, all three. Comments are printed back as comments, CDATA sections stay CDATA so their raw markup is not re-escaped, and processing instructions such as <?xml-stylesheet?> keep their target and data.

Why are mixed-content elements left on a single line?

Because adding a line break next to real text would insert a newline into that text. An element such as <p>Hello <b>world</b>!</p> mixes character data with child elements, so it is left exactly as written and only its child elements are formatted in turn. Prose is never re-wrapped.

Are namespaces and prefixes preserved?

Yes. Namespace declarations such as xmlns and xmlns:atom, prefixed element names, and prefixed attributes such as xsi:type are all printed back with their original prefixes and in their original order. The formatter never renames, adds or removes a namespace.

Is the XML declaration preserved?

Yes, exactly as you wrote it, including its encoding attribute and any byte-order mark. It is copied from your source text rather than regenerated, so an unusual or older declaration survives untouched.

What happens with DOCTYPE and ENTITY declarations?

They are refused before parsing begins. A DTD can declare entities, and an entity can reference a URL, which is the mechanism behind billion-laughs and XXE attacks. The document is never parsed, no entity is ever expanded and no network request is ever made. Keep the declaration and validate it with a tool you control if you genuinely need one.

Which indentation width should I use?

Two spaces is the common convention for feeds, sitemaps and config files. Four spaces is easier to spot by eye in deeply nested documents. Either is fine — what matters is that the document ends up consistent, since a file with mixed indentation is itself a common source of bugs.

Why is the error message different from another tool's?

The message and the line and column come from your own browser's XML parser, because that is what reads the document — the tool never sends it anywhere to be checked. Chrome, Edge, Firefox and Safari word their reports differently, and some omit a position entirely. The surrounding guidance is the same in every browser.

Can this fix my XML automatically?

No. It explains the error and points at the line and column when your browser supplies one, but it never rewrites your data to make it parse. Correcting the input by hand is the safe, predictable way to resolve a syntax problem.