Skip to content

XML Formatter, Viewer & Beautifier

Beautify and view XML online. Paste minified or messy XML and this XML formatter pretty-prints it with clean indentation, syntax highlighting and line numbers, so it is easy to read, search or commit.

Runs in your browser Free, no sign-up
Loading tool workspace...

What is XML Formatter?

This XML formatter turns minified or badly indented XML into neatly structured, readable XML. Paste a SOAP message, RSS feed, sitemap, configuration file or API response, and every element is placed on its own line with indentation that reflects the nesting, so you can see the document's structure at a glance.

It doubles as an XML viewer online. The Text view shows the formatted XML syntax highlighted with line numbers, and Ctrl+F searches it. The Tree view turns the document into a collapsible XML tree, so you can fold away the parts you don't need and explore a long feed or SOAP response one level at a time.

The XML is checked as part of formatting: if it is not well-formed, for example because of a mismatched closing tag or an unescaped &, you get an error instead of output, so you know the document needs fixing before you use it.

How to use XML Formatter

  1. Paste your XML into the input panel.
  2. The formatted XML appears in the output panel immediately; switch between Text and Tree to read it as highlighted text or as a collapsible tree.
  3. If you see "Invalid XML", check the document with the XML Validator to find the exact error.
  4. Copy or download the formatted XML.

Key features

  • Pretty prints XML with one element per line and nested indentation
  • Checks well-formedness while formatting
  • Preserves attributes, comments, text and CDATA
  • Handles SOAP, RSS, Atom, sitemaps, SVG and config files
  • Syntax highlighting and line numbers for reading XML
  • Tree view with collapsible elements, plus Expand all and Collapse all
  • Search the formatted XML with Ctrl+F
  • Copy or download the result
  • Runs entirely in your browser

Common use cases

  • Reading SOAP requests and responses
  • Inspecting RSS and Atom feeds and XML sitemaps
  • Formatting Maven pom.xml, Android manifests and .NET config files
  • Making minified SVG markup readable
  • Preparing XML samples for documentation

Technical details & standards

The document is parsed with the browser's DOMParser as application/xml, which enforces XML 1.0 well-formedness. It is then re-serialized through an XSLT identity transform with indentation enabled, so the element structure, attributes, text, comments and CDATA sections are preserved while whitespace is normalized.

The XML declaration (<?xml version="1.0" encoding="UTF-8"?>) is omitted from the output; add it back if your consumer requires it. Indentation width is determined by the browser's XSLT engine. Formatting runs locally, so documents containing credentials or personal data are not uploaded.

Format XML in Python and with xmllint

To pretty-print XML in a script or CI job, use the standard library in Python or xmllint in the terminal. Both turn <note><to>Alex</to><from>Sam</from></note> into the indented version below.

Python

from xml.dom import minidom

xml = "<note><to>Alex</to><from>Sam</from></note>"
print(minidom.parseString(xml).toprettyxml(indent="  "))
# <?xml version="1.0" ?>
# <note>
#   <to>Alex</to>
#   <from>Sam</from>
# </note>

Terminal (xmllint)

xmllint --format note.xml                      # print indented XML
xmllint --format note.xml --output pretty.xml  # save it to a file

Frequently asked questions

What is an XML formatter?

An XML formatter, also called an XML beautifier or pretty printer, rewrites XML with line breaks and indentation so the nesting of elements is easy to follow, without changing the data. This one also checks that the XML is well-formed and shows Invalid XML when it is not.

How do I format an XML file?

Open the file in any text editor, copy its contents and paste them here; the indented XML appears at once, and the Download button saves it. In VS Code, install the XML extension by Red Hat and run Format Document. On the command line, xmllint --format file.xml > pretty.xml writes an indented copy.

How do I pretty print XML?

Paste the XML into the input panel and the indented version appears instantly. Nothing is uploaded, so it is safe for configuration files and API payloads.

Can I use this as an XML viewer online?

Yes. Paste the XML and the Text view shows it indented, syntax highlighted and with line numbers, with Ctrl+F to search inside it. Switch to Tree to see it as a collapsible XML tree: click any element to fold or unfold it, or use Expand all and Collapse all.

How do I open and read an .xml file?

Open the .xml file in any text editor, copy everything and paste it here to read it formatted and highlighted. A browser can also open an .xml file directly, but minified XML stays on one line there, which is hard to read.

Why does it say Invalid XML?

The document is not well-formed: a tag may be unclosed or mismatched, an attribute unquoted, or a & or < unescaped. Paste it into the XML Validator to see the exact line and column of the error.

Does formatting change my XML data?

No. Elements, attributes, text and comments are preserved; only indentation and line breaks change. The XML declaration line is not included in the output, so add it back if you need it.

Can I convert XML to JSON?

Yes, with the XML to JSON Converter, which turns elements into JSON objects and repeated elements into arrays.

How do I format XML in VS Code?

VS Code has no built-in XML formatter. Install the XML extension by Red Hat, then run Format Document (Shift+Alt+F on Windows, Shift+Option+F on macOS, Ctrl+Shift+I on Linux). For a quick one-off format without installing anything, paste the XML here.

How do I format XML in Notepad++ or IntelliJ?

Notepad++: install XML Tools from Plugins > Plugins Admin, then choose Plugins > XML Tools > Pretty print (XML only). IntelliJ IDEA and other JetBrains IDEs: open the file and use Code > Reformat Code (Ctrl+Alt+L, or Cmd+Option+L on macOS). For a quick format without installing anything, paste the XML here.

How do I format XML on Linux?

Use xmllint from libxml2: xmllint --format file.xml prints the file indented, and adding --output pretty.xml saves the result instead. xmllint is preinstalled on macOS; on Debian or Ubuntu, install the libxml2-utils package.

Is my data safe?

Processing happens locally in your browser. Tool input is not sent to CodeUnpack servers.

Does it work offline?

Once the page has loaded, this tool can process input without an internet connection.

More formatters & viewers tools

View all