XML Formatter
Format or minify well-formed XML while protecting mixed content, CDATA, and inherited xml:space=preserve subtrees.
No output was created
XML needs attention
- Category
- Near
Nearby source (displayed as text)
Reparsed before export
XML result
Input or settings changed. Run the formatter again before copying or downloading this result.
Clipboard access was unavailable. The exact result is selected below for manual copy. Your platform may normalize line endings; Download keeps the validated bytes.
- Operation
- Input → output
- Raw tokens
- Protected elements
- Inserted LF breaks
- Encoding notes
Compare source and result
Conservative XML formatting
The formatter first checks the complete XML 1.0 document with the bundled saxes 6.0.0 namespace-aware parser and its bundled xmlchars 2.2.0 dependency. A separate quote-aware scanner records the original source spans. Output is assembled from those spans, then parsed again before Copy or Download becomes available. A malformed document never receives a partial rewrite.
Default Format inserts indentation only inside an unprotected parent that has no direct text node and no CDATA child. A parent containing even whitespace-only text stays untouched unless you explicitly select Reflow. Nonblank mixed text always stays in place. An inherited xml:space="preserve" protects the whole subtree.
Format, Reflow, and Minify do different work
| Choice | Whitespace behavior | Use it when |
|---|---|---|
| Format | Adds LF indentation only where no direct text or CDATA exists | You want a conservative structural view |
| Reflow existing indentation | Replaces whitespace-only direct text in eligible structural parents | You have reviewed the whitespace caution |
| Minify | Removes whitespace-only direct text in eligible structural parents | The receiving format contract treats that layout as insignificant |
Existing tag spelling, attribute order and quotes, entity-reference spelling, comments, CDATA, processing instructions, and the XML declaration remain raw source spans. Existing line endings in unchanged spans remain unchanged; any inserted layout break is LF and the result receipt flags mixed CRLF/LF output.
Errors and resource limits
The tool rejects empty input, invalid UTF-8 local files, XML 1.1, a declared non-UTF-8 encoding, malformed nesting, duplicate attributes, undefined entities, unbound prefixes, invalid XML characters, every DTD, depth over 200, more than 50,000 raw tokens, input over 1 MiB, or output over 2 MiB. Error context is displayed as text near a line and column; it is not inserted as HTML and is never added to telemetry.
The worker is canceled when input changes or Reset is pressed, and a bounded timer prevents an old run from replacing newer input. These limits keep the browser task responsive; they are not XML language limits.
Browser-only privacy and V1 scope
Pasted XML and local-file bytes enter a bundled browser Worker. The Worker does not fetch XML, a DTD, schema, or URL. The page stores no document in local storage, session storage, IndexedDB, cookies, query parameters, or fragments. Aggregate measurement contains only operation, size bucket, coarse result or error category, and copy/download outcome.
This V1 tool does not validate XML Schema, expand DTD entities, resolve external resources, canonicalize XML, rewrite namespaces, convert XML to another format, provide a DOM tree, or guarantee semantic equivalence for every downstream application.
Frequently asked questions
Why might formatting add whitespace?
Format can insert LF line breaks and indentation only in structural parents with no existing direct text or CDATA. Those new characters are whitespace-only text nodes, and an application can treat them as data. The tool therefore does not promise semantic equivalence for arbitrary XML.
What does xml:space do?
An inherited xml:space="preserve" protects that element subtree from layout changes. For safety, a nested xml:space="default" remains protected when it appears below a preserved ancestor.
Why are DTDs rejected?
DTDs can define entities and whitespace rules or refer to external resources. This V1 tool neither expands nor fetches them, so it rejects every DOCTYPE before creating output.
Is my XML uploaded?
No. Pasted text and local-file bytes are parsed, formatted, copied, and exported in your browser. They are not placed in a URL, browser storage, analytics, or a ToolNeko task request.
What is well-formedness versus validation?
Well-formed XML follows XML syntax and namespace rules. Validation additionally checks a DTD, XML Schema, RELAX NG, or another application contract. This tool checks well-formedness only.