Skip to content
Devtoolry

XML Formatter

Pretty print XML online with proper indentation. Malformed XML is reported with its line and column, so you can find broken tags fast. Runs in your browser.

Runs in your browser · Nothing uploadedFree · No sign-up

Something not working, or missing a feature? Send feedback

About the XML Formatter

The XML Formatter pretty-prints XML with clean indentation while keeping mixed content (text with inline elements) on one line, so the meaning of your document does not change.

Everything runs in your browser, so your input is never uploaded to a server.

How to use the XML Formatter

  1. Paste XML or open a file.
  2. Choose the indentation.
  3. Fix any error at the reported line and column, then copy or download the result.

Example

Indent a single-line SOAP response

Input

<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetPriceResponse><Price currency="EUR">19.99</Price><InStock>true</InStock></GetPriceResponse></soap:Body></soap:Envelope>

Result

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetPriceResponse>
      <Price currency="EUR">19.99</Price>
      <InStock>true</InStock>
    </GetPriceResponse>
  </soap:Body>
</soap:Envelope>

The declaration stays at the top, each element is indented by nesting level, and elements that only contain text stay on one line.

Common mistakes

  • An unescaped & in text. A bare & (as in "Tom & Jerry") is a syntax error in XML. Write it as &amp;, or wrap the text in a CDATA section.
  • Mismatched tag case. XML is case-sensitive, so <Item> must be closed with </Item>, not </item>. The error points to the closing tag that does not match.
  • Content before the declaration. Nothing, not even a blank line or a byte order mark, may come before <?xml ...?>. Remove it if the error mentions the declaration.

Works well with the XML Formatter

Frequently asked questions

Why is some content kept on one line?

Inside elements that mix text and tags, whitespace is part of the content. Adding line breaks there would change the text, so it is left as written.

Is the XML declaration kept?

Yes, the <?xml ...?> declaration is preserved at the top of the output.

Are comments and CDATA kept?

Yes. Comments, CDATA sections and processing instructions are kept and indented with the surrounding elements.

Can it format HTML?

Only XHTML, which is valid XML. For regular HTML, with void elements such as <br> and unquoted attributes, use the HTML Formatter.