What this tool does
The XML Formatter first uses the browser DOMParser to build the document tree and then outputs it by node type, instead of using regular expressions to insert newlines between angle brackets. For mixed text content, the original semantics will be preserved first.
- Attributes and namespaces are validated by the XML parser.
- Comments, CDATA, processing instructions, and text nodes are retained as per their respective types.
- Elements with significant mixed content will not be forced into whitespace that could alter the text.
How to use it
- Paste the complete XML.
- Choose 2 or 4 spaces indentation.
- Click "Format XML".
- Copy the results or download formatted.xml.
Common uses
- Collate configuration files and SOAP/XML responses.
- Check that labels are nested and closed correctly.
- Read documents that contain attributes, CDATA, or duplicate nodes.
XML Formatter Features
Validate and pretty-print XML with DOMParser, preserving attributes, comments, and CDATA. It is suitable for daily development, debugging, data sorting and code optimization scenarios. The processing results can be directly viewed, copied or downloaded.
FAQ
How does the tool determine that the XML is invalid?
DOMParser parses according to XML rules; when a parsererror is detected, the page displays the reason provided by the parser.
Will CDATA become normal text?
No. The formatter recognizes CDATA nodes and preserves CDATA boundaries.
Will formatting change mixed content?
For nodes that contain both significant text and child elements, the tool avoids adding additional indentation to reduce the risk of changing the semantics of whitespace.