What XML formatting does
An XML formatter parses a document and writes the same element hierarchy with consistent indentation and line breaks. The result makes nested elements, attributes, comments, and text easier to inspect. Parsing also identifies malformed structure such as a missing closing tag, an unquoted attribute, an invalid entity, or multiple top-level elements where one document root is required.
Formatting changes presentation, not the business meaning you intended. XML consumers can be sensitive to whitespace inside text nodes, mixed content, CDATA sections, declarations, namespaces, and digital signatures. Save the original and compare behavior in the receiving system before replacing a production document.
How to format an XML document
- Paste the complete XML, including its declaration when one is present.
- Run the formatter and address the first reported syntax error if parsing fails.
- Choose an indentation width that matches the repository or integration convention.
- Inspect whitespace-sensitive text, namespaces, comments, and CDATA in the result.
- Copy or download the formatted XML and validate it against a schema when required.
The first parser error may cause several later messages, so fix errors in order. A raw ampersand in text must be escaped, opening and closing tag names must match exactly, and attribute values need quotes. XML is case-sensitive: <Item> and <item> are different names.
Formatting is not full validation
Well-formed XML
A successful parse establishes that the document follows core XML structural rules. It can still contain the wrong elements, missing identifiers, an invalid date, or a namespace that the receiving application does not recognize. A formatter cannot infer those domain rules from appearance.
Schema and application validation
An XSD, DTD, RELAX NG schema, or application-specific validator can enforce allowed elements, ordering, types, and cardinality. Use the exact version required by the integration. External entity and DTD processing can introduce security risks, so browser formatters commonly avoid fetching external resources and should not be treated as authoritative DTD validators.
Practical use cases
Format an API response while debugging an integration, review a compact configuration file before a code change, or make a machine-generated feed understandable during support work. Developers can compare nested namespace scopes, while data teams can locate the record around a malformed closing tag without scrolling through one enormous line.
For diffs, format both documents with identical settings before comparing them. This reduces noise from indentation, although attribute order, namespace prefixes, and semantically insignificant whitespace can still differ. For cryptographic or canonical comparisons, use an XML canonicalization implementation designed for that purpose rather than a visual formatter.
Encoding declarations require care as well. Text pasted into a browser is already represented as browser text, so a declaration claiming a legacy byte encoding does not recreate the original byte stream. When debugging corrupted characters, inspect the source file's actual bytes and transport headers. Formatting alone cannot repair text that was decoded with the wrong character set before it reached the tool. Preserve the source until its consumer accepts the replacement.
Whitespace, signatures, and privacy
Mixed-content XML deserves special attention because spaces between text and child elements may be meaningful. Elements using xml:space="preserve" explicitly request whitespace preservation. Signed XML can also break if bytes are rewritten outside the signature's canonicalization rules. Inspect rather than overwrite when you do not control the consuming format.
Parsing and formatting happen in your browser, so the document does not need to leave your device. XML often contains credentials, customer records, internal endpoints, or signed assertions; remove such values before sharing the result. Browser extensions, clipboard history, and shared screens can still expose local content, so use an approved offline environment for highly sensitive documents.