UtilityToolsLab

© 2026 UtilityToolsLab. Built and maintained by the UtilityToolsLab Team.

About·Changelog·Privacy Policy·Terms of Service·Report a bug
HomeCode & DevXML Formatter

Related Tools

JSON FormatterBase64UUID GeneratorJWT DecoderTimestampRegex TesterRandom JSON GeneratorAPI Load TesterJSON Diff Checker

XML Formatter & Validator

Beautify or minify XML with your own indent, and read every well-formedness fault by line and column before the document is reformatted.

You Might Also Like

All Code & Dev

JSON Formatter

Paste raw JSON to instantly format, beautify, validate and minify it. Syntax errors are pinpointed by line and column. Free and fully private.

Base64

Encode text or data to Base64 and decode Base64 strings back to readable text. A fast developer utility for API payloads, tokens and data URIs.

UUID Generator

Generate RFC 4122 compliant UUID v4 strings with one click, or batch-generate up to 100 unique IDs at once. Cryptographically random and free.

JWT Decoder

Decode and inspect JSON Web Tokens. View header, payload, and signature. Detects expiry and maps all registered JWT claims.

Two XML files can carry identical data and share not one line. One came back minified from a SOAP endpoint; the other was hand-indented at four spaces by whoever last opened it in an editor. XML Formatter & Validator throws away both layouts and rebuilds the document from its parse tree, so indentation, attribute order and empty-tag style come out of your settings rather than out of the file's history.

Nothing gets reformatted until it parses. A hand-written tokenizer walks the source and reports every well-formedness fault it finds against a line and a column: a closing tag that does not match its opener, an attribute name repeated on one element, a bare ampersand, a second root element. Faults are collected together wherever recovering from one is safe, which means four typos come back in a single list instead of costing you four round trips.

Namespaced names such as dc:title stay whole. The XML declaration, comments, processing instructions and CDATA sections all reach the output intact, and the parser never reads inside a CDATA block, so an & parked in there is left alone while a bare one in ordinary text is flagged. Nothing is uploaded. The tokenizer is a few hundred lines of JavaScript running in the tab that loaded this page.

A Real Example: One Catalogue Record, 481 Bytes

Press Load Sample and a single unbroken line arrives, opening <?xml version="1.0" encoding="UTF-8"?><catalog xmlns:dc="http://purl.org/dc/elements/1.1/" updated="2026-03-14">. It holds one book, bk-0472, priced at 24.50 GBP. Beautify at two spaces opens it into 15 lines and 541 bytes, and the banner reads 481 B → 541 B (+12.5%). The stat row settles on 10 elements, 5 attributes and a maximum depth of 4.

Two details in that output are deliberate. <in-stock/> stays self-closing instead of expanding into a pair, and the CDATA block inside <blurb> rides on the same line as its tags, because an element whose only child is text or CDATA is never split across lines. Switch to Minify with Strip comments ticked and the same record returns at 438 bytes, 8.9% under what you pasted.

What Each Rewrite Option Changes

  • Indent offers 2, 4 or a real tab character. Tabs matter when the file goes back into a repository whose .editorconfig asks for them, since spaces would show up as a diff on every line.
  • Collapse empty tags is on by default and rewrites <tag></tag> as <tag/>. Turn it off when the consumer is an older parser that treats the two forms differently.
  • Strip comments drops every <!-- --> block. The XML declaration and any processing instructions are left where they are, because dropping those changes how the document is read.
  • Sort attributes A→Z reorders attributes inside each tag. XML gives attribute order no meaning, so this is a safe rewrite, and it makes two exports of the same config comparable line by line.
  • The download button beside Copy writes formatted.xml, or formatted.min.xml when you are in minify mode, straight from a Blob.
  • Under the stat row sits an Element census, collapsed until you ask for it. It lists every distinct tag name with its occurrence count and the first path it was seen at. The sample reports 9 distinct names with tag at 2.
  • Each path in that census is a button, and clicking one copies it. /catalog/book/tags/tag lands on your clipboard ready to paste into an XPath query or a test assertion. Almost nobody finds this on a first visit.

What Happens When the Document Is Not Well-Formed

  • A typo in a closing tag names both ends of the problem: Line 3, column 20: closing tag </titel> does not match <title>, which was opened at line 3, column 3. Knowing where the opener was is usually what tells you which of the two is misspelled.
  • An unescaped ampersand is the fault most XML tools report worst. Here it reads a bare & must be written &amp;. XML predefines only &lt; &gt; &amp; &quot; and &apos;. and it points at the ampersand itself, not at the end of the element.
  • A closing tag with no opener at all is reported and then skipped, so the rest of the document is still scanned. A tag that closes the wrong element stops the parse, because guessing which of the two nestings you meant would invent structure you did not write.
  • Input is capped at 500,000 characters, and a longer document is refused with its own size quoted back rather than being allowed to freeze the tab. Nesting is followed to 256 levels, past which the parse stops.
  • Mixed content is the one case where beautifying changes meaning. <p>Some <b>bold</b> text</p> comes back across four lines with the text nodes trimmed, so the single spaces either side of <b> are gone. For prose-bearing XML, minify instead: it drops whitespace-only nodes and leaves every other text node byte for byte.
Indent:
Rewrite options

Paste an XML document above, or press Load Sample for a minified catalogue record with a namespace, a comment, a CDATA block and a self-closing tag in it. Nothing is uploaded; the parser runs in this tab.