RunLocalTools

XML Formatter & Validator: Pretty-Print, Minify and Repair XML Online

Format, validate, minify and repair XML in your browser. Exact line and column errors, tree view, XPath, JSON export and batch zip. Nothing is uploaded.

What it does

Paste or drop XML and the tool checks it as you type. If it is well-formed you get it back pretty-printed with the indent style you choose, or minified into one compact line. If it is not, you get the exact line and column of the problem, a few lines of context with a caret under the mistake, and a “Jump to error” button that selects it in the editor.

Around that core there is a collapsible tree view with search, an XPath box, a one-click XML to JSON export, a statistics panel, an auto-repair for the most common mistakes, and a batch mode that formats or minifies a whole folder of files into a single .zip.

How it works

Most online formatters hand your text to the browser’s XML parser and print whatever comes back. That is why they tend to drop the DOCTYPE, rewrite entities, and report errors in different words in every browser. This tool uses its own parser instead, built to the XML 1.0 well-formedness rules, which is how it can promise a few things:

  • Errors are exact and consistent. Mismatched and unclosed tags (with where the tag was opened), duplicate attributes, unquoted attribute values, a bare & or <, a second root element, text outside the root, undeclared namespace prefixes, illegal control characters, malformed declarations, and unterminated comments or CDATA sections are all reported with a line and column.
  • Nothing is rewritten that you did not ask to change. Comments, CDATA sections, processing instructions, the DOCTYPE and entity references such as &amp; or &#160; come out exactly as they went in.
  • Whitespace that carries meaning is left alone. Spacing between elements is treated as formatting and re-indented. Text inside an element is never reflowed, so a paragraph such as <p>Hello <b>big</b> world</p> stays on one line, and anything under xml:space="preserve" is kept byte for byte.

The tool was checked against a reference parser on 50,000 generated documents, valid and invalid, and agreed on every one. Formatting, minifying and the JSON export were checked the same way on thousands of random documents to confirm the output means the same as the input.

Formatting options

Indent (2, 4 or 8 spaces, a tab, or your own), attributes kept on one line, wrapped past a column or one per line, optional alphabetical attribute sort (namespace declarations first), keep or strip comments, self-closing style for empty elements, quote normalisation, trimming of text in text-only elements, adding, keeping or removing the XML declaration, setting its encoding to UTF-8, LF or CRLF line endings, and an optional final newline. Your last-used choices are remembered.

Auto-repair

When a document is not well-formed, the tool lists exactly what it can fix and what it would leave, and applies nothing until you click. It can escape a bare &, add quotes around unquoted attribute values, remove illegal control characters, make a closing tag’s capitalisation match its opening tag, close elements left open at the end of the file, and drop stray text before the XML declaration. Every repair can be undone. Anything ambiguous, such as a closing tag that matches nothing, is reported instead of guessed.

How to use it

  1. Paste XML into the Input box, or drop a file on Open XML file(s). The file’s own declared encoding is respected, so a Latin-1 or UTF-16 file opens correctly.
  2. Read the green “Well-formed” bar, or the error panel. If there is an error, click Jump to error, or apply the auto-repair if it is offered.
  3. Pick a tab. Format and Minify show the result, Tree lets you browse and search it, XPath runs a query, JSON converts it, and Stats summarises it.
  4. Set the options in the sidebar, then Copy output or Download. Use output as input swaps the result back into the editor, and Undo reverses it.
  5. For many files, drop them into Batch mode, then choose Format all or Minify all to download one .zip. Files that are not well-formed are left out and listed in _skipped-files.txt.

Need the opposite direction? The JSON → XML translator turns a JSON response into XML, using the same naming conventions as this tool’s JSON export so the two round-trip.

Tree view, XPath and JSON export

The Tree tab shows the document as collapsible rows and stays fast on very large files, because only the rows on screen are drawn. Search matches tag names, attribute names and values, and text; click any node to see its path (for example /catalog/book[2]/price), copy it, or jump to it in the source.

The XPath tab runs XPath 1.0 with your browser’s built-in engine and shows each match with its path. Prefixes declared in the document work as written, and a default namespace is made available as d: so queries such as //d:book just work.

The JSON tab uses the common conventions: attributes become @name keys, text next to attributes or child elements becomes #text, and repeated sibling elements become arrays. Entities are decoded. An option keeps CDATA as its own #cdata key. Once you have JSON, the JSON formatter can validate and tidy it further.

Supported formats

Any XML-based text: .xml, .xhtml, .rss, .atom, .plist, .xsd, .xsl, .kml, .gpx, .config, .csproj, SOAP envelopes, sitemaps, and so on. SVG is XML too, so it validates and formats here; for shrinking SVG artwork specifically (precision, empty paths, editor metadata), use the SVG optimizer. Input can be UTF-8, UTF-16, or any legacy encoding the file declares.

Limitations

  • It checks that XML is well-formed. It does not validate against an XSD schema or a DTD, because browsers have no schema validator and the tool does not guess.
  • Entities declared in your own DOCTYPE are kept as written and never expanded, and external DTDs or entities are never loaded. XPath is switched off for documents that declare their own entities, which also rules out entity-expansion attacks.
  • Whitespace between elements is treated as formatting. An element that contains only a line break and indentation becomes empty; an element holding only spaces on one line keeps them.
  • Output is always saved as UTF-8. If the declaration names another encoding, a warning appears and one click sets it to UTF-8.
  • Very large output (over about 200 KB) is shown as plain text for speed; Copy and Download always include everything. The tree view shows up to 500,000 rows at a time, so collapse some branches for extreme files.

Privacy

Everything this tool does is local. Your XML is parsed, formatted, queried and converted inside your browser, and nothing you type or drop is sent to any server. There are no accounts and no optional features that use the internet.

For convenience, your current input and any batch files are kept in your browser’s own storage (IndexedDB) so a refresh does not lose your work. They never leave your device, and Clear saved work removes them. The only thing ever downloaded is a small open-source zip library, fetched once from a public CDN the first time you build a batch .zip; that request carries none of your data, and the zip itself is built locally.

FAQ

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

Well-formed means the document follows the basic syntax rules: tags properly nested and closed, attributes quoted, one root element, special characters escaped. Valid goes further and means it also obeys a schema (an XSD or DTD) that says which elements and attributes are allowed. This tool checks well-formedness, which is what every XML parser requires before it will read a file at all.

Will formatting change my data?

Not the data. Whitespace between elements is re-indented, which XML consumers ignore. Text inside elements is left exactly as written, and elements that mix text and tags are not reflowed. If you would rather strip surrounding spaces from simple values such as <name> Ada </name>, switch on “Trim text in text-only elements”. Compare the before and after with the diff checker if you want to see precisely what changed.

Why does it say &nbsp; is not defined?

XML only has five built-in entities: &amp;, &lt;, &gt;, &quot; and &apos;. HTML’s &nbsp;, &copy; and friends do not exist in plain XML unless a DOCTYPE defines them. Use the numeric form instead, such as &#160; for a non-breaking space or &#169; for ©.

Can it fix my broken XML automatically?

For the common slips, yes: bare ampersands, unquoted attribute values, stray control characters, closing tags with the wrong capitalisation, and tags left open at the end of the file. It shows the list first and only changes anything when you click Apply fixes, and Undo reverses it. It will not guess at structural problems such as a closing tag that matches nothing.

Is my XML uploaded or stored anywhere?

It is never uploaded. Your input is kept only in your own browser so it survives a refresh, and one click on Clear saved work deletes it. See the Privacy section above for the full picture.

Why does it complain about a namespace prefix?

An element like <x:item> needs a matching xmlns:x="…" declaration somewhere above it, otherwise strict parsers reject the file. If you are working with a fragment cut out of a larger document, untick Undeclared namespace prefixes are errors and the tool will treat it as a warning instead.