How to Format an XML File on Android (Pretty-Print)

You have an .xml file or a block of XML, and it is a mess - everything on one line, or indented inconsistently so the nesting is impossible to follow. What you want is formatted XML: proper indentation, one element per line, and a clear tree. This guide explains what formatting does and how to pretty-print XML on an Android phone.

Short version: open the XML in a viewer that lays it out as a formatted tree. It adds the indentation for you and highlights tags, attributes and values so the structure is obvious.

What "formatting" XML actually means

XML nests elements inside elements. The same document can be written compact, to save space:

<catalog><book id="1"><title>A</title><price>12</price></book></catalog>

Or formatted (also called pretty-printed or beautified), with indentation and line breaks:

<catalog>
  <book id="1">
    <title>A</title>
    <price>12</price>
  </book>
</catalog>

Both are the same document - formatting changes nothing about the content. It only adds whitespace so a person can read the structure. That is why "format", "pretty-print" and "beautify" all describe the same thing.

Why XML often arrives unformatted

Config files, API payloads, exports and feeds are frequently written compact, because removing whitespace makes them smaller and faster to move between systems. That is fine for machines, but on your phone a basic text preview shows the file exactly as stored - a dense block - and leaves you to untangle it yourself.

How to format an XML file on Android, step by step

1. Install an XML viewer

Install XML Viewer from Google Play. The core viewer is free and needs no account.

2. Open your XML file

Tap Open XML file and pick your file with the Android document picker - from device storage, Downloads, or another app such as mail or cloud storage. You can also open it directly from another app, or paste XML text.

3. Read the formatted tree

The XML is laid out in a formatted tree with proper indentation and syntax highlighting for tags, attributes and values. Expand and collapse nodes to move through it, use Go to line to jump to a specific line, and long-press a node to inspect its attributes and copy values.

Once it is readable

Formatting is usually the first step. From there you can search across node names, attributes and values to jump to what you need, bookmark nodes for quick navigation, and open the properties panel to see the document's root element, encoding, element and attribute counts, and maximum depth. If you need to keep the tidied-up version, saving and sharing the formatted XML is part of Pro.

The app behind this guide

XML Viewer is my own Android app, and it is what the steps above describe. It opens the file in a formatted tree view, works completely offline for local files, and the core viewer is free with no account required. Your files stay on your device - no uploads, no cloud processing.

Free covers the essentials: open files, read the formatted tree, expand and collapse nodes, search text, jump to a line, copy values, and switch theme. Pro adds larger files, XPath search, saved bookmarks, Copy XPath, save and share, and JSON/PDF export.

Get it on Google Play

Keep reading


โ†‘