More precise than “add whitespace”
What this raw-token XML pretty printer changes
An XML formatter makes element nesting easier to scan by placing structural nodes on lines and indenting descendants. It can clarify a compact configuration file, SOAP envelope, Maven document, SVG source, syndication feed, or test fixture. Formatting does not explain whether the element names are correct for that vocabulary.
This implementation preserves each raw tag and retained content token. Attribute order and quote style, self-closing spelling, supported entity-reference spellings, XML declarations, comments, CDATA sections, processing instructions, namespace prefixes, mixed-content subtrees, and inherited xml:space="preserve" regions remain verbatim. The formatter only replaces eligible whitespace between or around markup; this includes document-edge whitespace and inter-tag whitespace in regions that look element-only.
That narrow change still deserves a diff. Inter-tag whitespace becomes a text node in the XML data model, and a consumer can observe it even in a vocabulary that normally treats it as indentation. Byte comparisons, digests, canonicalization inputs, snapshots, and signatures can also change when structural whitespace changes.
Cryptographic XML signatures and canonicalization are especially sensitive. Pretty printing is not XML Canonicalization and does not preserve or verify a signature. If a signed document must remain verifiable, follow the signature profile and canonicalization algorithm used by the sender instead of reformatting the signed bytes.
- Indent
- Two spaces, four spaces, or a tab per structural level.
- Newline
- LF or CRLF for separators the formatter inserts; preserved raw regions keep their source text.
- Syntax
- XML 1.0 structure is checked, except that any DOCTYPE and internal-subset grammar remain opaque.
- Meaning
- Vocabulary, schema, signature, and business rules remain unchecked.
Whitespace may be data
Mixed content and xml:space need special care
Not every line break is safely decorative. Text-bearing XML can assign meaning to spaces between child elements.
Element-only configuration
A document whose parent elements contain only other elements is usually the clearest candidate for indentation. Even when every markup token stays exact, signatures and downstream byte comparisons can make newly inserted whitespace relevant.
Mixed text and elements
In <p>Read <em>this</em> now</p>, text occurs before and after a child element. Inserting visual line breaks can change the character data observed by an application.
xml:space="preserve"
The reserved xml:space attribute communicates whitespace-handling intent. A careful formatter should avoid inventing indentation within a preserved subtree, and a reviewer should confirm the consuming application behaves as expected.
CDATA and entity references
CDATA provides a source spelling for character data, while entity references provide another. This formatter keeps those raw spellings verbatim. Custom entity declarations and undefined named references are rejected because their replacement text is not expanded.
Document text remains local
Private XML formatting in the browser
XML often contains account identifiers, internal endpoints, build coordinates, message payloads, or operational metadata. When you press the format button, LiveParse creates a disposable Web Worker in this tab. The document is not posted to a formatter API, placed in the URL, or written to browser storage by the tool.
Input is limited to 200,000 UTF-16 code units and the page warns above 100,000; an astral Unicode symbol uses two units. The formatting operation is stopped after two seconds after the worker is ready, while worker loading has a separate twelve-second limit. Changing the source or an option terminates the current worker, preventing an older result from replacing newer input.
The XML parser never fetches external resources. A DOCTYPE is preserved as opaque source and is not validated; custom entity declarations and undefined named references are rejected. This boundary does not control browser extensions, clipboard managers, downloaded files, device backups, screen sharing, or other local software. Redact secrets and follow your organization's data-handling policy.
Before committing formatted output
XML formatting review checklist
ReviewWhy it mattersEvidence to collect
Text and mixed contentInserted whitespace can become character data.Compare parsed text nodes and application rendering.
Namespaces and QNamesPrefixes and namespace URIs identify vocabulary names.Check namespace-aware parsing in the target system.
Raw tokensQuotes, attributes, supported entity references, CDATA, declarations, and empty tags are preserved verbatim.Confirm the diff contains only intended whitespace between or around markup.
Validity and signaturesReadable XML can still violate a schema or invalidate a signature.Run the authoritative validator, canonicalizer, signature verifier, and tests.