XML Viewer & Formatter

Check that XML is well-formed, pretty print or minify it, and explore the element tree — in your browser.

Drop an XML file here

or click to browse — read locally, max 10 MB

View
Output

Paste XML, drop a file or load the example to start.

Working with JSON instead? Explore it in the JSON Viewer or convert it with JSON to XML.

What this XML viewer does

XML still runs a lot of the plumbing: SOAP services, RSS feeds, sitemaps, Android layouts, Maven and .NET project files, SVG images and office document internals. It often arrives as one enormous line, and a single unclosed tag makes the whole file unreadable for the program that consumes it. This tool answers two questions quickly: is this XML well-formed, and what does it look like when it is properly indented?

Your browser parses the text with its native XML parser. If that fails you get the parser's message and, when the browser provides it, the line and column with the surrounding source. If it succeeds, the tool walks the parsed document and writes it back out with clean indentation, or with all formatting whitespace removed.

How to use it

  1. Paste XML into XML input, drop a file on the upload area, or click Load example.
  2. Check the status line: Well-formed XML with the root element and element count, or a red error box.
  3. Under View, keep Formatted XML for text output or switch to Tree to fold elements.
  4. Choose Pretty print or Minify, the Indentation and, if you like, Remove comments.
  5. Click Copy or Download .xml. In the tree, Expand all and Collapse all reset every branch.

Worked example

This one-line input (shortened from the built-in example) contains a namespace, an entity, a comment, CDATA and mixed content:

<?xml version="1.0" encoding="UTF-8"?><catalog xmlns:dc="http://purl.org/dc/elements/1.1/"><!-- 2 books --><book id="bk101" lang="en"><dc:title>XML &amp; You</dc:title><price currency="EUR">29.99</price><desc><![CDATA[Use <tags> freely]]></desc></book><book id="bk102"><dc:title>Second</dc:title><note>Read <b>this</b> first</note><empty/></book></catalog>

With Pretty print and 2 spaces the tool produces:

<?xml version="1.0" encoding="UTF-8"?>
<catalog xmlns:dc="http://purl.org/dc/elements/1.1/">
  <!-- 2 books -->
  <book id="bk101" lang="en">
    <dc:title>XML &amp; You</dc:title>
    <price currency="EUR">29.99</price>
    <desc><![CDATA[Use <tags> freely]]></desc>
  </book>
  <book id="bk102">
    <dc:title>Second</dc:title>
    <note>Read <b>this</b> first</note>
    <empty/>
  </book>
</catalog>

Note that <note> stays on one line: it mixes text and a <b> element, and adding line breaks there would change the text. Switching to Minify with Remove comments gives back the single line without the comment.

Options and formatting rules

  • Pretty print puts each child element, comment and processing instruction on its own line. Elements containing only text stay on one line with the text untouched.
  • Minify removes whitespace-only text between elements. Text content, mixed content and xml:space="preserve" sections keep their spaces.
  • Indentation sets the unit used per level: 2 spaces, 4 spaces or a tab.
  • Remove comments drops every <!-- … -->. CDATA sections, processing instructions such as <?xml-stylesheet?>, the DOCTYPE and the XML declaration are always kept.
  • Escaping: text is written with &amp;, &lt; and &gt;; attribute values always use double quotes.
  • Tree shows elements with their attributes (namespace declarations in grey), text, CDATA, comments and processing instructions. Elements with many children show 200 at a time.

Limitations

  • Well-formedness only — no XSD, DTD or RELAX NG validation.
  • Entity and character references are expanded by the parser, so &#169; comes out as ©, and a DOCTYPE internal subset may not be reproduced by every browser.
  • Attribute quotes become double quotes and the spacing inside tags is normalised.
  • Error positions and wording depend on the browser (Chrome, Firefox and Safari word them differently).
  • Input is limited to 10 MB; the tree shows up to 50,000 nodes and syntax colouring turns off above 200,000 characters.

Tips and common errors

  • Extra content at the end of the document usually means two root elements — wrap them in one parent.
  • A bare & in text must be written as &amp;, or the text wrapped in CDATA.
  • Tag names are case-sensitive: <Item>…</item> is a mismatch.
  • Converting data between formats? Try JSON to XML, or inspect JSON in the JSON Viewer.

Frequently Asked Questions

Is my XML sent to a server?

No. The XML is parsed by your browser's built-in DOMParser and formatted by JavaScript in the page. Nothing is uploaded, and scripts or external resources referenced in the document are never loaded.

Does this tool validate XML against an XSD or DTD?

No. It checks that the document is well-formed: one root element, every tag closed and correctly nested, quoted attributes and legal characters. Checking against a schema (XSD, DTD or RELAX NG) requires a validating parser such as xmllint.

Can it format minified XML that is all on one line?

Yes. The output is rebuilt from the parsed element tree, not from the original line breaks, so a one-line SOAP response or sitemap is indented properly.

Will pretty printing change my data?

Only whitespace between elements is changed. Text inside elements, mixed content such as <p>Hi <b>there</b></p> and anything under xml:space="preserve" is written exactly as parsed. Entities like &#169; are written as the character they stand for, which is equivalent XML.

Why does the error say a different line than I expected?

The parser reports where it noticed the problem, which is often after the real mistake. For example a tag that was never closed is detected at the closing tag of its parent. The line and column come from your browser; if it reports none, only the message is shown.

Which file types work?

Any XML-based format: .xml, .svg, .xsd, .xsl, RSS and Atom feeds, sitemaps, .plist, .csproj, .config, KML and GPX. HTML is not XML and usually fails because of unclosed tags like <br>.