GALAXY OF TOOLS

DEV SECTOR

XML Formatter

Pretty-print, minify and validate XML with line-numbered errors, and convert XML to JSON.

Runs entirely in your browser. Nothing you enter or upload is sent to a server.

An XML formatter and validator that keeps your data intact

The XML Formatter turns a single-line SOAP response, sitemap, RSS feed, Android layout or configuration file into neatly indented XML you can actually read — and minifies it again when you need the smallest file. Every tag, attribute, comment, CDATA section and processing instruction is kept exactly as written; only the whitespace between them changes.

Before formatting, your XML is checked by the browser’s own XML parser. If it is not well-formed — a missing closing tag, an unquoted attribute, a stray & — you see the line and column, the parser’s message and the surrounding lines with a caret, plus a button that jumps straight to the problem.

You can also convert XML to JSON, with attributes as @name keys and repeated elements as arrays. Everything happens in your browser; nothing you paste is uploaded.

How to use the XML Formatter

  1. Paste XML into XML input, drop a file onto it or press Load file.
  2. Choose an indent of 2 spaces, 4 spaces or a tab, and tick Remove comments if you want them stripped.
  3. Press Format to pretty-print, Minify to remove whitespace between tags, or Validate to check well-formedness only.
  4. Press XML → JSON to get a JSON version of the document.
  5. If there is an error, read the line and column, then press Go to error. Otherwise use Copy or Download.

XML Formatter features

Lossless pretty printing

Tags and attribute values are kept byte for byte; only indentation and line breaks change. Short text elements stay on one line, like <name>Dune</name>.

Real validation

Well-formedness is checked by the browser’s XML parser — the same one that reads SVG and RSS — with line and column numbers.

Respects xml:space

Elements marked xml:space="preserve" are left exactly as they are, so significant whitespace is never touched.

Minify with or without comments

Whitespace-only text between tags is removed; comments can be kept or stripped.

XML to JSON

Attributes become @attr keys, mixed text becomes #text, repeated elements become arrays and CDATA is merged into text.

Well-formed XML rules

An XML document is well-formed when it follows the basic syntax rules of the XML 1.0 specification. Most validation errors break one of these:

  • There is exactly one root element that contains everything else.
  • Every start tag has a matching end tag, or is self-closing like <br/>, and elements close in the reverse order they opened.
  • Tag names are case-sensitive: <Item> must be closed by </Item>, not </item>.
  • Attribute values are always quoted, and an element cannot repeat the same attribute.
  • The characters < and & must be escaped in text as &lt; and &amp;, or wrapped in a CDATA section. HTML entities like &nbsp; are not defined in XML unless a DTD declares them — use &#160; instead.
  • The XML declaration <?xml version="1.0"?>, if present, must be the very first thing in the file.

How XML maps to JSON

All values stay strings, because XML has no number or boolean types. Namespaced names keep their prefix, such as media:thumbnail. For other conversions, try the YAML ↔ JSON Converter and tidy the result with the JSON Formatter.

XMLJSON
<name>Dune</name>"name": "Dune"
<book id="1">Dune</book>"book": {"@id": "1", "#text": "Dune"}
Two or more <book> siblings"book": [ … , … ]
<owner/>"owner": ""
<![CDATA[x < y]]>Plain text "x < y"

XML Formatter FAQ

How do I format XML online?

Paste the XML and press Format. This XML formatter checks that the document is well-formed, then indents each nested element on its own line. Choose 2 spaces, 4 spaces or tabs, and download or copy the result.

Does formatting change my XML?

Only the whitespace between tags changes. Text is trimmed at the edges inside elements that are reformatted, which is insignificant in data formats like sitemaps, feeds and configuration files. Use xml:space="preserve" on any element whose spacing matters and it is left untouched.

What is the difference between well-formed and valid XML?

Well-formed means the syntax is correct — tags nest and close properly, attributes are quoted. Valid means it also follows a schema (XSD) or DTD for a particular format. This tool checks well-formedness, which catches the vast majority of real errors.

Why does it say an entity is undefined?

XML only predefines five entities: &lt;, &gt;, &amp;, &quot; and &apos;. HTML names such as &nbsp; or &copy; need a numeric reference instead — the HTML Entity Encoder can produce one.

Can it handle large XML files?

Yes — files of several megabytes format in about a second. Live updating pauses above roughly 400 KB, so press Format instead.

Is my XML uploaded to a server?

No. Parsing, formatting and conversion all run in your browser, so SOAP payloads, API keys in config files and other private data never leave your device.

You might also need