XML Formatter, Beautifier & Validator
Pretty-print minified XML with your preferred indentation, validate well-formedness with exact line numbers, minify for transport and convert XML to JSON. Sitemaps, RSS feeds, SOAP envelopes, Android layouts and config files - all processed locally in your browser.
XML Formatter Workspace
Paste XML on the left. Switch between Beautify, Minify and XML → JSON. The validator reports the first error with its line and column.
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<!-- Autumn catalog -->
<product id="p-100" sku="TSHIRT-M">
<name>Organic Cotton T-Shirt</name>
<price currency="USD">24.90</price>
<tags>
<tag>apparel</tag>
<tag>organic</tag>
</tags>
<description><![CDATA[Soft & breathable <b>unisex</b> tee]]></description>
<stock warehouse="LHR">120</stock>
</product>
<product id="p-101" sku="MUG-01">
<name>Ceramic Mug</name>
<price currency="USD">12.00</price>
<tags/>
<stock warehouse="KHI">0</stock>
</product>
</catalog>Why Developers Use the Agenvix XML Formatter
A careful formatter that keeps your document semantically identical.
Faithful Pretty Printing
Declarations, DOCTYPE, comments, processing instructions and CDATA sections are preserved; elements with short text stay on one line for readability.
Real Validation
The browser's XML parser checks well-formedness - mismatched tags, unescaped ampersands, bad attributes - and the error message includes the line so you can jump straight to it.
XML to JSON
Convert documents to JSON with attributes prefixed by @, repeated elements collected into arrays and mixed text under #text - handy for APIs and quick inspection.
Private by Design
Invoices, SOAP payloads and config files never leave your machine. There is no upload, no account and no history.
Simple as 1-2-3
How the Formatter Works
Tokenise, validate, re-indent.
Paste XML
Minified feeds, API responses, exported settings - any XML, even slightly broken markup is formatted on a best-effort basis.
Choose Mode & Options
Beautify with 2/4 spaces or tabs, strip comments, minify, or convert to JSON.
Copy or Download
Copy the result or download .xml / .json. The status line confirms whether the document is well-formed.
How Each XML Construct Is Handled
Formatting, minifying and JSON conversion rules.
| Feature / Specification | Best Use Case | Engine / Output Standard | Privacy & Security | Performance Rating | Action |
|---|---|---|---|---|---|
| Elements & attributes | Document structure | Indented per depth | JSON: @attr keys | Core | |
| Text content | Values | Trimmed, inline when short | JSON: string or #text | Core | |
| <!-- comments --> | Documentation | Kept (optional strip) | Dropped by minify | Optional | |
| <![CDATA[ … ]]> | HTML / code payloads | Byte-for-byte preserved | JSON: text value | Core | |
| Declaration, DOCTYPE, PI | Headers | Preserved on own line | Not in JSON | Core |
Well-Formed XML and Readable Markup
1. Well-formed vs valid
Well-formed XML follows the syntax rules: one root element, every tag closed, attributes quoted, special characters escaped (&, <). Valid XML additionally conforms to a schema (XSD, DTD, RELAX NG). This tool checks well-formedness - the layer that breaks most feeds and API payloads - and reports the first offending line. Schema validation needs the schema itself and is out of scope here.
2. The errors you will actually see
The most common failures are an unescaped ampersand in a URL or title (& must be &), a mismatched closing tag, an attribute without quotes, text before the <?xml ?> declaration (including a UTF-8 BOM), and HTML-style void tags such as <br> that must be <br/> in XML.
Paste the document, read the line number in the status bar, fix that spot and re-validate.
3. Converting XML to JSON
XML and JSON do not map one-to-one: XML has attributes, ordered mixed content and namespaces. The conversion here uses a widely used convention - attributes become @name keys, repeated child elements become arrays, an element with only text becomes a string, and text next to child elements lands in #text. Namespace prefixes are kept as part of the key (for example atom:link).
4. Minify for production
Whitespace between elements is usually insignificant, so minified sitemaps, feeds and SOAP requests are smaller and faster to parse. Minify removes comments and inter-element whitespace but never touches text content or CDATA. If your schema treats whitespace as significant (rare, for example xml:space="preserve"), keep the formatted version.
Everything you need to know about formatting XML
Validation, options, JSON conversion and privacy.
How do I format XML online?
Paste your XML into the input, choose 2 or 4 spaces or tabs, and the beautified document appears instantly. Copy it or download an .xml file.
Does the formatter validate my XML?
Yes. It checks well-formedness with the browser's native XML parser and shows the first error with its line and column. Schema (XSD/DTD) validation is not performed.
Are comments and CDATA preserved?
Beautify keeps comments, CDATA, the XML declaration, DOCTYPE and processing instructions. You can strip comments with the toggle; minify removes comments by default.
How does XML to JSON handle attributes?
Attributes become keys prefixed with @ (for example "@id"), repeated child elements become arrays, text-only elements become strings and mixed text is stored under "#text".
Can I format a broken XML file?
Beautify works on a best-effort basis even when the document is not well-formed, so you can read it and find the problem. The validator will tell you where the first error is.
Is my XML sent to a server?
No. Formatting, validation and conversion all run in your browser; nothing is uploaded or stored.
Related Developer Utilities
Discover companion utilities engineered for zero-log speed and browser-side execution.
JSON Formatter & Validator
Prettify, format, repair syntax errors, and convert raw JSON data strings into trees.
XML Sitemap Generator
Turn a URL list into valid XML sitemaps with lastmod, auto-splitting and a sitemap index.
HTML Entity Encoder
Escape reserved HTML characters or resolve named and numeric entities back to plain text.
YAML to JSON / JSON to YAML Converter
Convert YAML to JSON and JSON to YAML with validation, multi-document support, key sorting and indent control.
SQL Formatter & Prettifier
Format and minify SQL for PostgreSQL, MySQL, SQLite, T-SQL, BigQuery, Snowflake and more with keyword casing and indent options.
Text Diff Checker
Compare two text blocks with LCS line matching, word level highlighting and similarity scoring.
More in Code & Data
Specialized utilities within the same technical domain
