XML Formatter & Validator
Format, validate, minify, convert to JSON, and query with XPath — all in your browser, no uploads, no account.
XPath Query
Run XPath 1.0 expressions against your XML. Try //book, /library/catalog/book[@available='true'], or //@id.
How to Use the XML Formatter
Five ways to work with XML on this tool — built for real developer workflows.
@attributes, text content under #text..xml file from disk, or download the formatted output as a formatted.xml file. All processing stays local.All Features at a Glance
Everything built into this free tool — private, fast, no account required.
XML Syntax Cheatsheet
Quick reference for well-formed XML — the rules developers most often overlook.
Frequently Asked Questions
Common questions about XML formatting, validation, and this tool.
Well-formed XML follows these rules: (1) there is exactly one root element, (2) all elements are properly nested and not overlapping, (3) all tags are closed (or self-closed with />), (4) tag names are case-sensitive and must match, (5) all attribute values are quoted, (6) the characters &, <, and > inside text are escaped as entities. A well-formed document can be parsed; a valid document also satisfies an associated DTD or schema.
Well-formed XML follows the basic syntactic rules of XML (proper tag nesting, quoting, character escaping). Valid XML is well-formed AND conforms to a DTD (Document Type Definition) or XML Schema (XSD) that defines which elements and attributes are allowed and in what order. This tool validates well-formedness. Full schema validation requires loading your DTD/XSD, which is beyond a browser-only tool.
This tool supports XPath 1.0 via the browser's native document.evaluate() API. Supported patterns include: //tagname (any descendant), /root/child (specific path), //@attrname (any attribute), //tag[@attr='value'] (predicate filtering), count(//tag) (function calls), and text() node selection. XPath 2.0 and 3.0 features are not supported in the browser.
The converter walks the DOM tree and maps each element to a JSON key. Attributes are collected under an @attributes object. Plain text content becomes the value directly (or under #text if attributes are also present). Repeated sibling elements with the same tag name are collected into a JSON array. Comments and processing instructions are ignored in the output.
No. All formatting, validation, and conversion happens entirely in your browser using JavaScript and the browser's native DOMParser. Your XML data never leaves your device and is never stored or transmitted. This makes the tool safe for confidential API responses, configuration files, and private data structures.
XML namespaces allow elements from different vocabularies to coexist in one document without naming conflicts. A namespace is declared with xmlns:prefix="uri" and then used as prefix:tagname. Errors occur when a prefix is used without being declared, or when the namespace URI is malformed. The DOMParser in this tool validates namespace consistency according to the XML Namespaces 1.0 specification.
A CDATA section (<![CDATA[…]]>) tells the XML parser to treat its content as literal character data, not markup. Use it when your text content contains many <, >, or & characters — for example, embedded HTML snippets, code samples, or SQL queries. Without CDATA, each of these characters must be escaped as <, >, or &.
Mixed content occurs when an element contains both text nodes and child elements — for example <p>Hello <b>world</b></p>. This is perfectly valid XML and is normal in document-oriented XML (like XHTML). It is flagged as a warning by this tool because it can complicate data-centric XML processing — parsers and converters may handle whitespace in mixed-content models unexpectedly. If you are building document XML (not data XML), you can safely ignore this warning.
There is no official standard for XML indentation. Two spaces is the most common convention and produces compact output. Four spaces improves readability for deeply nested documents. Tabs allow each developer to control visual width via their editor settings. For files committed to version control, match your project's existing convention to avoid noisy whitespace diffs. Note that whitespace is technically significant in mixed-content XML, so formatters may not be appropriate for XHTML or DocBook source files.