XML Formatter
Paste XML to pretty print it with two or four spaces, or select Minified and copy the compact output. Text leaves, mixed content, CDATA and xml:space="preserve" regions stay together so spacing inside them is kept. The page checks matching tags and incomplete token boundaries; it is not a full XML or XSD validator. For a compact starting view, open the [XML minifier](/xml-formatter/minify).
Formatted XML appears here.
Multiline whitespace between child elements is rewritten unless kept above. Tag balance is checked; XML schema and full well-formedness are not validated.
Common questions
- How do I pretty print XML or format an XML file?
- Copy XML text from your file or response body into the editor, choose Formatted and set two or four spaces. Use Copy formatted to return the preview to your editor. There is no file picker, URL fetch or downloadable native application. XML namespaces and attributes are kept as text; the formatter does not resolve a namespace or evaluate a SOAP request.
- How do I minify XML?
- Select Minified and use Copy minified. The input remains unchanged while the preview and copied output remove eligible multiline indentation between child elements. Comments and declarations remain. Mixed text and xml:space regions can contain real line breaks, so minified output is not guaranteed to fit on one line.
- Does it preserve spaces in mixed content and CDATA?
- For an element such as <p>Hello <b>world</b> !</p>, the complete element is kept as written. Text-only leaves, CDATA regions, inline whitespace between child elements and xml:space="preserve" elements are also kept, including their nested content. Ordinary multiline indentation in an element-only region can still be changed.
- What if whitespace between elements is meaningful in my XML vocabulary?
- Turn on Keep all text whitespace. Any element containing a text token then remains as written, which can also retain indentation you hoped to remove. Without a schema, the formatter cannot know whether every whitespace-only text node is meaningful. Formatting changes bytes and is not XML canonicalization, signature preservation or a promise of lossless semantics.
- What does the tag check validate?
- It checks whether each opening tag has the expected closing tag and detects incomplete comments, CDATA, processing instructions and tag boundaries. It does not enforce the whole XML grammar: one root element, attribute uniqueness, valid entities and namespaces, every valid XML name and schema constraints are not all checked. A successful format is not proof that an XML parser or XSD validator will accept the document.
- Are comments, declarations and DOCTYPE preserved?
- Comments, CDATA, the XML declaration, processing instructions and a simple DOCTYPE without an internal subset remain as text. A DOCTYPE internal subset is refused before rewriting, rather than partially scanned. DTDs and external entities are never fetched or expanded; entity references remain their original text.
- Can it convert JSON, PDF or Word into XML?
- No. Formatting an existing XML document does not create XML from another format, extract a PDF or Word document, or infer an XSD. For an editable schema draft from a supported XML sample, use the [XML Schema Generator](/xml-schema-generator).
- Is the XML uploaded or remembered?
- Formatting and tag checks run in your browser. Your edited draft and indent choice can be remembered in local storage on this device. A page prefill does not replace the saved draft until you edit it. Loading the website still needs a connection; there is no separate offline package or editor extension.
Mixed text, text leaves, CDATA, inline child spacing and xml:space="preserve" regions are kept as written. Multiline whitespace between child elements may be rewritten unless Keep all text whitespace is selected. Checks cover tag balance and token boundaries, not full XML grammar or schema validity. DTD internal subsets are refused; nothing is fetched or expanded.