SuperDevTools

XML formatter and validator

Output
Paste some XML, drop a file or click "Example".
Elements
0
Attributes
0
Depth
0
Output size
0

External entities are never loaded: the browser's DOMParser does not fetch any file or address declared in a DOCTYPE.

Everything happens in your browser: your XML is not sent or stored anywhere.

An XML formatter and validator that runs in your browser

XML carries structured data in RSS feeds, sitemaps, e-invoices, config files and exports from business software. These files often arrive on a single line, or with one badly closed tag that makes an import fail. This tool checks that the document is well formed, beautifies or minifies it, shows it as a tree you can browse and converts it to JSON.

Paste the text into "Your XML", drop a file on the box or click "Open a file". The check runs as you type: you get either "Well-formed XML." or a message with the line, the column and the cause, plus an excerpt with the faulty character highlighted. "Go to the error" puts the cursor on it.

How to use it

  1. Pick the "Output": "Format", "Minify", "XML → JSON" or "JSON → XML".
  2. Set the "Indentation" (2 spaces, 4 spaces or tab), where "Attributes" go (On the tag line or One per line), and tick or untick "Keep comments".
  3. Switch to "Tree" to expand elements. Clicking a tag or an attribute shows its XPath, for example /catalog/product[2]/@ref, which "Copy the path" puts on the clipboard. The search box looks through tags, attributes and text.
  4. Click "Copy" or "Download".

Well formed or valid?

A well-formed document follows the XML syntax; a valid document also matches a schema (DTD or XSD) that lists the allowed tags. This tool checks well-formedness, not schema validation. The rules are short: a single root element, every tag closed in reverse order of opening, attribute values in quotes, case-sensitive names, and & and < escaped in text.

WrittenProblemCorrect
<a><b></a></b>overlapping tags<a><b></b></a>
<a id=1/>value without quotes<a id="1"/>
<a>R&D</a>unescaped &<a>R&amp;D</a>
<a>&nbsp;</a>HTML entity unknown to XML<a>&#160;</a>
<Price>9</price>different case<price>9</price>

Example: with <order> on line 1, <item>Pen on line 2 (indented by two spaces) and </order> on line 3, the tool reports "line 3, column 1: found </order> while <item>, opened at line 2, column 3, is still open". The browser's DOMParser then checks the same text; if it finds another problem, its own message is shown with its line and column.

CDATA, namespaces and entities

A <![CDATA[ … ]]> section holds raw text in which < and & need no escaping. Its content is copied as is, both when formatting and when minifying. The same goes for the text of an element, for mixed content (text and tags interleaved) and for any element marked xml:space="preserve": only the whitespace between tags changes.

A prefix such as p:price must be declared with xmlns:p="…" on the element or a parent, otherwise the tool flags it. Without a DTD only five named entities exist: &amp;, &lt;, &gt;, &quot; and &apos;, plus numeric references such as &#233;. External entities are never loaded: the browser's DOMParser does not fetch any file or URL declared in a DOCTYPE, which rules out XXE attacks.

Converting XML to JSON and back

The conversion follows a simple convention: attributes prefixed with @, text with #text, CDATA with #cdata, repeated elements grouped into an array, and values always kept as strings. So <item ref="X1" qty="2">Pen</item> becomes {"item":{"@ref":"X1","@qty":"2","#text":"Pen"}}, and the reverse conversion gives back the same tag. Comments and the order between tags with different names are not kept.

Frequently asked questions

Will a 20 MB file freeze the page?

No. Formatting runs in the background; only the browser's own check keeps the page busy for a moment. Above 2 MB the file is not copied into the input box and only the beginning of the output is displayed, but "Copy" and "Download" include all of it.

Why does my XPath find nothing in my code?

Usually because of a default namespace (xmlns="…"): most libraries then require a prefix declared in your code.

Does formatting change my data?

No. Whitespace between tags is rewritten and spacing inside tags is normalised, but text, attribute values and quote marks stay the same. An element that holds only whitespace becomes empty.