XML Formatter & Validator
Paste XML into the left panel to instantly format, beautify and validate it. Configurable indentation, minify mode, namespace and CDATA support — all client-side.
.xml fileXML's Sharp Edges: XXE and Entity Expansion
XML has a well-documented history of security issues that don't exist in simpler formats like JSON, and it's worth understanding them even when using a client-side formatter that isn't itself vulnerable. XML External Entity (XXE) injection abuses the <!DOCTYPE> and <!ENTITY> declarations that let an XML document reference external resources — a maliciously crafted document can define an entity that points at a local file path or an internal network address, and a vulnerable server-side parser configured to resolve external entities will fetch that resource and embed its contents into the parsed output, leaking local files or probing internal services the attacker couldn't otherwise reach. A related attack, sometimes called a "billion laughs" attack, defines a small number of entities that each reference several other entities, nesting exponentially so that a document only a few kilobytes in size expands to gigabytes in memory once fully resolved, exhausting server resources.
This tool uses the browser's built-in DOMParser, which — unlike many server-side XML libraries in their default configuration — does not fetch external entities over the network, making it safe to paste untrusted or unfamiliar XML here purely for formatting and validation. That safety property doesn't transfer automatically to whatever system actually consumes the XML in production: any server-side parser handling XML from an external source should have external entity resolution and DTD processing explicitly disabled, regardless of how this browser tool behaves.
Formatting Habits Worth Adopting
- Validate before you format, not after: confirm the document is well-formed first — an unclosed tag or unescaped ampersand produces a parse error that's far easier to fix while you still remember what you just edited than after several more changes have piled on top.
- Keep indentation consistent across a repository's XML files: mixed 2-space, 4-space, and tab indentation across Maven POMs or Spring configs in the same project makes diffs noisy and unreadable in code review — pick one indent width and apply it uniformly.
- Minify only at the point of transmission, never in source control: commit the readable, indented version to your repository and let a build step or a runtime library minify it if payload size actually matters — a minified XML file in version control is nearly impossible to review meaningfully in a diff.
- Preserve comments and processing instructions rather than stripping them during cleanup: a comment explaining an unusual configuration choice in a Jenkins or Spring XML file is often the only documentation of why that choice was made — losing it during a reformatting pass erases institutional knowledge for a purely cosmetic gain.
From SOAP Fault to Readable Structure
Legacy SOAP services frequently return error responses as a single unbroken line of XML, which is exactly the shape this tool is built to untangle. Consider a minified SOAP fault from a billing service: <soap:Envelope xmlns:soap="..."><soap:Body><soap:Fault><faultcode>soap:Server</faultcode><faultstring>Invoice not found</faultstring></soap:Fault></soap:Body></soap:Envelope> — technically complete and parseable, but functionally illegible at a glance. The formatter parses this with DOMParser, confirms it's well-formed, and re-serializes it with each element on its own indented line: soap:Envelope at the root, soap:Body nested one level in, soap:Fault nested inside that, with faultcode and faultstring appearing as clearly indented sibling leaves.
The actual error message — "Invoice not found" — which was buried in the middle of an unbroken string, becomes the first thing your eye lands on. If the input were instead malformed — say, a missing closing tag on soap:Fault — the parser would return a <parsererror> node instead of a usable document, which the tool surfaces directly as an error message rather than producing garbled or partial output.
Where Structured XML Review Pays Off
- Debugging a SOAP API integration: formatting a minified fault response to quickly locate the actual error code and message buried inside the envelope, rather than scanning an unbroken line of tags by eye.
- Reviewing a Maven POM before a dependency change: a large POM with many dependencies, profiles, and plugin declarations is far easier to scan for a version conflict once properly indented than in its original, often inconsistently formatted state.
- Auditing CI/CD pipeline configuration: Jenkins pipeline definitions, TeamCity build configs, and MSBuild project files stored as XML benefit from clean formatting when reviewing a change to build logic in a pull request.
- Sanity-checking hand-edited configuration before deployment: confirming a manually edited Spring application-context file or Android manifest is still well-formed after a quick edit, before it reaches a build pipeline that would otherwise fail on a typo far from where it was introduced.
Frequently Asked Questions
How does the XML Formatter work?
Paste or type XML into the input panel and the formatter immediately processes it using the browser's built-in DOMParser API, which parses the XML into a structured DOM tree using the same engine that renders HTML in your browser. If the XML is well-formed, the tool recursively walks the DOM tree and serialises it back with clean, configurable indentation applied at each level of nesting — making the document hierarchy immediately visible. If the XML contains errors, the parser returns a <parsererror> element identifying the problem, which the tool displays in the status bar so you can quickly locate and fix the issue. All processing happens locally in your browser — no data is sent to any server.
Does it support namespaces and CDATA?
Yes. The formatter fully supports XML namespaces, preserving namespace prefixes and namespace declarations (xmlns:prefix="uri") exactly as written in the source document. This is important when working with SOAP envelopes, which use multiple namespaces like xmlns:soap and xmlns:xsd, or with Spring XML application contexts that use Spring's xmlns:beans namespace. CDATA sections (<![CDATA[...]]>) are also preserved intact — their content is not escaped or modified. Processing instructions (<?xml version="1.0"?>) and XML comments (<!-- ... -->) are retained in their original positions in the document tree.
Is my data private?
Completely. The XML Formatter runs entirely within your web browser using client-side JavaScript — no XML content is ever transmitted to a remote server, logged, or stored. This makes it safe to use with sensitive configuration files, internal SOAP API payloads, database export files, and proprietary data structures that your organisation's security policy prohibits sending to third-party services. You can verify this by running the tool with your browser's network inspector open — you will see zero outbound requests triggered by the formatter's parse and format operations. The only network requests on the page are for loading the static page assets themselves.