TheTools.World tool
XML formatter online
Paste XML to add readable indentation based on element nesting. This is a lightweight formatter for already well-formed XML, not a full XML parser or validator.
Format XML
Paste XML to add readable indentation based on element nesting. This is a lightweight formatter for already well-formed XML, not a full XML parser or validator.
How to format XML
- Paste your XML into the box.
- Click Format XML.
- Review the indented result, checking nesting around any self-closing or namespaced elements.
- Copy the result or download it as an .xml file.
- If a section looks wrong, check that source XML for an unclosed or mismatched element.
This formatter uses the same tag-nesting indentation logic as the HTML formatter, adapted for XML's stricter tag-closing rules. It does not validate against a schema or DTD.
What this formatter does and how it works
The formatter puts each element on its own line and indents based on nesting depth, increasing the indent after an opening tag and decreasing it after the matching closing tag. Self-closing elements (like <item/>) and XML declarations (<?xml ...?>) don't affect the indent level. Because XML requires every element to be explicitly closed (unlike HTML, which allows some tags to be implicitly closed), this formatter is generally more reliable on XML than on loosely-written HTML.
Best practices
- Use it to make minified or single-line XML readable for review, debugging, or documentation.
- Check namespaced elements and attributes carefully after formatting, since this tool indents based on tag structure, not full namespace-aware parsing.
- Keep a copy of the original before formatting if the XML is from a system that's sensitive to exact whitespace (rare, but possible for some XML-based formats).
Common mistakes to avoid
- Expecting this to validate against an XML schema or DTD. It only reformats whitespace based on tag nesting; it does not check element or attribute validity against a schema.
- Assuming it will fix malformed XML. XML that isn't well-formed (unclosed tags, mismatched nesting) will format incorrectly, since the tool relies on tags being properly paired.
- Formatting XML that's sensitive to whitespace (rare, but some XML-based formats treat whitespace as significant data) without checking whether that matters for your use case first.
Real-world use cases
- Reading an API response or config file that came back as unformatted XML.
- Reviewing an RSS/Atom feed, SOAP payload, or sitemap.xml for debugging.
- Cleaning up XML pasted from a log or export before committing it to source code or documentation.
- Quick formatting during code review without a full XML tooling setup.
Limitations
This is a lightweight, pattern-based formatter, not a validating XML parser: it does not check well-formedness against XML rules, does not validate against a DTD or XML Schema, and does not resolve namespaces. Malformed XML (unclosed or mismatched elements) will produce incorrectly indented output rather than a clear validation error.
Privacy
XML you paste is processed locally in your browser. It is not sent to a server, logged, or stored. See the privacy policy for the site's full data handling approach.
Troubleshooting
- If indentation looks wrong from a certain point onward, check for an unclosed or mismatched element just before that point in your source XML.
- If self-closing elements cause odd indentation, confirm they end with
/>. - If you need HTML formatted instead, use the HTML formatter.
XML vs. JSON and HTML formatting
XML, JSON, and HTML are all structured, nested text formats, but each has its own syntax rules, so this site provides a dedicated formatter for each rather than one generic tool. XML requires every element to have an explicit closing tag (or be self-closing), which makes tag-nesting detection more reliable than for HTML, where some tags can be implicitly closed by the browser's own parsing rules. If your data is actually JSON dressed up as text, or HTML rather than XML, use the JSON formatter or HTML formatter instead for a cleaner result and more relevant validation notes.
Conclusion
Use this formatter to make well-formed XML readable for review and debugging. For JSON, use the JSON formatter; for HTML, use the HTML formatter.
Related tools
FAQ
Does this validate my XML?
No. It only reformats whitespace based on tag nesting. It does not validate well-formedness, schemas, or DTDs.
Will it fix malformed XML?
No. Unclosed or mismatched elements will produce incorrectly indented output since the formatter relies on tags being properly paired.
Does it understand XML namespaces?
It indents based on tag structure only and does not resolve or validate namespaces.
Is my XML uploaded anywhere?
No. Formatting happens locally in your browser, and your data is not sent to a server.