Orpheus

Format XML

Indent it, or strip it back down.

Options
Action
Indent with
Result

Everything is processed in this tab. Nothing you paste is sent anywhere.

Every tool runs entirely in your browser. Your files are never uploaded to a server.

Formatting XML indents each element by its depth so the structure is visible. It changes only whitespace between tags — the document parses identically either way.

How to use XML Formatter

  1. Paste your XML. A fragment, a document, a config file or an API response.
  2. Choose indent or minify. Indent for reading, minify for transmission.
  3. Copy the result. CDATA sections and comments come through untouched.

About formatting XML

XML formatting is a readability operation. The parser does not care how a document is laid out — whitespace between elements is insignificant in most contexts — so indenting by depth is safe and makes structure visible in a way a single-line document never is. That said, "most contexts" is doing real work in that sentence, and it is where formatters go wrong. Two constructs must survive untouched. A CDATA section exists specifically to hold characters that would otherwise be parsed as markup, so everything inside it is data and reindenting it changes the document. Comments are the same in practice, since their content is frequently meaningful to whoever left them. Both are lifted out before any whitespace manipulation and restored afterwards. Mixed content is the subtler case. An element containing both text and child elements — common in document-oriented XML like DocBook or XHTML — has whitespace that genuinely affects rendering, because the text nodes around the children are part of the content. Pushing text onto its own indented line inserts whitespace that was not there. Keeping short text content on the same line as its tags avoids the worst of it and is also more readable. The tag-balance check here counts rather than parses, which catches the common error of an unclosed element without pulling a parser into a page that ships no dependencies. It is not validation: a document can balance perfectly and still violate its schema.

Frequently asked questions

Does indenting change the document?
It changes whitespace between elements, which XML parsers generally treat as insignificant. It can matter where an element's content is mixed text and markup, which is why text is kept on the same line as its tags here rather than being pushed onto its own.
Why is CDATA left alone?
Because everything inside a CDATA section is character data by definition — that is the entire purpose of the construct. Reindenting it would alter the data, which is the one thing a formatter must never do.
What is the difference between XML and HTML here?
XML requires every element to be closed and is case sensitive; HTML permits unclosed tags like <br> and is not. That strictness is why an unclosed tag can be detected by counting, and why an XML parser rejects documents a browser would happily render.
Does this validate against a schema?
No. It checks that tags balance and nothing more. Validating against a DTD or XSD requires the schema itself and a real validating parser, which is a different job from formatting.
Should I minify XML for transmission?
Rarely worth it on its own. Compression already handles repeated indentation extremely well, so the saving over a gzipped connection is small. It is more useful when embedding a document in a single-line field or a log entry.

Last updated