Free Online XML Formatter — Five XML Tools in One
This page provides five browser-based XML utilities accessible from the left sidebar. Every tool runs entirely in your browser using the built-in DOMParser — nothing is uploaded, nothing is stored, and no account is required. Choose a tool from the sidebar, paste your XML, and the output appears automatically.
XML Formatter
Prettifies and validates XML with 2-space, 4-space, or tab indentation. Preserves the XML declaration, all attributes, CDATA sections, and namespace prefixes. Shows the exact parse error for invalid input.
XML Minifier
Strips all inter-element whitespace and comments from XML, producing the smallest possible well-formed XML string. Ideal for API payloads, configuration files, and data storage.
XML Validator
Checks XML well-formedness using the browser native parser. Reports root element, child count, encoding, and declaration presence for valid input, or the exact error for invalid input.
XML to JSON
Converts well-formed XML to a structured JSON object. Element names become keys, text content becomes values, repeated elements become arrays, and attributes are grouped under @attributes.
XML Escape
Escapes the five XML reserved characters — & < > " and ' — so plain text can be safely embedded inside XML element content or attribute values.
Online XML Formatter — Prettify XML with Indent Control
API responses, configuration files, and data feeds are frequently delivered as compact single-line XML that is almost impossible to read or debug. The XML Formatter takes that compressed input and restructures it with your chosen indent size — 2 spaces, 4 spaces, or a real tab character. The output updates automatically as you type, so you see a formatted result immediately without pressing any button.
How the XML Formatter Works
The formatter uses the browser built-in DOMParser to parse the input as application/xml. If the document is well-formed, a custom recursive serialiser walks the DOM tree and rebuilds the XML string with correct indentation at each nesting level. Text-only elements are kept on a single line. Elements with child elements are expanded across multiple lines with their children indented one level deeper. If the input is not well-formed, the DOMParser produces a parsererror element and the formatter shows the error message so you can locate and fix the problem.
What the Formatter Preserves
The XML declaration (<?xml version="1.0" encoding="UTF-8"?>) is kept on the first line if present. Element names, attribute names, attribute values, text content, CDATA sections, XML comments, and namespace prefixes are all preserved exactly as in the original. Only inter-element whitespace is changed.
XML Minifier — Compact XML for Production Use
The XML Minifier removes all whitespace that is not part of text content, producing the shortest possible well-formed XML document. Comments are also stripped since they serve no data purpose in production payloads. This is the format expected by most XML-consuming APIs and the standard for XML embedded in build artifacts or stored in databases.
When to Minify XML
Minification reduces payload size, which directly reduces transfer time and bandwidth cost. For XML served in REST or SOAP API responses this can be significant when payloads are large or the API is called frequently. For XML configuration files checked into version control, minification reduces diff noise and storage footprint. To recover readable XML from a minified document, paste it into the XML Formatter tool on this page.
XML Validator — Check Well-Formedness Instantly
The XML Validator checks whether your XML is syntactically well-formed using the browser native DOMParser. Well-formedness is the baseline requirement for any XML document: a single root element, all tags properly opened and closed, attribute values enclosed in quotes, and reserved characters escaped. If valid, the tool reports the root element name, the number of direct child elements, whether an XML declaration is present, and the declared character encoding. If invalid, it shows the parse error and lists the most common causes.
Well-Formedness vs Validity
XML has two levels of correctness. A well-formed document follows the core XML syntax rules covered by this validator. A valid document additionally conforms to a specific schema — an XSD (XML Schema Definition) or a DTD (Document Type Definition) — which defines what elements and attributes are allowed and in what structure. This tool checks well-formedness only. For schema validation, use a dedicated XSD validator.
Common XML Syntax Errors
The most frequent causes of malformed XML are unclosed tags, mismatched opening and closing tag names (XML is case-sensitive so <Name> and <name> are different tags), unescaped ampersands or less-than characters in text content or attribute values, more than one root element, and attribute values not enclosed in either single or double quotes.
XML to JSON Converter — Convert XML to Structured JSON
The XML to JSON converter takes a well-formed XML document and produces a structured JSON object that represents the same data. Element names become object keys, text content becomes string values, child elements become nested objects, and elements that repeat at the same level are automatically collected into JSON arrays. XML attributes are grouped under an @attributes key inside the element object, following the widely used Badgerfish convention.
How Repeated Elements Become Arrays
When the converter encounters two or more sibling elements with the same tag name — for example multiple <book> elements inside <catalog> — it automatically converts them into a JSON array. The first occurrence creates a single value; the second occurrence converts that value into a two-element array; additional occurrences append to the array. This means the JSON output correctly represents repeated XML structures without requiring any special input from you.
Mixed Content and CDATA
If an element contains both text and child elements, the text portion is stored in a #text key alongside the child element keys. CDATA sections are treated as text content and placed in the same value field. This ensures that all character data in the XML is captured in the JSON output, even in complex mixed-content documents.
XML Escape — Safely Embed Text in XML
The XML Escape tool converts plain text into a string that can be safely placed inside an XML element or attribute value. XML reserves five characters for its own syntax: the ampersand (&), less-than (<), greater-than (>), double quote ("), and apostrophe ('). Any of these appearing in raw text would break the XML structure. The tool replaces each with its named entity reference, producing output that can be pasted directly into any XML document.
When to Use XML Escape
Common use cases include embedding user-supplied text in XML configuration files, inserting URLs that contain ampersands as query string separators, placing code snippets or SQL queries into XML data fields, writing XML attribute values that contain double quotes, and preparing any free-text content for inclusion in SOAP envelopes, RSS feeds, SVG files, or Android resource strings.
Related XML, JSON, and Code Tools
If you work with XML and structured data regularly, these tools on the site work well alongside this page:
- JSON Formatter — format, validate, minify, convert JSON to CSV, convert JSON to XML, and escape JSON strings
- Code Formatter — format HTML, CSS, JSON, XML, and JavaScript in one tool
- HTML Editor — full CodeMirror editor with live preview and HTML validator
- Markdown Viewer — live Markdown preview, Markdown to HTML, and Markdown table generator
- AI Table Generator — generate formatted HTML tables with AI from a text description