Skip to content
toolbelt
Back to Guides

Making XML Readable Without Breaking It

By ·

Updated

SOAP responses and legacy exports arrive as one unbroken line. Indenting them reveals the structure — and the problems.

What is this tool?

XML is verbose by nature, and formatters make that obvious. Indenting a document shows you the tree you actually have, rather than the tree you assumed.

How it works

The document is parsed into a tree and re-printed with indentation. Whitespace between elements is not meaningful in XML, so this is safe. Whitespace inside text content is preserved, because there it does matter.

Example

Before:
<soap:Envelope><soap:Body><GetUser><id>42</id><name>Ada</name></GetUser></soap:Body></soap:Envelope>

After:
<soap:Envelope>
  <soap:Body>
    <GetUser>
      <id>42</id>
      <name>Ada</name>
    </GetUser>
  </soap:Body>
</soap:Envelope>

When to use it

Any time you inherit an integration. Older systems speak XML, and the response is usually minified by whatever generated it. Also before diffing two XML responses, since a one-line diff is useless.

Optimization Tips

Watch the namespace prefixes. A document can be valid while every prefix is wrong, and the formatted output is where you notice that soap: and ns0: appear where you expected one consistent prefix.

Frequently Asked Questions

Does indenting change the document?
Only whitespace between elements. Any XML parser sees the same tree.
My XML has mixed content and looks wrong now
That is expected. Text with inline markup cannot be indented without changing it, so the formatter leaves it alone.
Why does it fail on an unclosed tag?
XML requires every tag to close. The error shows which element was still open when the parser reached the end.
Can it handle CDATA?
Yes, CDATA sections are preserved as-is and their contents are not reindented.

Ready to try it out?

Put this knowledge into practice with our free tool.

Go to Tool

Related tools