- iTechFever Tools
- Developer Tools
- XML Formatter
XML Formatter
Paste markup that arrived as one long line and get it back readable. Comments, CDATA and declarations are copied through untouched, and a tag that closes in the wrong place is reported with its line.
Runs entirely in your browser. Your files are never uploaded.
How to use XML Formatter
- 1Paste the XML, SVG or HTML fragment.
- 2Pick an indent, or minify it instead.
- 3Read the error if the tags do not line up.
- 4Copy the formatted markup.
Structure is checked, nothing else
The one thing a formatter cannot work around is tags that do not nest. If a document closes <b> while <i> is still open, there is no correct way to indent it, so that is reported with the line and the tag involved.
Everything else is left alone. Entities are not resolved, namespaces are not validated, and no schema is consulted, because none of that is what someone looking at a SOAP response needs in the moment.
What gets copied through
Comments, CDATA sections, processing instructions and the doctype are reproduced exactly, including a doctype with an internal subset in square brackets. Whitespace inside an attribute value is kept, while the gaps between attributes are collapsed to one space.
HTML void elements, the likes of <br> and <img>, are understood to need no closing tag, so pasting an HTML fragment works. They come back in the self-closing form, which is valid in both HTML and XML.
Where indenting changes meaning
An element holding both text and child elements is the awkward case. Putting each child on its own line adds whitespace that did not exist, and in XHTML the space between two inline tags is visible in the rendered page.
An element with nothing but text is kept on one line for that reason. Mixed content is indented and its text trimmed, so check the result before formatting markup that goes straight into a browser.
Limits
- Tags must nest correctly. Overlapping tags are an error rather than something to repair.
- No schema, DTD or namespace validation, and entities are left as written.
- Whitespace inside mixed content is normalised, which can matter in XHTML.
- Attribute order and quoting are preserved as they were, not canonicalised.
Frequently asked questions
- Can I format HTML with it?
- A fragment, yes, including the void tags that carry no closing tag. A whole page written with optional closing tags left out, as HTML allows, will report an unclosed element, because the formatter follows XML nesting rules.
- Will it format an SVG file?
- Yes. SVG is XML, so paste the file's contents in. For large icon sets the minified output is often what you want, since it is what ends up in the page.
- Why did my spacing between tags disappear?
- Indenting an element that holds both text and tags means deciding where the line breaks go. The text is trimmed in that case, which is standard behaviour for a formatter and worth checking if the markup is XHTML that a browser renders directly.