XML Formatter
Format, minify and validate XML online, powered by the native browser parser with clear error messages.
How to use
- Paste your XML into the box, or click "Sample" to load demo data.
- Click "Format" for a two-space indented version, or "Minify" to strip whitespace between tags.
- If the XML has syntax errors such as unclosed tags, a message will tell you what went wrong.
- Use the "Copy" button at the top right of the result to grab the output.
FAQ
Does it support namespaces?
Are comments and processing instructions kept?
Is my data uploaded?
How to use
- Paste or load a sample
Paste your XML into the input box. Press Sample to load demo data and preview the indentation style before working on real files.
- Format for readability
Press Format to get two-space indentation with each tag on its own line. Comments, CDATA sections and namespace declarations are preserved as-is.
- Minify for transfer
Press Minify to collapse the document into a single line by stripping whitespace between tags. Payloads shrink without touching any text content.
- Fix errors from the message
If a tag is unclosed or the syntax is broken, the red notice explains what went wrong. Correct the input and run Format again.
- Copy the result
Use the Copy button at the top right of the output box. Paste the tidy XML back into configs, API docs or test fixtures.
About this tool
XML appears in API responses, RSS feeds, build configs and sitemaps. Machine-generated files often arrive as one unreadable line with messy or missing indentation. This formatter parses your data with the browser's native XML engine and re-serializes it. Format adds two-space indentation per nesting level. Minify removes only the whitespace between tags. Comments and processing instructions survive both operations.
Use it to check whether an API payload has unclosed tags. It also sets a consistent indentation style before code review, or shrinks a bloated config file before transfer. Namespaced documents using xmlns format cleanly. Parsing happens before any output, so a malformed document produces a concrete error message. That gives the workflow a lightweight validation step.
How it works
The W3C finalized XML 1.0 in 1998, and the specification splits correctness into two levels. Well-formed documents satisfy structural rules: one root element, closed tags, quoted attributes. Valid documents additionally pass DTD or XSD validation, and well-formedness is the prerequisite. The browser's built-in DOM parser checks only the first level. Inside text nodes, < and & must be written as < and &. Long verbatim chunks go into CDATA sections to avoid per-character escaping. Neither formatting nor minifying touches those constructs.
Formatting is parse-then-reserialize. The parser reads the document into a DOM tree, and the serializer prints it back level by level. Details like attribute quote style and empty-tag notation get normalized, so the information is identical even though the bytes are not. Whether whitespace carries meaning is governed by the xml:space attribute. By default the indentation between tags is only layout noise, while text that must keep every space declares xml:space="preserve" on its element. One-line RSS feeds, sitemaps and pom files can flip between human-readable and transfer-friendly forms through these two steps.
When to use it
- Health-checking RSS and sitemaps
Feeds and sitemaps are generated in bulk, and one unclosed tag invalidates the whole source. A single Format pass with the error notice beats waiting for readers to report missing articles.
- Tidying exported test fixtures
XML exported from packet captures and test platforms arrives with mixed indentation. Normalize it once before committing, so later fixture diffs show data changes instead of layout churn.
- Comparing two supposedly equal configs
When two configurations that should match refuse to agree, format both to the same indentation first. Read them side by side; missing nodes, extra levels and attribute differences become obvious.
Tips & tricks
- Namespace declarations and prefixed tags are kept exactly as written, so documents using xmlns can be formatted directly.
- Load the Sample first to see the expected output style, then compare it against your own data to spot structural issues.
- Minify strips whitespace between tags only. Spaces inside text node content are never touched, so sentence text stays intact.
Things to watch
- The report stops at the first fault
A DOM parser halts on the first error it meets. Fixing one unclosed tag may expose the next one behind it. Work through the notices one by one instead of assuming the document holds a single defect.
- Exactly one root element is allowed
Everything in XML must hang under a single root, so pasting several sibling nodes is rejected as malformed. Wrap them in one container element and the structure becomes valid immediately.
- Minifying cannot shorten long text
Minification only touches whitespace between tags and leaves long text inside elements untouched. Expecting dramatic size savings leads to disappointment, so prune nodes and attributes instead.