XML Formatter
XML Formatter does not use an XML parser or validate well-formedness. It removes whitespace between adjacent tags, inserts line breaks between tag boundaries, and changes indentation based on opening/closing-tag regexes. Mixed content, comments, CDATA, processing instructions, declarations, namespaces, self-closing variants, embedded greater-than characters, and malformed markup can be reformatted incorrectly or have meaningful whitespace changed.
Runs locally — files stay on your deviceDoes successful formatting prove valid XML?
No. No XML parser is invoked.
XML is not safely formatted by tag regex alone
XML grammar includes mixed character content, CDATA, comments, entity references, namespaces, and whitespace that can be semantically meaningful.
How it works
Regex replacements create one tag-like node per line and a simple counter adds two spaces for inferred nesting.
Key concepts
Heuristic depth
The counter is not an XML tree.
Whitespace changes
Text between tags can be collapsed.
When to use it
- Indent a small, simple, known-safe element tree.
- Make basic machine-generated XML easier to scan.
- Spot obvious tag nesting visually.
When not to use it
- Do not use it on mixed-content documents.
- Do not rely on it for validation.
- Do not process signed/canonical XML where whitespace matters.
Worked examples
Simple
- Input
<a><b>1</b></a>- Expected output
Indented tags
The heuristic handles this shape.
Mixed text
- Input
<p>Hello <b>world</b> !</p>- Expected output
Potential whitespace changes
Text flow is significant.
Malformed
- Input
<a><b></a>- Expected output
Formatted-looking text
No validity error is guaranteed.
Common mistakes
Calling output valid
Formatting is not parsing. Correction: Validate with a conforming XML parser/schema.
Formatting signed XML
Byte changes can invalidate signatures. Correction: Use signature-aware canonicalization.
Ignoring mixed content
Spaces can change. Correction: Use an XML-aware formatter.
Best practices
- Restrict use to simple known input.
- Validate before and after with XML tooling.
- Keep originals when whitespace or signatures matter.
Related operations and differences
JSON Beautifier
Choose JSON Beautifier when you need to format JSON with readable indentation.; use XML Formatter specifically for xml format.
YAML Formatter
Choose YAML Formatter when you need to format YAML with consistent indentation.; use XML Formatter specifically for xml format.
CSV Formatter
Choose CSV Formatter when you need to normalize CSV quoting and row structure.; use XML Formatter specifically for xml format.
JSON to XML
Choose JSON to XML when you need to convert JSON objects into formatted XML.; use XML Formatter specifically for xml format.
XML Minifier
Choose XML Minifier when you need to remove whitespace between XML tags.; use XML Formatter specifically for xml format.
XML to JSON
Choose XML to JSON when you need to convert XML elements and attributes into JSON.; use XML Formatter specifically for xml format.
Limitations and privacy
- Regex heuristic only.
- No well-formedness, namespace, DTD/schema, entity, mixed-content, CDATA, signature, canonicalization, or preservation guarantee.
The pasted data is parsed and transformed locally in this browser.
Frequently asked questions
Does it validate tags?
No.
Can whitespace change?
Yes.
Is it safe for signed XML?
No.
Are namespaces resolved?
No.