XML Formatter
Paste XML or open a file to beautify, minify or validate it. Errors are reported with the line and column, comments and CDATA are kept, and text content is never changed.
Everything runs in your browser. Files you open are read locally and never uploaded.
How to use the XML Formatter
- Paste your XML into the input box, open an .xml file, or press Sample.
- Press Format XML and choose 2 spaces, 4 spaces or tabs. The output updates as you type.
- Check the status bar. A green tick means the XML is well-formed. Otherwise you get the error message with its line and column; press Go to error to jump there.
- Press Minify to remove indentation and line breaks between tags, optionally removing comments.
- Switch to Tree to fold elements and click any node to see its path, then copy or download the result.
How the formatter keeps your data intact
Many online beautifiers re-flow every text node, which silently changes data. This XML formatter follows four rules so the output means exactly the same as the input:
- Only whitespace between tags is changed. Gaps made purely of spaces and line breaks between elements are replaced by consistent indentation.
- Text stays inline. An element that contains only text, such as
<price>44.95</price>, is printed on one line with its text untouched. - Mixed content is left alone. In
<p>An <b>in-depth</b> look</p>the spaces around<b>are part of the text, so the whole element is kept on one line exactly as written. - xml:space="preserve" is respected, and comments, CDATA sections, processing instructions and the DOCTYPE are copied verbatim.
Before and after
Input:
<order id="7"><item sku="A1"><name>Lamp</name><qty>2</qty></item><!-- gift --></order>
Formatted with 2 spaces:
<order id="7">
<item sku="A1">
<name>Lamp</name>
<qty>2</qty>
</item>
<!-- gift -->
</order>
Common XML errors and how to fix them
| Error message | Typical cause | Fix |
|---|---|---|
| Opening and ending tag mismatch | Tags closed in the wrong order, or a typo in a closing tag | Close the innermost element first: <a><b></b></a> |
| Extra content at the end of the document | More than one root element | Wrap everything in a single root element |
| Entity 'nbsp' not defined | HTML entities used in XML | Use   or declare the entity in a DTD |
| xmlParseEntityRef: no name | A bare & in text or an attribute | Write & or wrap the text in CDATA |
| AttValue: " or ' expected | Attribute value without quotes | Quote every value: id="5" |
| XML declaration allowed only at the start | Spaces, a blank line or a second <?xml ?> before the declaration | Make <?xml ... ?> the very first characters of the file |
Frequently asked questions
What does an XML formatter do?
It re-indents XML so that each nested element starts on its own line with consistent indentation, making the structure easy to read. It only changes whitespace between tags; element names, attributes, text, comments and CDATA sections stay the same.
Does formatting change my data?
No. Whitespace-only gaps between elements are re-indented, but text content is kept exactly as written. Elements with short text, such as <name>Bob</name>, stay on one line, and mixed content (text with inline tags) and elements with xml:space="preserve" are left untouched.
How do I validate XML?
Paste the XML and look at the status bar. The validator uses your browser's XML parser to check that the document is well-formed: one root element, every tag closed and correctly nested, quoted attributes and valid entities. If not, it shows the first error with the line and column.
Does this check my XML against a schema (XSD or DTD)?
No. It checks well-formedness, which is what most parsers require first. Validating against an XSD or DTD needs a schema-aware validator such as xmllint or an IDE.
Why do I get an error about an undefined entity like ?
XML only predefines five entities: &, <, >, " and '. HTML entities such as or © are not valid in plain XML unless a DTD declares them. Use a numeric reference instead, for example   for a non-breaking space.
What is the difference between formatting and minifying XML?
Formatting adds line breaks and indentation for people to read. Minifying removes that whitespace between tags to make the file smaller for storage or transfer. Both keep the same data.
Is my XML uploaded to a server?
No. Parsing, formatting and validation all run in your browser, and files you open are read locally.