XML Beautifier: Retain Text, Comments and Spacing

Format a shipment XML without collapsing its label or storage note

XML whitespace can be data. This formatter validates a plain document and adds or removes formatting whitespace only in element-only content. Mixed text, CDATA and xml:space content need different treatment from the spaces between structural tags.

A spacing-sensitive shipment

Select Load spacing-sensitive shipment. The label contains two spaces on each side of an ampersand, the note asks XML readers to preserve its spacing, two item elements carry IDs, and a comment records the local count. The formatted result keeps these observations:

label text: "Paper  &  board"
item IDs: ["0042", "0043"]
note text: "  shelf B\n  keep spacing  "
comment: " counted locally "

Download XML output saves prepared.xml. Compare the decoded label and note text as well as both IDs after parsing the download. The added indentation helps inspect the items, but it must not turn double spaces into single spaces or remove the comment. A source XML declaration is normalized to a UTF8 declaration for the UTF8 export.

Pretty and compact output

Indentation offers 2, 4, 8 spaces or tabs. Compact element-only whitespace removes spacing between structural children where there is no meaningful text. It retains comments; it is not a comment remover or a guarantee of the smallest possible byte count. A leaf text value keeps its existing whitespace.

A paragraph with text before and after a child element keeps that node order and text. CDATA boundaries remain serialized. xml:space preserve is inherited by descendants; xml:space default allows formatting to resume. Processing instructions and namespace-qualified names are retained. XML parsing and serialization can normalize line endings, attribute whitespace, entity spelling, empty-element spelling or namespace declarations; this is a parsed-document formatter, not a byte-preserving editor.

Documents that should stay original

Keep the original for signatures, forensic comparisons or downstream systems that treat formatting whitespace as significant without marking it. The formatter does not validate a schema, evaluate a processing instruction, fetch an external resource or certify shipment facts. If you need JSON data instead, XML to JSON uses a separate mapping with different losses.

Malformed closing tags, multiple roots, duplicate attributes, unbound prefixes and unknown entities fail visibly. DTD and entity declarations are not supported; literal declaration text inside CDATA or comments remains ordinary content. Built-in entities and valid character references are handled by the browser XML parser.

Bounds, files and recovery

Input is capped at 256 KiB of UTF8, output at 1 MiB, XML nodes at 20,000 and nesting at 32 levels. UTF8 files may include a BOM, invalid bytes fail, and reads stop after 20 seconds. Editing source or formatting settings removes an older result immediately. Correct the error and prepare again before downloading; in manual mode loading the example only fills the editor.

XML stays text in the page, and preparation uses no API. A downloaded file can still contain sensitive values. Ordinary site requests follow our Privacy Policy. Formatting makes this original demonstration easier to inspect; the export still needs destination-specific review.

Guide published by . View our publishing information and contact details.