XML Viewer, Formatter & Validator · Tutorial

How to make XML from an API readable

5 min readbeginnerUpdated

An API or export gives you XML on a single line. You will format it so the structure is clear, choose an indent style, and copy it into a ticket or document.

What you need

Steps

  1. Paste the XML

    Load the example: a book catalogue in one long line, with a namespace, a comment and an escaped ampersand.

  2. Read the structure

    Each book is now a block, with its author, title, price and date indented underneath. The status line counts elements and attributes and shows how deep the document goes.

    <book id="bk101" lang="en">
      <author>Okafor, Amara</author>
      <title>Practical XML</title>
  3. Match your style

    Pick 4 spaces or tabs under Indent if your project uses them. Choose One per line in the @ (attributes) menu when elements carry many attributes.

  4. Copy or download

    Copy the result, or download it as formatted.xml. Notice that Datos &amp; formatos is unchanged: formatting never alters text or entities.

Try it yourself

Opens the XML Viewer, Formatter & Validator with this tutorial's sample loaded.

Try it now

Common mistakes

Pasting HTML
HTML allows unclosed tags like <br> that XML doesn’t. Use an HTML formatter for web pages.
Expecting it to fix errors
If the XML is broken, the formatter tells you where, but you need to fix it. The how to fix invalid XML tutorial covers common fixes.

Next steps

Go back to the XML Viewer, Formatter & Validator, or keep going with one of these:

Tutorial · 6 min · beginner

How to find and fix errors in invalid XML

Use the XML formatter's live check to locate an unclosed tag and an unescaped ampersand, fix them one by one, and confirm the document is well-formed.

Tutorial · 8 min · beginner

How to select XML elements with XPath

Learn the XPath expressions you will use most, from simple paths to filters on attributes and values, by trying them on a sample document.