# XML Formatter

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

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

- **Category:** Format Conversion

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

## Overview

The XML Formatter is a utility tool designed to format, beautify, and minify XML data. It allows you to configure indent sizes, toggle between beautification and minification modes, preserve comments, and collapse whitespace while keeping CDATA sections intact.

## 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 need to clean up unformatted, single-line XML payloads received from APIs or web services for easier debugging.
- When you want to reduce the file size of XML configuration files by minifying them and removing unnecessary whitespace.
- When you need to format complex XML structures with custom indentation while preserving critical CDATA sections and developer comments.

## How it works

- Paste your raw XML data into the XML Input text area.
- Select the desired mode (Beautify or Minify) and configure options like Indent Size, Preserve Comments, and Collapse Whitespace.
- Click the format button to process the XML and instantly view or copy the structured output.

## Use cases

- Beautifying minified SOAP API responses to inspect payload structures and troubleshoot integration errors.
- Compressing Android layout XML files or Maven pom.xml files to minimize deployment package sizes.
- Formatting configuration files with custom indentation to maintain clean, readable codebases in version control.

## Frequently asked questions

### Can I format XML without losing my comments?

Yes, enable the 'Preserve Comments' option to keep all XML comments intact during formatting.

### What indentation sizes are supported?

You can configure the indent size anywhere from 0 to 8 spaces.

### Does this tool support minification?

Yes, switch the Mode option to 'Minify' to strip out unnecessary whitespace and compress your XML.

### Will my CDATA sections be modified?

No, the formatter preserves CDATA sections to ensure your data integrity is maintained.

### What does the Collapse Whitespace option do?

It removes redundant spaces, tabs, and newlines within text nodes while keeping the XML structure valid.

## Related tools

- [XMP Metadata Extractor](https://elysiatools.com/en/tools/image-xmp): Extract and view XMP metadata from images including Adobe Photoshop, Lightroom, and Creative Cloud information
- [JSON Formatter](https://elysiatools.com/en/tools/json-formatter): Format and validate JSON data
- [TOML Formatter](https://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://elysiatools.com/en/tools/yaml-formatter): Format and beautify YAML. Note: comments are lost (js-yaml limitation)
- [CSV to XML Converter](https://elysiatools.com/en/tools/csv-to-xml): Convert CSV data to XML format with customizable formatting options
- [JSON to XML Converter](https://elysiatools.com/en/tools/json-to-xml): Convert JSON data to XML format with customizable formatting options
- [Text to XML Converter](https://elysiatools.com/en/tools/text-to-xml): Convert various text formats to XML with customizable structure and formatting options
- [CSS Beautifier](https://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://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://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://elysiatools.com/en/samples/android-serialization-java): Android Java serialization examples including JSON serialization, deserialization, and XML parsing
- [Android Serialization Kotlin Samples](https://elysiatools.com/en/samples/android-serialization-kotlin): Android Kotlin serialization examples including JSON serialization, deserialization, and XML parsing

## Related content

- [XML Conversion, Mapping, and XPath Tools](https://elysiatools.com/en/hubs/xml-convert): Curated tools for XML conversion, mapping, merging, and XPath extraction in one hub.
- [Text Redaction, Highlighting, and Presentation Formatting Tools](https://elysiatools.com/en/hubs/text-format): Compare tools for masking sensitive text, finding PII, normalizing phone numbers, highlighting phrases, centering text, and formatting diffs in one hub.
- [JSON Formatting, Diff, and Normalization Tools](https://elysiatools.com/en/hubs/json-format): Compare JSON formatting, diffing, log review, config comparison, and data-normalization tools in one hub for readable and reviewable JSON workflows.
