Glyph WidgetsGlyph Widgets
概要お問い合わせブログプライバシー利用規約Ko-fiでサポート

© 2026 Glyph Widgets. All rights reserved.

·

100%クライアントサイド処理

ブログに戻る

XML Formatter: Beautify & Validate XML

XML formatter: beautify and validate XML in your browser. Supports minification, configurable indentation, and file download.

Glyph Widgets
2026年2月27日
9 min read
xml formatterxml validatorxml beautifierformat xml onlinexml pretty print

What Is XML Formatter?

XML Formatter is a browser-based tool that takes raw or collapsed XML and produces properly indented, human-readable output. Developers and data engineers regularly encounter XML that has been compressed into a single line — SOAP responses, Maven POM files copied from a terminal, Spring configuration snapshots, RSS feeds, or SVG exports from design tools. Reading any of these without formatting is slow and error-prone.

This tool solves that by validating the XML using the browser's native DOMParser, then applying clean indentation with configurable spacing. If validation fails, it surfaces the exact parser error message. If the XML is valid, the formatted result is ready to copy or download in one click. Everything runs entirely in your browser — no data is sent to any server, there is no account to create, and the tool is completely free.

Key Features

  • Format XML with customizable indentation (2 or 4 spaces) — Choose your indent size from the action bar dropdown. The tool preserves your last-used indent size for the duration of your session, and supporters can save it as a default preset.
  • Validate XML syntax with error messages — Validation runs through the browser's built-in DOMParser with the application/xml MIME type. If a parsererror node is found in the result document, the raw parser error text is displayed below the output panel.
  • Minify XML (remove whitespace) — Produces condensed XML with all inter-tag whitespace removed, suitable for embedding in payloads, log lines, or configuration strings.
  • Copy formatted output to clipboard — Uses the Clipboard API with a textarea fallback for environments where the API is unavailable.
  • Download as .xml file — Saves the output as formatted.xml with application/xml MIME type.
  • Keyboard shortcuts — Ctrl+Enter (or Cmd+Enter on Mac) triggers Format; Ctrl+Shift+M (or Cmd+Shift+M) triggers Minify.

How to Use XML Formatter

Step 1: Paste Your XML

Open the tool at /developer/code/xml-formatter. Paste your XML document into the Input panel on the left. The textarea has a monospace font, resizable height, and accepts any document size your browser can handle comfortably. There is no paste size limit enforced by the tool.

Step 2: Select Indentation

In the action bar below the two panels, open the indent dropdown and choose 2 spaces or 4 spaces. Two-space indentation is common in frontend and JavaScript-adjacent tooling. Four-space is conventional in Java, C#, and many enterprise XML standards like XSLT and XSD.

Step 3: Click Format

Click Format or press Ctrl+Enter / Cmd+Enter. The tool first validates the input using DOMParser. If the XML is malformed, a red error message appears below the output panel showing the browser's parser error (for example: "error on line 5 at column 12: Opening and ending tag mismatch: config line 1 and value"). If validation passes, the formatted XML appears in the read-only Output panel on the right.

Example input (single-line Maven dependency):

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><version>3.2.1</version><scope>compile</scope></dependency>

Output with 2-space indent:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-web</artifactId>
  <version>3.2.1</version>
  <scope>compile</scope>
</dependency>

Step 4: Minify (Optional)

Click Minify or press Ctrl+Shift+M / Cmd+Shift+M to collapse the XML back to a minimal single-line representation. Minification also runs through the validator first — the tool will not produce minified output from invalid XML. This prevents accidentally compressing a document that has a silent error somewhere in its structure.

Step 5: Copy or Download

Click Copy to place the formatted or minified output on your clipboard. Click Download to save formatted.xml to your downloads folder. Both buttons are disabled until the output panel contains content.

Practical Examples

Cleaning Up a SOAP Response

Your service monitoring tool logs raw SOAP responses on one line for compactness. You need to read a fault response for a support ticket:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server</faultcode><faultstring>Authentication failed: token expired</faultstring></soapenv:Fault></soapenv:Body></soapenv:Envelope>

Paste it, click Format. The nesting structure becomes immediately clear — the Fault element sits inside Body inside Envelope, and both the faultcode and faultstring values are now on their own readable lines.

Reviewing a Spring Configuration File

A colleague sends you a pasted Spring applicationContext.xml fragment with all whitespace stripped. Rather than manually inserting line breaks and indentation, paste it into the formatter and click Format with 4-space indent to match your team's convention. The formatted output can be pasted directly back into the source file.

Compressing XML for an API Payload

Your integration spec requires XML embedded as a string value in a JSON field, with all whitespace removed to keep the payload size down. Paste your well-formatted source XML and click Minify. The output is a single line with no spaces between tags, ready to embed or URL-encode.

Tips and Best Practices

Validate before editing. If you are about to edit a multi-hundred-line XML file, paste it through the formatter first. A red error message immediately tells you whether the current state is valid before you invest time making changes.

The formatter handles CDATA sections. Content inside <![CDATA[...]]> blocks is preserved as-is during formatting. The formatter does not attempt to indent the content of CDATA sections, which means embedded code or free text inside CDATA remains intact.

Self-closing tags stay self-closing. The formatter identifies self-closing tags (e.g., <br/>, <input type="text"/>) correctly and does not convert them to open/close pairs or vice versa.

Use 4-space indent for XSD and XSLT. These XML dialects have deep nesting by convention. Four-space indentation makes the structural hierarchy more visible at a glance compared to two-space.

Copy then open in your editor. After formatting, click Copy and paste directly into your code editor. The formatted text is plain UTF-8 with no invisible characters, so it imports cleanly into any editor.

Common Issues and Troubleshooting

"Invalid XML syntax" error with a namespace-heavy document — Some XML processing tools produce namespace declarations that the browser's DOMParser handles correctly but reports as warnings on certain platforms. If you see an error like "Namespace prefix ns0 is not defined," confirm the namespace declarations are present in the root element and retry.

Formatted output has unexpected extra blank lines — The formatter splits on \n after replacing >\s*< with >\n<. Documents with pre-existing line breaks between tags may produce additional empty lines in edge cases. Use the Minify button and then Format again to normalize the whitespace.

Error message is very long and contains HTML — The browser's DOMParser includes the full error text from the XML parser, which occasionally contains HTML markup when the parser embeds an HTML error page. The key information (line number and column) is always in the first two lines of the message.

Minify button produces output but Format button shows an error — This should not occur because both operations run through the same validator first. If you encounter this, it typically means the XML was valid at minify time but the input was changed between operations. Clear both panels and start fresh.

Output panel is empty with no error message — This means the input was empty or whitespace-only when you clicked Format. The error message "Please enter XML to format" will appear below the output panel.

Privacy and Security

XML Formatter runs entirely in your browser. All formatting and validation happens through JavaScript and the browser's native XML parser — no text you enter is sent to any external server. The tool is safe for XML documents that contain authentication tokens, private configuration values, internal API endpoints, personally identifiable information, or any other sensitive content. The tool also works with no network connection after the initial page load.

Frequently Asked Questions

Is XML Formatter free? Yes, fully free. There are no usage limits, no account required, and no cost for any formatting or validation operation. Glyph Widgets supporter features (preset saving, session history, tool notes) are available to Ko-fi supporters, but the core XML formatting functionality is unrestricted.

Does it work offline? Yes. All operations run in your browser using JavaScript and the browser's built-in XML parser. Once the page has loaded, you can disconnect from the internet and continue formatting and validating XML without interruption.

Is my data safe? Yes. The XML you paste is never transmitted to a server. It stays in your browser's memory for the duration of your session and is cleared when you click the Clear button or close the tab.

What kinds of XML errors does the validator detect? The validator uses the browser's native DOMParser with application/xml parsing, which catches unclosed tags, mismatched opening and closing tag names, invalid namespace declarations, malformed attribute syntax, illegal characters, and duplicate attribute names.

Does the formatter support XML declarations and processing instructions? Yes. The <?xml version="1.0" encoding="UTF-8"?> declaration and processing instructions like <?xml-stylesheet type="text/xsl" href="style.xsl"?> are preserved in their original positions during formatting.

Can I format SVG files? Yes. SVG is well-formed XML and formats correctly. The formatter preserves all SVG element nesting, attribute values (including d path data), and namespace declarations. Note that the d attribute values inside <path> elements contain coordinate sequences that the formatter does not modify.

What is the difference between Format and Minify? Format adds indentation and line breaks to make the document human-readable. Minify removes all inter-tag whitespace to produce the smallest possible representation. Both operations validate the XML first and refuse to produce output if the input is invalid.

Can I use it on XHTML documents? Yes. XHTML is valid XML and will parse and format correctly. HTML5 documents that are not well-formed XML (e.g., missing closing tags, unquoted attributes) will fail validation.

What is the keyboard shortcut to format? Ctrl+Enter on Windows/Linux, or Cmd+Enter on macOS. To minify, use Ctrl+Shift+M on Windows/Linux or Cmd+Shift+M on macOS.

Does the formatter change my attribute order? No. Attribute order within elements is preserved. The formatter only adds indentation and line breaks between elements — it does not reorder or modify attribute values.

Related Tools

JSON Formatter — Format, validate, and minify JSON with the same indentation controls, plus schema validation, schema generation, and a tree viewer.

YAML Formatter — Format YAML files and optionally convert them to JSON output.

Try XML Formatter now: XML Formatter

最終更新: 2026年2月27日

続きを読む

他の記事XML Formatterを試す