XML Formatter & Validator

Format, minify, and validate XML, SVG, or RSS code. View as a tree and fix syntax errors.

๐Ÿ“ Drag & drop .xml / .svg / .rss files here, or click to select
Files are read only in the browser ยท Max 8MB
Result

Validation is done by the browser's built-in XML parser (DOMParser). If an error occurs, the line:column position provided by the parser is displayed, and the cause is explained in Korean. The XML parser may point to where it noticed a problem, not where it began, so check upwards from the indicated line.
Preservation โ€” CDATA, comments, processing instructions (<?xml?> , etc.), DOCTYPE, namespace prefixes, and attribute order are preserved. Elements with mixed content (text and child elements) are kept on a single line without line breaks, as whitespace might be data.
External Entities โ€” are not processed. DOMParser does not fetch external DTDs or entities, so there's no risk like XXE, and no network requests occur even if SYSTEM entity declarations are present in the file. Undefined entities are reported as errors.

What is the XML Formatter & Validator?

Clean up, validate, and explore XML documents right in your browser. While often hidden, XML is the backbone for RSS feeds, SVG images, and many configuration files and API responses. This tool takes raw, single-line XML and makes it human-readable with proper indentation. It also validates your code as you type, translating cryptic browser errors into clear advice with line and column numbers. Unlike basic formatters, it carefully preserves CDATA blocks, comments, and processing instructions. All processing happens locally; your data never leaves your computer.

How to use

  1. Paste your code into the "XML Input" area, or drag and drop an .xml, .svg, or .rss file.
  2. The tool instantly checks your syntax. Errors are flagged with a precise location and explanation.
  3. Click "Format (Pretty)" for an indented result, or "Minify" to create a compact, single-line version.
  4. Toggle the view mode to "๐ŸŒณ Tree" to browse the document structure interactively.
  5. Review stats like "Elements" and "Max Depth", then use "Copy" or "Save" to get your result.

XML Formatter & Validator guide

How this tool is used in real work, and what to watch out for.

Where You Still Find XML Today

You might think JSON has taken over, but XML still shows up in some important places. Public data is a big one. Many government open APIs, for example, default to XML. Sometimes you can request JSON with a special parameter, but other times XML is the only option. Anyone who's integrated with APIs for weather forecasts, business registration lookups, or official address data has probably run into this.

  • Public Data Open API responses โ€” They often come as a single, minified line. Pasting and formatting here lets you instantly see where the resultCode and resultMsg are.
  • RSS & Atom feeds โ€” Blog and news feeds are still XML. If your feed reader won't parse a feed, check its syntax here first.
  • SVG โ€” Vector images are just XML. Formatting them lets you visually trace which path belongs to which group.
  • Sitemaps (sitemap.xml) โ€” Used for syntax validation before submitting to search engines.
  • E-invoices, EDI, and various industry-standard documents โ€” Many domains still have schemas defined in XML.
You can drag and drop files, including those with .svg and .rss extensions. Files are read directly by the browser, so nothing is uploaded.

When Errors Occur: The 5 Most Common Causes

Validation is performed by the browser's built-in XML parser (DOMParser). The tool displays the line and column number provided by the parser and explains the cause in plain English. In almost all cases, the error is one of these five:

  • Using & literally โ€” In XML, & starts an entity. If you put a URL querystring like `?a=1&b=2` in a value, it will break right there. You must use `&amp;` or wrap the content in a CDATA section.
  • Mismatched case in tag names โ€” `<Title>Notice</title>` is an error. Unlike HTML, XML is case-sensitive.
  • Unclosed empty tags โ€” HTML habits like `<br>` or `<img src="โ€ฆ">` will cause errors. Empty tags must be closed, like `<br/>`.
  • Using HTML-only entities โ€” Entities like `&nbsp;` or `&copy;` are not defined in XML. Use numeric character references like `&#160;` and `&#169;` instead.
  • More than one root element โ€” This error happens if you paste two responses together. An XML document must have only one top-level element.
The XML parser points to where it *noticed* a problem, not necessarily where the problem *began*. An unclosed tag high up in the document can cause an error to be reported many lines down. Start at the indicated line and work your way up, looking for mismatched tags. Switching to the Tree view can often help you spot nesting errors more quickly.

Namespaces: Prefixes Are Aliases, Not Names

XML namespaces are a mechanism to prevent name collisions when elements from different sources are mixed in a single document. Examples include RSS feeds that mix `<dc:creator>` and `<content:encoded>` tags, or government forms that combine multiple schemas.

Here's a common point of confusion: it's the URI that defines the element's identity, not the prefix (like `dc:`). The prefix is just an alias. If you change the `xmlns:dc="โ€ฆ"` declaration at the root, the same `dc:creator` tag takes on a different meaning. For this reason, this tool preserves prefixes and their declarations exactly as they are in the original. Normalizing them arbitrarily could change the document's semantics.

  • `xmlns` declarations look like attributes, but you must not delete them. The moment you do, you'll get an "undeclared prefix" error.
  • A default namespace (`xmlns` without a prefix) applies to that element and all its descendants. If you copy and paste a fragment, the declaration might not come with it, changing the meaning of the elements.
  • Attribute order is also preserved. While the XML standard says attribute order is not significant, it is significant to a human running a `diff` against the original file.

CDATA: When to Use It and What to Watch For

A CDATA section is a block that says, "Don't interpret this as markup; read it as literal text." A classic use case is embedding an HTML body inside an RSS feed's `description` tag. Without it, you'd have to escape every `<` and `&` in the body, resulting in an unreadable string.

  • You cannot include the string `]]>` inside a CDATA section, as it marks the end of the section. If your content must contain this sequence, the common workaround is to split the CDATA section in two.
  • CDATA only prevents parsing; it is not a security feature. If you inject HTML wrapped in CDATA directly into your page, any XSS vulnerabilities will pass right through.
  • This tool preserves CDATA, comments, processing instructions, and DOCTYPE from the original document. If you uncheck "Keep comments", comments will be removed from the output.
xml
<!-- Escaped: hard to read -->
<description>&lt;p&gt;Today &amp; Tomorrow&lt;/p&gt;</description>

<!-- With CDATA: original text remains readable -->
<description><![CDATA[<p>Today & Tomorrow</p>]]></description>

Formatting Integrity and External Entities

The formatter only cleans up insignificant whitespace between elements. For elements with mixed content (text mixed with child elements), it keeps everything on a single line without adding line breaks. In an element like `<p>Hello <b>John Doe</b></p>`, the space after "Hello" is data. Pretty-printing it with indentation would change the rendered output.

The "Collapse empty tags" option converts empty elements from `<tag></tag>` to the self-closing form `<tag/>`. In the XML standard, these two are completely identical. However, if you're dealing with a legacy system that inspects the XML with simple string comparisons, it's safer to leave this option unchecked.

External entities (XXE) are not processed. The browser's built-in `DOMParser` does not fetch external DTDs or entities, so no network requests are made even if `SYSTEM` entity declarations are present in the document. However, this only means the tool itself is safe. It does *not* mean the same file is safe to feed into your server-side XML parser. Server-side parsers must be explicitly configured to disable external entities.

Frequently asked questions

Can I use this for HTML code?

No, this tool uses a strict XML parser. It will report errors for HTML tags that don't self-close (like <br>) or HTML-specific entities (like &nbsp;).

Does formatting change my original XML?

The structure is preserved. CDATA, comments, processing instructions, and attribute order are kept. Elements with mixed text and child tags are kept on one line to protect meaningful whitespace.

Is the error location always exact?

The tool shows the line and column where the browser's parser first detected a problem. This may be after the actual mistake, so if an error seems misplaced, check the lines above it for an unclosed tag.

Is my XML data sent to a server?

No. All formatting, validation, and analysis happen entirely in your browser. Your data is never sent to or stored on any server, ensuring your information remains private.