XML Formatter & Validator
Paste XML, click Format to prettify with proper indentation, or Validate to check syntax. Handles attributes and namespaces. Runs in your browser — no upload.
- Paste your XML into the left textarea.
- Click Format to round-trip through fast-xml-parser and produce indented XML.
- Click Validate to check well-formedness without modifying the input.
- Errors point at the offending position in the document.
What does it do?
Parses XML with fast-xml-parser and re-emits it with consistent indentation. Attribute order is preserved within each element; element nesting is preserved exactly. Mixed content (text + child elements) and namespaces (prefix:tag) are kept intact. The output is well-formed XML — but well-formed is not the same as valid (validity requires a schema or DTD, which this tool does not check).
Example
Messy XML input:
<root version="1"><name>Ada</name><tags>math</tags><tags>logic</tags></root> Formatted output:
<root version="1">
<name>Ada</name>
<tags>math</tags>
<tags>logic</tags>
</root> Common XML errors and how to fix them
XML well-formedness rules are stricter than HTML. The patterns below cover most parser failures.
- Unclosed tag. `<a><b></a>` is invalid — `<b>` must be closed (`<b/>` or `</b>` somewhere). XML does not allow HTML-style optional close tags.
- Mismatched case. XML is case-sensitive — `<Foo></foo>` is two different tag names. Match the case exactly.
- Unescaped special characters. A literal `<`, `>`, `&`, or quote inside text or an attribute value must be escaped: `<`, `>`, `&`, `"`. Wrap data with these characters in CDATA: `<![CDATA[...]]>`.
- Multiple roots. XML requires exactly one root element. `<a/><b/>` at the top level is invalid — wrap them: `<root><a/><b/></root>`.
- Invalid element name. Element names cannot start with a digit, contain spaces, or use reserved characters (`< > & " \'`). Names starting with `xml` (any case) are reserved by the spec.
- Mismatched quotes around attributes. `<a name="value\'>` mixes double and single quotes. Pick one style consistently per attribute. Either is valid XML.
Frequently asked questions
Does formatting change my data?
Only whitespace between elements. Element order, attribute order, attribute values, text content, and CDATA framing are preserved. Self-closing form (`<x/>`) and explicit form (`<x></x>`) may normalize.
Are XML comments preserved?
fast-xml-parser drops comments by default. If you need comment-preserving formatting, use a different tool (the XSLT identity transform, for example, or `xmllint --format`).
Does this validate against a schema?
No. This checks well-formedness only — that the document parses as syntactically valid XML. Schema validation (XSD, DTD, RelaxNG) is a separate step that requires the schema as an additional input.
How are namespaces handled?
Namespace prefixes are kept as part of the element name (`x:foo`). Default namespace declarations and prefix bindings are preserved as attributes. Namespace-aware processing (URI resolution) is not performed.
Is my XML uploaded?
No. Everything runs in your browser — your input is parsed and re-serialized by JavaScript on this page and never sent to any server.
Can I customize the indentation?
Currently fixed at 2 spaces per level. To customize, run fast-xml-parser on the command line — same library — and pass `{ indentBy: " " }` or any other string.