How to format XML online
Formatting XML makes its nested structure visible without changing the meaning of the document. This guide explains how to beautify XML, what well-formedness means, and what to check when a parser reports an error.
Format a minified XML document
- Open the free XML formatter.
- Paste the document or upload the file from your device.
- Choose two spaces, four spaces, or tabs for indentation.
- Select Format XML.
- Copy, download, or open the clean result in a new tab.
A formatter adds whitespace between elements to expose parent-child relationships. It should preserve element names, attributes, namespaces, text nodes, comments, CDATA, and processing instructions.
What “well-formed XML” means
Before XML can be formatted safely, it must follow the core XML syntax rules. Every opening element needs the correct closing element, attribute values must be quoted, reserved characters must be escaped when used as text, and the document must have one root element.
Malformed
<order><item>Book</order>
Well-formed
<order> <item>Book</item> </order>
Common XML parsing errors
- Mismatched tags: an element closes with a different name or in the wrong nesting order.
- Unescaped characters: text contains a raw ampersand or less-than sign instead of an XML entity.
- Unquoted attributes: an attribute value is missing single or double quotation marks.
- Multiple root elements: two top-level elements appear without one containing root.
- Invalid namespace prefixes: a prefixed element is used without a corresponding namespace declaration.
XML validation versus formatting
Well-formedness validation checks basic XML syntax. Schema validation goes further by comparing the document with rules in an XSD or DTD. FreeFormatterr currently checks well-formedness; it does not claim that a document satisfies a particular business schema.
Choosing indentation
Two spaces produce compact output and work well for deeply nested API responses. Four spaces create stronger visual separation. Tabs let each reader control visual width in a compatible editor. The best choice is the convention used by your project or team.
Formatting SOAP, RSS, SVG, and namespaced XML
SOAP envelopes and many enterprise documents use namespace prefixes such as soap: or ns1:. RSS and Atom feeds contain repeated entries, while SVG stores vector graphics as XML. These documents can be formatted like other XML, but namespace declarations must remain in scope and must not be removed merely to shorten the output.
Ready to clean up your XML?
Use the free browser-based tool—no sign-up and no document upload.
Format XML now