XML Formatter, Validator & XPath Query Tool
Paste raw or minified XML to instantly beautify it with proper indentation, validate well-formedness, run XPath queries against the parsed document, and minify for compact output. Entirely browser-based — no server, no signup required. Need to work with related formats? See our tools for SQL formatting or testing regular expressions against XML content.
How to Use the XML Formatter Online
- Paste raw, minified, or malformed XML into the left input panel.
- Choose your preferred indent size: 2 spaces, 4 spaces, or tabs.
- Click Format XML, or enable Format on Paste for automatic formatting as you type.
- Check the validation badge — green confirms valid XML, red shows the exact parse error message from DOMParser.
- Enter an XPath expression in the query bar and click Evaluate to highlight matching nodes and see a match count.
- Click Minify for a compact single-line output, or Download .xml to save the formatted file.
Key Features
- True XML validation using the browser's native DOMParser — not regex, not heuristics
- Color syntax highlighting: tags, attributes, values, comments, and processing instructions
- Three indentation options: 2 spaces, 4 spaces, or tab character
- XPath query evaluation with match highlighting in the output panel
- XML minification — removes whitespace-only text nodes
- Element count, attribute count, and character count statistics
- Format on Paste for instant results without clicking a button
- Download as .xml file or copy formatted output to clipboard
XML Formatter Use Cases
Validating XML configuration files
Maven POM files, Spring XML configs, and Android layout files must be well-formed XML. Paste your config here to immediately see whether DOMParser accepts it as valid, and get the exact line and character position of any syntax error.
Beautifying minified API XML responses
SOAP web services and legacy REST APIs often return compact, single-line XML that is impossible to read. Paste the response and click Format to produce indented, readable output with color-coded syntax highlighting. For REST APIs that return JSON data instead, use the JSON Formatter.
Running XPath queries on XML data
Use XPath expressions like //book/title, //@lang, or //item[price < 10] to navigate and filter XML without writing code. Matching nodes are highlighted directly in the formatted output, showing exactly which elements are selected.
Minifying XML for production builds
Strip all formatting whitespace from XML configuration files or SOAP payloads before bundling. The Minify button produces a compact single-line string and the character count confirms the size reduction.
FAQ's
HTML has relaxed parsing rules designed for browser display — unclosed tags and unquoted attributes are allowed. XML has strict well-formedness rules for data storage and transport: all tags must be closed, attribute values must be quoted, and the document must have exactly one root element. XHTML is HTML reformulated as XML.
Common causes: unclosed tags, unquoted attribute values, special characters like <, >, or & outside CDATA sections, multiple root elements, or an invalid XML declaration. The red error badge shows the exact DOMParser error message to help you find the problem.
Common XPath expressions: //element (all matching elements), /root/child (absolute path), //@attribute (all matching attributes), //element[@attr='value'] (filtered by attribute), and //element[1] (first match). XPath 1.0 is supported.
The formatter runs in your browser using the DOM parser. Files up to a few megabytes work well on modern devices. For very large XML files (over 5 MB), consider a desktop tool like XMLSpy or the command-line xmllint utility.
No. All parsing and formatting uses the browser-native DOMParser and XMLSerializer APIs entirely client-side. Your XML never leaves your device and is never transmitted to any external server.
When Format on Paste is enabled, the formatter automatically formats and validates your XML as soon as you paste it into the input panel — no need to click the Format button manually. You can disable it if you want to paste incrementally.
Minify mode removes all whitespace-only text nodes from the parsed DOM tree and re-serializes the document as a compact single-line string. This is ideal for reducing payload size in SOAP requests, configuration files, or embedded XML data.