XML Formatter

Indent XML while respecting mixed content and xml:space="preserve". DTDs and external entities are rejected: nothing is fetched or expanded.

Options

Input

Up to 5 MiB. The file is not uploaded: it is read in your browser.

Ctrl + Enter to run

Result

The XML formatter indents nested elements so the structure is easy to read. When an element mixes text and tags (mixed content, such as <p>Hello <b>world</b></p>) or declares xml:space="preserve", its content is kept exactly as is so the meaning does not change.

For security, documents with a DOCTYPE are rejected: there are no external entities or expansions to process.

How to use it

  1. Paste the XML or open a local file.
  2. Pick the indentation.
  3. Press Run and copy or download the result.

Example

Example input
<?xml version="1.0" encoding="UTF-8"?><catalog><book id="b1"><title>Guía de ejemplo</title><price currency="EUR">19.90</price></book><note>Texto <b>mixto</b> conservado</note></catalog>
Result
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book id="b1">
    <title>Guía de ejemplo</title>
    <price currency="EUR">19.90</price>
  </book>
  <note>Texto <b>mixto</b> conservado</note>
</catalog>

Limitations

  • No DTDs or user-defined entities; only &lt; &gt; &amp; &apos; &quot; and numeric references.
  • Whitespace between elements is normalized.
  • Attributes are separated by one space and keep their original quotes.

FAQ

Why is my XML with a DOCTYPE rejected?
DTDs can declare entities that read files or URLs (XXE) or expand exponentially. This tool never processes them.
Does it change my text content?
No: each element’s text is kept; only whitespace between elements without mixed content is added or removed.

Related tools

References