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
- The XML Formatter
- Some XML, such as an API response
Steps
Paste the XML
Load the example: a book catalogue in one long line, with a namespace, a comment and an escaped ampersand.
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>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.
Copy or download
Copy the result, or download it as
formatted.xml. Notice thatDatos & formatosis unchanged: formatting never alters text or entities.
Try it yourself
Opens the XML Viewer, Formatter & Validator with this tutorial's sample loaded.
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: