XML Formatter & Minifier
Format, minify, validate and run XPath on XML online: SOAP, SVG, RSS/Atom, XSD/XSLT, Maven POM, sitemaps and Spring/Android config, with CDATA-safe minify.
XML Formatter & Validator - Format and Validate XML Online
A powerful online XML formatter and validator tool that helps you format, beautify, minify, and validate XML data. Features syntax highlighting, error detection, and various formatting options. Perfect for developers, API testers, and anyone working with XML data.
What is XML?
XML (eXtensible Markup Language) is a markup language that defines rules for encoding documents in a format that is both human-readable and machine-readable. XML is used for:
- Data storage and transmission
- Configuration files
- Web services and APIs (SOAP)
- Document formats (SVG, RSS, Atom)
- Data interchange between systems
- Structured data representation
Unlike HTML which is designed for displaying data, XML is designed for storing and transporting data. It's self-descriptive and allows you to create custom tags to describe your data structure.
What does this XML Formatter do?
This tool provides three main functions:
1. Format (Beautify): Takes compressed or poorly formatted XML and makes it readable with proper indentation and line breaks. You can choose indent size (2, 4, or 8 spaces, or tabs) and optionally preserve or remove comments.
2. Minify: Removes all unnecessary whitespace and line breaks to create the smallest possible XML file. Optionally removes comments. Useful for reducing file size in production.
3. Validate: Checks if your XML syntax is correct and identifies any errors. If errors are found, it shows detailed error messages to help you fix them.
All functions include syntax highlighting for better readability.
How do I validate XML?
Validating XML is simple:
1. Paste or type your XML in the input field
2. Click the 'Validate' button
3. View the validation result
The validator checks for:
- Proper tag nesting and closure
- Valid XML declaration
- Correct attribute syntax
- Well-formed structure
- Special character encoding
If validation passes, you'll see a green success message. If there are errors, you'll see a detailed error message explaining what went wrong and where the problem is.
Note: This validator checks for well-formedness, not validity against a schema (DTD or XSD).
What's the difference between well-formed and valid XML?
There are two levels of XML correctness:
Well-formed XML:
- Has a root element
- All tags are properly closed
- Tags are properly nested
- Attribute values are quoted
- Special characters are escaped
- Case-sensitive tag matching
This tool checks for well-formedness.
Valid XML:
- Is well-formed AND
- Conforms to a specific schema (DTD or XSD)
- Has correct data types
- Follows structural rules defined in schema
To check validity against a schema, you need specialized XML validators. This tool focuses on ensuring your XML is well-formed, which is the first requirement for any XML document.
What does 'Preserve comments' mean?
The 'Preserve comments' option controls whether XML comments are kept or removed:
With preserve comments (checked):
<?xml version="1.0"?>
<!-- This is a comment -->
<root>
<item>Value</item>
</root>
Without preserve comments (unchecked):
<?xml version="1.0"?>
<root>
<item>Value</item>
</root>
When to preserve:
- During development and debugging
- When comments contain important documentation
- When working with configuration files
When to remove:
- In production to reduce file size
- When comments are not needed
- For data transmission
Note: When minifying, unchecking this option provides maximum size reduction.
Common XML errors and how to fix them
Common XML syntax errors include:
1. Unclosed tags:
Wrong: <tag>Content
Right: <tag>Content</tag>
2. Mismatched tags:
Wrong: <tag>Content</Tag>
Right: <tag>Content</tag>
3. Improper nesting:
Wrong: <a><b></a></b>
Right: <a><b></b></a>
4. Unquoted attributes:
Wrong: <tag attr=value>
Right: <tag attr="value">
5. Special characters not escaped:
Wrong: <tag>5 < 10</tag>
Right: <tag>5 < 10</tag>
6. Multiple root elements:
Wrong: <root1/><root2/>
Right: <root><root1/><root2/></root>
This validator helps you identify and fix all these errors with clear error messages.

Is my XML data safe?
Yes, your data is completely safe and private. This tool:
- Processes all XML entirely in your browser
- Does not send any data to our servers
- Does not store or log any of your XML
- Works offline once the page is loaded
- Does not use any external services
You can even disconnect from the internet after loading the page and the tool will still work perfectly. Your XML data never leaves your computer.
How do I run an XPath query on XML?
Paste your XML, type an XPath expression in the XPath Query box, then click 'Run XPath'. The tool parses the document with the browser's native XPath engine and lists every matching node.
Examples:
- //item/title — every <title> inside an <item> (RSS/Atom feeds)
- //*[@id='main'] — any element with id="main"
- //book[price>35]/title — conditional selection
- //ns:Body — works with the document's default namespace
Each match is serialized back to XML (for element nodes) or shown as its text/value (for attributes and text nodes), with the total match count. This is ideal for extracting fields from large SOAP responses, configuration files, and feeds without writing code.
Does minify preserve CDATA and processing instructions?
Yes. The minifier protects <![CDATA[...]]> sections before collapsing whitespace, then restores them byte-for-byte. This is important because CDATA can hold scripts, embedded markup, or pre-formatted text where newlines and spacing are significant — a naive minifier would corrupt that data.
The XML declaration and DOCTYPE are kept intact, and attribute values that contain a '>' character (e.g. expr="a > b") are handled correctly when formatting or minifying, so well-formed tags are never truncated. Comments are removed during minify unless you check 'Preserve comments'.
Why does my XML with > in an attribute fail to format?
A '>' inside a quoted attribute value — for example <node expr="a > b"/> — is perfectly well-formed XML, but naive formatters scan for the first '>' and stop there, truncating the tag and garbling the output. This tool tracks quote state while scanning, so it only treats an unquoted '>' as the end of a tag. Your attributes containing '>' (common in XSLT, MathML, and condition expressions) will format and minify correctly.
How do XML namespaces and prefixed elements work here?
XML namespaces qualify element and attribute names to avoid collisions, using either a default namespace (xmlns="...") or a prefix (xmlns:ns="..."). Prefixed elements look like <ns:Envelope> — common in SOAP, SVG, and Atom.
For formatting, minifying, and validating, namespaces are treated as part of the markup and preserved exactly. For XPath, this tool provides a resolver based on the document's root element, so queries against the default namespace resolve correctly. For heavily prefixed documents you may need to match local names (e.g. //*[local-name()='Body']) since custom prefix-to-URI mapping is not configurable in the browser's basic resolver.
Can I format large XML files?
Yes, this tool can handle large XML files efficiently. It uses optimized browser-based parsing and doesn't have artificial size limits.
Tips for large files:
- Formatting large files may take a moment - be patient
- Minifying is generally faster than formatting
- Very large files (>10MB) may slow down syntax highlighting
- Consider breaking extremely large XML into smaller chunks if possible
For files larger than 50MB, you may want to use command-line tools like xmllint for better performance, but this online tool works well for most use cases.
Key Features
- Format XML with customizable indentation (2, 4, 8 spaces, or tabs)
- Minify XML to reduce file size for production
- Validate XML syntax with detailed error messages
- Run XPath queries to locate and extract matching nodes
- CDATA-safe minify and correct handling of '>' in attributes
- Preserve or remove comments option
- Syntax highlighting for tags, attributes, values, and comments
- Real-time statistics (characters, lines, size)
- Copy formatted XML to clipboard
- Download formatted XML as .xml file
- Upload XML files for formatting
- Dark mode support
- No file size limits
- 100% client-side processing - your data never leaves your browser
- Works offline after initial load
- Mobile-friendly responsive design
