When you need an XML beautifier
XML is often sent and stored with all the line breaks removed. You meet it in forms like these:
- a SOAP request or response copied from a log or a debugging tool,
- an RSS or Atom feed, or a sitemap, that a server prints on one line,
- an API response or a message from a queue,
- an SVG or configuration file that a tool has minified,
- a value in a database column that holds XML.
The beautifier adds the line breaks and the indentation that these sources remove, so that you can see how the elements are nested and where an attribute or a value sits.
Example
<?xml version="1.0"?><feed><entry id="1"><title>First</title><link href="http://example.com/1"/></entry><entry id="2"><title>Second</title><link href="http://example.com/2"/></entry></feed>
becomes:
<?xml version="1.0"?>
<feed>
<entry id="1">
<title>First</title>
<link href="http://example.com/1"/>
</entry>
<entry id="2">
<title>Second</title>
<link href="http://example.com/2"/>
</entry>
</feed>
How to read a long XML document
- Beautify it first, so that every element has its own line.
- Find the root element and its direct children. They show what the document is made of.
- Follow one branch down to the value you need. The indentation shows the path.
- Look at the attributes of the elements on that path. A namespace prefix such as
soap:tells you which vocabulary an element comes from.
What the beautifier keeps
- Mixed content (text with elements inside) is copied exactly, so that the spaces in a paragraph do not change.
- CDATA sections, comments, processing instructions and the DOCTYPE are kept.
- An element with
xml:space="preserve"is not touched.
Beautifier or formatter?
The two names describe the same job. This page is set up for the common case of unreadable XML, and the XML formatter page has the same options and is meant for tidying XML that you write yourself. Both keep the data and change only the layout.
If nothing happens
The XML must be well-formed. If it has an error, the tool lists it with the line and column. XML copied from a log often has an unescaped ampersand or is cut off at the end. The XML validator explains the errors and fixes bare ampersands.
See also the XML minifier for the reverse, the XML formatting guide, the XML to JSON converter and the HTML beautifier.