# XML Formatter

Format, beautify and minify XML with configurable indent. Preserves comments and CDATA

> Canonical page: https://test.elysiatools.com/en/tools/xml-formatter

- **Category:** Format Conversion

- **Keywords:** xml, formatter, beautify, pretty print, minify, xml formatter, xml beautifier, indent

## Overview

Parses XML with xmldom, reports malformed input as an error, and re-serializes it in beautified or minified form. Comments, CDATA, processing instructions, and attributes are preserved by default. Collapse Whitespace is enabled by default and can change significant whitespace inside text nodes, so disable it for mixed-content documents where spacing matters.

## Inputs

- **XML Input** (textarea): Enter your XML here...
- **Indent Size** (number): Enter indent size (0-8)
- **Mode** (select)
- **Preserve Comments** (checkbox)
- **Collapse Whitespace** (checkbox)

## When to use

- When you receive a minified or single-line XML file that is difficult to read or debug.
- When you need to reduce the file size of XML data for network transmission or storage.
- When you want to enforce consistent indentation standards across your project's XML files.

## How it works

- Paste your XML content into the 'XML Input' field.
- Select 'Beautify' in the 'Mode' dropdown to add indentation, or 'Minify' to remove it.
- Adjust the 'Indent Size' (0-8) if you chose 'Beautify' to set your preferred spacing.
- Toggle 'Preserve Comments' or 'Collapse Whitespace' as needed, then view the formatted output.

## Use cases

- Preparing configuration files for readability by manually adjusting indentation levels.
- Compressing XML payloads for API responses by switching to 'Minify' mode.
- Cleaning up auto-generated XML exports that lack consistent formatting.

## Frequently asked questions

### Does this tool remove comments?

No, you can choose to keep or remove comments using the 'Preserve Comments' checkbox.

### Can I change the indentation size?

Yes, you can set the 'Indent Size' to any value between 0 and 8 spaces.

### What is the difference between Beautify and Minify?

Beautify adds line breaks and indentation for readability, while Minify removes all unnecessary whitespace to create a compact, single-line string.

### Does Collapse Whitespace change text content?

Yes. It compresses runs of whitespace inside text nodes; disable it for mixed-content XML where spaces are significant.

## Related tools

- [XMP Metadata Extractor](https://test.elysiatools.com/en/tools/image-xmp): Extract and view XMP metadata from images including Adobe Photoshop, Lightroom, and Creative Cloud information
- [JSON Formatter](https://test.elysiatools.com/en/tools/json-formatter): Format and validate JSON data
- [TOML Formatter](https://test.elysiatools.com/en/tools/toml-formatter): Format and beautify TOML. Note: comments are lost and key order may change (@iarna/toml limitation)
- [YAML Formatter](https://test.elysiatools.com/en/tools/yaml-formatter): Format and beautify YAML. Note: comments are lost (js-yaml limitation)
- [CSV to XML Converter](https://test.elysiatools.com/en/tools/csv-to-xml): Convert CSV data to XML format with customizable formatting options
- [JSON to XML Converter](https://test.elysiatools.com/en/tools/json-to-xml): Convert JSON data to XML format with customizable formatting options
- [Text to XML Converter](https://test.elysiatools.com/en/tools/text-to-xml): Convert various text formats to XML with customizable structure and formatting options
- [CSS Beautifier](https://test.elysiatools.com/en/tools/css-beautifier): Format and beautify minified or messy CSS code into readable, well-indented stylesheets

## Samples

- [Nginx Log Parser Samples](https://test.elysiatools.com/en/samples/nginx-log-samples): Comprehensive Nginx log samples for testing log-parser tool, including access logs and error logs with various formats and scenarios
- [Text Case Format Samples](https://test.elysiatools.com/en/samples/text-case-formats): Examples of different text case formats: camelCase, snake_case, kebab-case, PascalCase, and more
- [Android Serialization Java Samples](https://test.elysiatools.com/en/samples/android-serialization-java): Android Java serialization examples including JSON serialization, deserialization, and XML parsing
- [Android Serialization Kotlin Samples](https://test.elysiatools.com/en/samples/android-serialization-kotlin): Android Kotlin serialization examples including JSON serialization, deserialization, and XML parsing

## Related content

- [Podcast Episode Audio and RSS Publication Preflight](https://test.elysiatools.com/en/hubs/podcast-episode-rss-publication-preflight): Check one finished podcast episode against its RSS entry, verify final-file size, type and duration, and separately test public media access and player behavior before publication.
- [Code Minify, Beautify, and Format Tools](https://test.elysiatools.com/en/hubs/code-minify-beautify-format-tools): Prepare code and markup for review or delivery with readable formatting, compact output, and preservation checks.
