XML Formatter
Indent XML so its structure is easy to read, or minify it for transport. The formatter first checks that the document is well-formed, then rewrites only the whitespace between elements. Text, CDATA sections, comments, processing instructions, attributes and namespace prefixes are copied exactly as they are in your input.
Format Your XML
Where the error is
Formatted XML
Result
How to Use the XML Formatter
- Paste your XML into the box.
- Choose Pretty-print or Minify, and the indentation.
- Press Format. If the XML is not well-formed you get the line, column and a hint instead.
- Copy the result or download it as formatted.xml.
About This Tool
Developers reading SOAP, RSS, SVG, Android or Maven files, integrators comparing XML payloads, and anyone handed a single-line XML export.
Input: XML ยท Output: Formatted XML (.xml).
Features and Limitations
Features
- Well-formedness check first, with the exact line and column of the first error and a plain-English hint.
- Elements that mix text and child elements, and elements marked xml:space="preserve", are never re-indented, so no text value changes.
- Keeps CDATA, comments, processing instructions, the XML declaration, DOCTYPE, attributes and namespaces.
- Optional comment removal and one-attribute-per-line layout.
Limitations
- The input must be well-formed XML. The tool reports the problem; it does not repair broken markup.
- Entity references such as & are kept as written. Custom entities declared in a DTD are not expanded, and the browser's parser may reject documents that rely on them.
- Text inside elements is left as typed, so whitespace inside a text value is not trimmed.
- It checks that XML is well-formed, not that it is valid against a DTD or XSD schema.
- Results are computed in your browser; nothing you enter is sent to a server.
Example
1
Frequently Asked Questions
Will formatting change my data?
Only whitespace between elements is changed. Text values, attributes, comments and CDATA are copied unchanged, and elements that mix text with child elements are left exactly as written.
Why does it say my XML is not well-formed?
Typical causes are a closing tag that does not match, an unquoted attribute value, an unescaped & or <, text outside the root element, or whitespace before the XML declaration. The message names the problem and the position.
Does it validate against a schema?
No. It checks well-formedness only. Schema (XSD) and DTD validation need a dedicated validator.
Is my XML uploaded?
No. It is parsed in your browser. External entities and DTDs are never fetched, so there is no XXE risk from pasting a document here.
Does it handle namespaces?
Yes. Prefixes and xmlns declarations are kept as written, and a prefix that is not declared is reported as an error.
Related Tools
More like this: all Format & Validate tools, all Developer & Web tools or the TinySandy home page.