An XML beautifier adds line breaks and indentation so nested elements are easier to inspect. A minifier removes comments and unnecessary-looking whitespace to create compact output. This tool performs both operations locally and checks the source with the browser's XML parser for well-formedness errors.
Formatting is not neutral for every XML document. The implementation trims text tokens and the minifier collapses whitespace inside them, so use it primarily for data-oriented XML where inter-element whitespace is insignificant. Preserve the original whenever mixed content, signatures, or exact bytes matter.
How to Use the XML Beautifier and Minifier
Format the sample or replace it with your own XML source.
- Select Beautify or Minify under Action.
- In Beautify mode, choose 2 spaces, 4 spaces, or Tab from Indent.
- Paste or type XML into Source code; the Output updates after a short pause.
- Read the status for input and output byte counts or a well-formedness warning.
- Select Copy to copy the current Output.
- Select Use output as input to replace Source code with the result and run the operation again.
How XML Beautification and Well-Formedness Checking Work
Well-formed XML follows the document-level syntax rules: elements are properly nested, start and end tags agree, attribute values are quoted, and the document has an appropriate root structure. A well-formed document is not necessarily valid against a DTD, XML Schema, or application-specific contract.
This formatter tokenizes declarations, processing instructions, doctypes, comments, CDATA sections, tags, and text. In Beautify mode it tracks element depth and writes each structural token at the selected indentation. A simple element containing only text, such as <name>Ada</name>, stays on one line.
After producing output, the page parses the original Source code with DOMParser using the application/xml media type. If the browser returns a parser error, the output remains visible but the status begins Formatted, but the XML is not well-formed: followed by the browser's diagnostic. Because parser messages come from the browser, their exact wording can differ by engine.
The formatter is not an XML repair tool. It may indent malformed markup into something that looks structured, but the warning remains the relevant result. It also does not validate a schema, resolve application rules, or confirm that referenced resources exist.
XML Declarations, Namespaces, CDATA, and Doctypes
XML declarations and processing instructions are kept as tokens and placed on their own formatted lines. Comments, CDATA sections, and doctypes are also recognized as single tokens by the formatter. Beautify preserves comments, whereas Minify removes ordinary XML comments.
Namespaces are expressed through names and xmlns attributes. This tool preserves those tag and attribute strings, but it does not resolve namespace URIs or verify whether prefixes are declared correctly beyond whatever the browser's well-formedness parser reports. It performs no namespace-aware reordering or canonicalization.
CDATA protects text from being interpreted as markup until ]]> closes the section. The formatter keeps a recognized CDATA block intact rather than reindenting its internal content. Similarly, the tokenizer recognizes a doctype, including an internal subset matched by its pattern, but the tool is not a DTD validator.
For JSON-shaped data rather than XML, the JSON formatter applies JSON parsing and indentation rules. Do not convert between the formats merely to format a document; their data models differ in attributes, ordering, namespaces, and mixed content.
What XML Minification Removes and Changes
Minify trims the document, removes comment tokens, discards whitespace-only text tokens, and collapses each remaining text token's whitespace runs to one space. It then joins the tokens without added line breaks. Tags, declarations, CDATA blocks, and recognized doctypes remain in the output.
That behavior can change meaning. In mixed content such as <p>Hello <b>XML</b> reader</p>, spaces live in text nodes around the child element. Trimming and joining tokens can produce Hello<b>XML</b>reader, changing the rendered sentence. Whitespace can also be significant in document formats, test fixtures, and applications using xml:space="preserve"; this minifier does not implement special handling for that attribute.
Minification is not XML canonicalization. It does not normalize namespace declarations, sort attributes, expand entities, standardize character encodings, or produce Canonical XML. If a document is digitally signed or hashed, even harmless-looking presentation changes alter its bytes and can invalidate the signature.
Check representative documents with the consuming application before adopting minification. A smaller byte count in the status describes the text size change in the browser, not a guarantee of equivalent XML application behavior.
Common XML Errors and Safe Handling
Frequent well-formedness errors include mismatched closing tags, more than one document element, unquoted attributes, bare ampersands, and raw < characters in text. Escape data correctly, for example with & for an ampersand, instead of trying to repair arbitrary markup through string replacement.
XML parsing also has a security history involving external entities and oversized expansions. This page formats text and checks it with the browser parser; it does not fetch external resources or upload the source. Still, do not assume that XML proven well-formed here is safe to feed into a different server-side parser whose DTD and entity settings may differ.
Treat confidential XML as sensitive even during local work. Redact credentials, personal information, private keys, and signed production messages before copying output into tickets or chats. For exact comparisons between original and formatted text, use the text diff checker, but keep in mind that a text diff does not determine semantic XML equivalence.
Frequently Asked Questions
Does beautifying XML change its data?
It can. This formatter trims text tokens and inserts structural line breaks, which is often acceptable for data-oriented XML but can alter mixed content or whitespace-sensitive documents. Keep the original and verify the result with the application that consumes it.
Does this tool validate XML against an XSD or DTD?
No. It checks well-formedness with the browser's XML parser after formatting or minifying. It does not load an XSD, validate element types, enforce application constraints, or perform DTD validation.
What does Minify remove?
It removes XML comments, drops whitespace-only text tokens, and collapses whitespace runs in other text tokens before joining the tokens. It preserves recognized tags, declarations, processing instructions, CDATA sections, and doctypes. This can change whitespace-sensitive content.
Why is formatted output shown when the XML is malformed?
Formatting uses a tokenizer rather than the validating parser, so it can produce an indented result before the separate well-formedness check reports a problem. The visible output is not evidence that the document is correct. Use the error status to fix the source and run it again.
Is XML formatting performed on a server?
No. The formatting, minification, byte counting, and well-formedness check run in your browser, and the XML is not uploaded for processing. Sensitive values can still be exposed if you copy or share the result, so sanitize production documents when possible.
References: W3C: Extensible Markup Language (XML) 1.0 · MDN: DOMParser.