XML Formatter

Parses your XML in the browser, then re-indents it with 2 spaces, 4 spaces or tabs, or minifies it by removing indentation and comments. Text content is not changed.

Last updated
349 chars

About the XML Formatter

XML from RSS feeds, SOAP responses, Android layouts, Office files or configuration exports is often saved without line breaks. The formatter re-indents it so each element sits on its own line under its parent, using the indent you choose. Minify does the opposite: it removes indentation and comments to give the smallest single-line version.

Unlike formatters that work on raw text, this one lets your browser’s XML parser read the document first and then writes it out again from that structure. Two things follow from that. First, the input must be well-formed: a missing end tag or an unescaped & stops the process with the parser’s error message instead of producing misleading output. Second, the layout stays correct for awkward content such as CDATA sections, comments, namespace prefixes and attribute values containing >.

Text is never re-wrapped. An element that contains text, or a mix of text and child elements such as <p>Hello <b>world</b></p>, is written on one line exactly as it was, because adding whitespace inside it would change the data. Elements with xml:space set to preserve are also left as they are. In Format mode the XML declaration, the DOCTYPE and any comments around the root element are kept in place.

If you only need to know whether a file is well-formed and where it breaks, the XML Validator shows the failing line with a marker. For JSON data, use the JSON Formatter.

How to use the XML Formatter

  1. 1

    Paste your XML

    Replace the bookstore example in the Input XML box.

  2. 2

    Choose an indent

    Pick 2 spaces, 4 spaces or Tab from the Indent menu.

  3. 3

    Click Format or Minify

    Format produces indented output; Minify removes indentation and comments. Next to Output you see Well-formed or Not well-formed.

  4. 4

    Copy the result

    Click Copy above the output. The button is hidden while an error is shown.

What it can do

Parser-based formatting

The document is parsed by the browser first, so the layout always follows its real structure.

Text content untouched

Elements with text or mixed content are written as parsed, and xml:space preserve is respected.

Declaration and DOCTYPE kept

The XML declaration and DOCTYPE, including an internal subset, are copied from your input.

Minify

Removes whitespace between elements and all comments without changing text content.

Indent options

2 spaces, 4 spaces or tabs.

Limitations

  • Because the output is rebuilt from the parsed document, some cosmetic details change: attributes are always written with double quotes, empty elements become <tag/>, and character references such as &#169; are written as the character itself.
  • It checks well-formedness only and does not validate against a DTD or XSD schema.
  • Whitespace-only text between elements is treated as indentation and replaced. If that whitespace is meaningful in your format, set xml:space to preserve on the element.
  • Documents that rely on entities defined in a DTD may not come out exactly as they went in.

Privacy

Your XML is parsed and formatted by your browser’s built-in DOMParser; it is not uploaded to FlexyPdf.

Frequently asked questions

Why does it say Not well-formed when the file opens elsewhere?

Some programs tolerate mistakes that XML parsers must reject: an unescaped & in text (write &amp;), tags closed in the wrong order, more than one root element, or an HTML entity like &nbsp; that XML does not define. The message tells you where the parser stopped.

Will formatting change my data?

Text content and attribute values are kept. Only the whitespace between elements changes, along with the cosmetic details listed under Limitations, such as the quote style.

What does Minify remove?

All comments and the whitespace between elements. The XML declaration, the DOCTYPE, processing instructions, CDATA sections and text content are kept.

How is this different from the XML Validator?

Both use the same parser. This page is for reshaping XML, with indent options and minify. The XML Validator is for diagnosing it: it shows the failing line with a caret and counts elements, attributes and nesting depth.

Can it format HTML?

Only HTML written as well-formed XHTML. Ordinary HTML usually contains tags such as <br> without a closing slash, which an XML parser rejects. Use the HTML Beautifier for regular HTML.

Ratings & Reviews

—
No ratings yet
5
0
4
0
3
0
2
0
1
0

Rate XML Formatter

Help others by sharing your experience. Your rating is shown without your name.

0/600