What This Tool Does
Use this tool to clean already-valid XML in your browser. Paste XML into Paste XML content below, or add a file, choose the cleanup rules. The result updates automatically. The result remains XML and includes a change summary plus a Before / after preview.
Choose the Cleanup Rules
Enable the rules that match the cleanup you need:
- Normalize text whitespace (collapse & trim, drop whitespace-only nodes) collapses runs of spaces, tabs, and newlines in non-whitespace text, trims the result, and removes whitespace-only text nodes.
- Remove comment nodes ( <!-- ... --> ) removes XML comment nodes.
- Remove empty elements (no attributes, text, or children) removes elements with no attributes, element children, non-whitespace text, CDATA, or comments. Processing instructions do not count as content for this test.
Empty-element removal runs in repeated passes, so removing a child can make its parent removable too. It stops after 20 passes and does not remove the document element. Namespace and attribute nodes are not targeted, but serialization and element removal can change the output representation or structure.
Set Output Indentation
Use Output indentation to choose 2 spaces, 4 spaces, Tab, or Compact (no whitespace). The tool always serializes the parsed document and passes it through its formatter. As a result, whitespace between tags can change even when Normalize text whitespace (collapse & trim, drop whitespace-only nodes) is disabled. This is formatting and serialization, not raw-input preservation.
How to Clean XML
- Paste XML into Paste XML content below, or drop/upload a file. The file picker accepts XML and TXT extensions.
- Choose the cleanup rules and an option under Output indentation.
- Review the automatically updated result.
- Review Changes made and the Before / after preview.
- Click Copy Cleaned XML or Export XML.
Review the Preview and Limitations
The Before pane is not a raw copy of your input. It shows the input after reparsing, serialization, and formatting. The After pane shows the cleaned, serialized, and formatted XML. Review both panes before exporting, especially when removing empty elements: nested parents can be removed, while the document element remains.
- The tool assumes well-formed XML. Parse failures are reported, but broken XML syntax is not diagnosed or repaired.
- The cleaning traversal skips CDATA sections and processing instructions. Later serialization and formatting can still change matching whitespace in their serialized output, so they are not guaranteed byte-for-byte unchanged.
- Uploaded files are read as UTF-8. Files longer than 200,000 characters are truncated only in the textarea preview; the full loaded content is processed.
- Dropped files are read without an extension validation check.
Browser-Side Processing
Parsing, cleaning, preview generation, copying, and export are implemented in the browser. The local implementation does not establish a usage-limit policy.
Frequently Asked Questions
How is this different from the XML Validator?
The XML Validator checks whether your XML is well-formed and helps you locate syntax errors. This tool assumes your XML is already valid and cleans its content - normalizing whitespace, removing comments, removing empty elements. It does not diagnose or repair broken syntax.
How is this different from the XML to JSON Converter?
The XML to JSON Converter changes the format entirely, turning XML into JSON. This tool keeps the output as XML while changing selected whitespace, comments, and empty elements.
Will this remove or change my namespaces and attributes?
Namespace and attribute nodes are not targeted by the cleanup rules. However, the document is reparsed, serialized, and formatted, so the exact serialized representation is not guaranteed. Enabled empty-element removal can also change structure.
What counts as an "empty element"?
An element with no attributes, no child elements, no comments, and no non-whitespace text or CDATA content. Processing instructions do not count as content. The document element is not removed, and cleanup runs for at most 20 passes, allowing newly empty parents to be removed.
What does whitespace normalization do exactly?
Inside text nodes with real content, runs of spaces, tabs, and newlines are collapsed to one space and trimmed. When enabled, whitespace-only text nodes are removed. CDATA sections and processing instructions are skipped during traversal, but later formatting can affect matching serialized whitespace.