XML formatter

Format XML with 2-space, 4-space or tab indentation. Checks the document is well formed first and shows the line and column of any error. Runs in your browser.

Processed locally in your browser
Loading tool…

About XML formatter

The XML formatter puts each element on its own line and indents it according to its depth, turning a single-line SOAP response, sitemap or config file into something you can read. Elements that contain only text, such as <title>Home</title>, stay on one line so the output is not padded with needless lines.

Before formatting, the document is checked with the fast-xml-parser validator. If a tag is not closed or an attribute is malformed, you get the line and column of the problem instead of misleading output. Comments, CDATA sections, processing instructions and DOCTYPE declarations are kept in place.

How to use XML formatter

  1. Paste XML into the input box, or open or drop an .xml file.
  2. Choose 2 spaces, 4 spaces or Tabs for the indentation.
  3. Read the status bar: “Valid XML” with a character count, or an error with its line and column.
  4. Copy the formatted XML or download it as an .xml file.

Features

  • Indents nested elements with 2 spaces, 4 spaces or tabs.
  • Keeps elements with only text, or no content, on a single line.
  • Preserves comments, CDATA sections, processing instructions and the XML declaration.
  • Checks well-formedness first and reports errors with line and column.
  • Handles files up to 2 MB in a background worker.

Common uses

  • Reading SOAP or other XML API responses captured from logs.
  • Reviewing a sitemap.xml, RSS or Atom feed before publishing it.
  • Tidying Android layouts, Maven pom.xml files or .csproj project files.
  • Preparing XML examples for documentation or bug reports.

Tips

  • Whitespace around text is trimmed and blank text between tags is removed. If whitespace inside text nodes matters to your application, check the result before replacing the original.
  • Text in an element that also contains child elements, such as <p>Hello <b>world</b></p>, is split onto separate lines, which adds whitespace around it.

Frequently asked questions

Does formatting change the meaning of my XML?

Element names, attributes and their order are unchanged; only whitespace is modified. Indentation is added between elements and text is trimmed. For data-oriented XML this makes no difference, but documents that mix text and markup, such as XHTML paragraphs, gain line breaks inside their text.

What does “Invalid XML at line 3, column 5” mean?

The validator found a well-formedness error at that position, for example a closing tag that does not match its opening tag, an unescaped & or < in text, a missing quote around an attribute value, or a repeated attribute. Fix that spot and the document will format.

Does it validate against a DTD or XSD schema?

No. It checks that the document is well formed, which every XML parser requires, but it does not load DTDs or XML Schemas. It cannot confirm that elements and attributes are the ones a particular schema allows.

Which indentation should I use for XML?

There is no standard. Two spaces keeps deeply nested documents narrow, four spaces is common in Java and .NET projects, and tabs let each editor choose the width. Pick whatever the rest of your project uses so diffs stay small.

Can I format HTML with the XML formatter?

Only if it is well-formed XML, such as XHTML. Ordinary HTML allows unclosed tags like <br> and <li>, which XML treats as errors. Use the HTML formatter for regular web pages.

Is my input uploaded?

Tools run in your browser. Files, text and results are not uploaded to our servers and are cleared when you leave the tool.

Your privacy comes first

Tools run in your browser. Files, text and results are not uploaded to our servers and are cleared when you leave the tool.

Find your next tool
↑ ↓ · Enter ↵Esc · Close search