XML Formatter
Format, validate, and minify XML with syntax highlighting.
このツールについて
A fast, browser-based XML formatter that instantly prettifies messy XML with configurable indentation, validates your markup and reports any errors with line numbers, and minifies XML by stripping unnecessary whitespace. Syntax highlighting with color-coded elements, attributes, and values makes large documents easy to read. No data is ever sent to a server — all processing happens entirely in your browser.
使い方
- 1 Paste your XML into the input textarea.
- 2 Select indent size: 2 spaces, 4 spaces, or a tab character.
- 3 Click Format to prettify or Minify to compress.
- 4 Errors are highlighted with a message showing the problem.
- 5 Click Copy to copy the formatted output to your clipboard.
- 6 Click Clear to reset both panels.
Why XML needs formatting and validating
XML (eXtensible Markup Language) is a strict, tree-structured text format used for configuration files, RSS feeds, SOAP web services, Office documents, SVG graphics, and countless data-exchange APIs. Unlike HTML, XML has no forgiving browser to paper over mistakes: every opening tag must be closed, every element nested correctly, every attribute value quoted, and there can be exactly one root element. A single stray ampersand or mismatched tag makes the entire document invalid. This tool does two jobs that solve the two most common XML pain points — turning a wall of minified markup into a readable indented tree, and confirming that the markup is actually well-formed before you ship it.
How the formatter works under the hood
Rather than naively reformatting text with regular expressions, this tool parses your XML with the browser's built-in DOMParser — the same engine browsers use for real documents. It builds a proper node tree, then walks it recursively, adding your chosen indentation at each depth. Because it parses first, the formatter is also a genuine validator: if DOMParser reports a parsererror, the tool catches it and shows the message instead of producing garbage output. That is an important distinction. A regex-based "pretty-printer" will happily indent broken XML and hide the error; a parser-based one cannot, so a clean formatted result is itself proof that your document is well-formed.
You can choose 2 spaces, 4 spaces, or a tab character for indentation. The serializer applies a few readability rules: an element with a single text child is kept on one line (so <title>Hello</title> stays compact), an element with no children renders as a self-closing tag, and comments and CDATA sections are preserved and colour-coded. Syntax highlighting tints element names, attribute names, attribute values, and text differently so the structure of a large document jumps out.
A worked example
Paste this minified one-liner:
<catalog><book id="1"><title>XML Basics</title><price>29.99</price></book></catalog>
With 2-space indentation, Format produces a nested tree: catalog at the root, an indented book carrying its id="1" attribute, and inside it title and price each on their own line with their text inline. The status line confirms "Valid XML — formatted successfully." Now delete the closing </book> and click Format again: the parser stops and the red banner reports the exact problem, often with a line reference, so you know precisely what to fix.
Format versus Minify
The two buttons are inverses. Format adds whitespace for humans; Minify strips it for machines. Minify re-serializes the parsed tree and collapses the whitespace between tags, shrinking the byte size for transport or storage. The byte counters above each panel show the before-and-after size so you can see exactly how much you saved — useful when XML is being sent over a network or embedded in a larger payload where every kilobyte counts.
Common XML errors and how to read them
- Unescaped ampersand. A raw
&in text or an attribute is illegal; it must be written&. This is the single most frequent cause of a parse failure. - Mismatched or unclosed tags.
<b>text</i>or a missing closing tag breaks the tree. - Multiple root elements. XML allows exactly one top-level element; two siblings at the root are invalid. Wrap them in a single container.
- Unquoted attribute values.
id=1must beid="1"; XML always requires quotes. - Illegal characters. Stray control characters or a misplaced
<inside text will halt the parser.
Practical tips
- Paste triggers an auto-format. Dropping XML into the input field formats it immediately, so you get instant feedback on validity.
- Well-formed is not the same as valid against a schema. This tool checks that the syntax is correct; it does not verify your document against a DTD or XSD. A file can be perfectly well-formed yet still violate a schema's required-element rules.
- Mind the size. Typical config files and feeds process instantly. Multi-megabyte files may take a moment, and gigabyte-scale data is better handled by a streaming desktop tool.
Your data stays on your device
All parsing, formatting, validation, and minification run locally in your browser using the native DOMParser and XMLSerializer. Nothing you paste is uploaded to a server, which matters when the XML contains API keys, configuration secrets, or proprietary data. You can confirm this by disconnecting from the network — the tool keeps working.
よくある質問
JSON の整形・検証・圧縮 — 構文エラー箇所を正確に表示。
Format, validate, and explore JSON with syntax highlighting, JSONPath browser, tree collapse, and schema inference.
HTML、CSS、JavaScriptをミニファイしてファイルサイズを削減します。ブラウザ上で完全に動作します。
YAML構文を検証してフォーマットされたJSONに変換します。ブラウザ上で完全に動作します。
設定可能なインデントで複数の言語にわたってコードをフォーマットおよびビューティファイできます。