About XML Formatter
Indent XML by nesting depth, collapse it back to one line, or check whether it parses at all. Documents are validated with the browser’s own XML parser before anything is reformatted.
What is preserved
Formatting works on the tag and text stream rather than a rebuilt DOM tree, so comments, processing instructions, CDATA sections and the XML declaration all survive exactly as written. A DOM round-trip would quietly drop or rewrite several of them.
Elements holding a single value
An element whose only content is text is kept on one line, so a list of simple fields reads as a list instead of tripling in height.
Frequently asked questions
- Why is my XML reported as invalid when it looks fine?
- XML is far stricter than HTML: every tag must be closed, tag names are case sensitive, and a raw & or < inside text must be escaped as & or <. An unescaped ampersand inside a URL is the most common cause.
- Does reformatting change my document?
- It changes whitespace between elements. That is insignificant for most consumers, but if a schema declares an element as whitespace-sensitive, or the document is signed, reformatting can matter.
- Can it format HTML too?
- Use the HTML formatter instead. HTML permits unclosed tags and implicit nesting that an XML parser rejects outright.