Developer Tools
Prettify XML with two spaces, four spaces or tabs, minify inter-tag whitespace, validate well-formed documents, and preserve comments, namespaces and CDATA without fetching DTDs or external resources.
Simple workflow
How to use XML Formatter & Validator
- 1Paste XML of up to 2 MiB.
- 2Choose indentation, then format, minify or validate.
- 3Copy or download the processed XML locally.
Good to know
Frequently asked questions
Can XML external entities load?
No. DOCTYPE and entity declarations are rejected before parsing, and the tool does not resolve DTDs or remote resources.
What content is preserved?
Well-formed namespaces, comments and CDATA sections are preserved by the bounded formatter. Formatting is intentionally conservative.
Is XML sent to a server?
No. Parsing and formatting remain on this device.
Practical guide
Format well-formed XML without resolving external resources
The formatter parses up to 2 MiB of XML in the browser, reports malformed syntax, and then either applies conservative indentation or removes whitespace-only text nodes between elements. It preserves element and attribute names, namespace declarations, comments and CDATA nodes in the processed document.
This is a well-formedness check, not schema validation. A document can have balanced tags and valid XML syntax while still violating the element order, data types or required attributes defined by an XSD, RELAX NG schema or application contract.
Worked example
Format namespaced XML with mixed content
- Start with
- Paste <doc xmlns="urn:example"><!--note--><p>Hello <b>world</b>.</p><raw><![CDATA[a < b]]></raw></doc>.
- Choose
- Choose 2 spaces and select Format XML.
- You get
- The namespace declaration, comment and CDATA section remain. The p element stays serialized as mixed content instead of receiving indentation that would insert visible text whitespace.
Tips for a useful result
- Use Validate to check XML syntax without claiming that the document satisfies an external schema.
- Use Format for human review. Avoid Minify when whitespace-only nodes may carry meaning unless the document marks preserved regions with xml:space="preserve".
- Processing stays in this tab. The formatter does not fetch schemas, DTDs, external entities, images or other remote resources.
Well formed is different from schema valid
Well-formed XML follows XML syntax rules: it has one document element, properly nested and closed tags, quoted attribute values, and valid character and entity syntax. Schema validation is a separate operation that checks the vocabulary and constraints chosen by a particular system.
This tool does not accept an XSD or any other schema, so Valid XML means only that the browser parser accepted the document as well formed. It cannot confirm that an invoice, feed, configuration file or API message meets the receiving application's rules.
Namespaces, mixed content and CDATA
An XML namespace associates a prefix, or a default namespace, with a URI so vocabularies can share a document without treating identical local names as the same expanded name. Formatting preserves those declarations and qualified names; it does not look up the namespace URI or judge whether the vocabulary is correct.
Mixed content places text and child elements in the same parent, as in <p>Hello <b>world</b>.</p>. Adding line breaks inside that element could change its text, so the formatter leaves an element containing non-whitespace text or CDATA serialized without structural line wrapping. CDATA preserves text that would otherwise need markup escaping; it does not make executable content safe in a later consumer.
Minify removes whitespace-only text nodes unless xml:space="preserve" applies. That can be useful between structural elements, but whitespace-sensitive document formats may assign meaning to those nodes. Keep an original copy and review the receiving format's rules before replacing it.
Why DOCTYPE and entity declarations are rejected
A DOCTYPE can define internal or external entities and can point a parser at another resource. Resolving untrusted external entities can expose local files, make unintended network requests or consume excessive resources. This tool rejects both DOCTYPE and ENTITY declarations before DOM parsing instead of trying to distinguish safe from unsafe declarations.
The restriction means XML that depends on a DTD, declared entity or external subset cannot be formatted here. The tool also performs no XInclude, schema loading or stylesheet transformation. Use a deliberately configured offline XML environment when those features are required.
Authoritative external sources
- W3C: Extensible Markup Language (XML) 1.0 (external)
The W3C XML syntax and well-formedness specification.
- W3C: Namespaces in XML 1.0 (external)
The W3C specification for namespace names and qualified element names.
- OWASP: XML External Entity Prevention Cheat Sheet (external)
Security guidance for disabling DTD processing and external entity resolution in untrusted XML.
Understand the details
Related reference guide
Keep going