Layerbit
Runs entirely in your browser

XML Formatter, Validator & XPath Tester

Pretty-print or minify XML, see well-formedness errors with their line, validate against XSD, RelaxNG, DTD or Schematron, transform with XSLT 1.0 or XQuery 3.1, run XPath with namespace support, compare two documents, and convert XML to JSON and back. Files of 8 MB and more are formatted in a background worker. Nothing is uploaded.

XML
Output
XPath
Load a document to enable queries. Prefixes declared on the root element are available; the default namespace is bound to ns.
Validate, transform, compare
XSD and RelaxNG run in libxml2, compiled to WebAssembly and loaded on first use.

What the formatter does, and does not do

Formatting XML is not just inserting newlines. Whitespace inside an element is data unless the schema says otherwise, so a naive pretty-printer that indents everything changes the meaning of <p>Hello <b>world</b></p>. This tool parses the document with the browser's DOMParser, then re-serialises the tree with a rule: an element whose children are all elements is broken across lines and indented; an element that contains text stays on one line with its text untouched. Comments, CDATA sections and processing instructions are preserved unless you strip them. Attribute order is preserved as written.

Reading a SOAP or SAML response

Enterprise APIs still return dense single-line XML. Paste the body here to see the structure, then use XPath to pull the one value you need — //soap:Fault/faultstring or //saml:Attribute[@Name='email']/saml:AttributeValue — without writing a parser for a one-off check.

Finding the well-formedness error

"XML parsing error" from a library rarely says where. The browser's parser reports the line and column of the first problem, and the tool shows it with the offending line. The usual culprits are an unescaped & in text, a mismatched closing tag, an attribute without quotes, or a BOM or stray character before the <?xml declaration.

XML to JSON for a quick look

The JSON mode gives a compact object view: attributes as keys prefixed with @, text as #text when an element has both, repeated child elements collapsed into arrays. It is meant for reading and for quick scripts, not as a lossless conversion — namespaces, comments and element order across siblings of different names are not representable in a plain object.

Config files and feeds

Maven pom.xml, web.config, Android manifests, RSS and Atom feeds, SVG, plist — all XML, all readable here. For SVG, formatting is safe; for feeds, an XPath like //item[1]/pubDate answers "when did this last update" faster than opening a reader.

XPath in five minutes

ExpressionSelects
/orderThe root element, only if it is named order
//itemEvery item element anywhere in the document
//item[@qty > 1]Items whose qty attribute is greater than 1 (numeric comparison)
//item[2]The second item child of each parent — not the second item overall; use (//item)[2] for that
//item/@skuThe sku attribute nodes of every item
//item/text()The text nodes directly inside each item
count(//item)A number, not a node set
//item[contains(., 'Widget')]Items whose string value contains "Widget"
//*[local-name()='title']Any element named title regardless of namespace — the escape hatch when prefixes are awkward
//ns:entry/ns:titleElements in the document's default namespace, using the ns prefix this tool binds for you

Browsers implement XPath 1.0, so functions from XPath 2.0 and 3.1 — matches(), string-join(), for … return — are not available, and a query that uses them fails with a syntax error. The four result types are what XPath 1.0 has: a node set, a string, a number or a boolean, and the tool labels which one you got.

The namespace trap

The most common reason an XPath returns nothing is a default namespace. An Atom feed declares xmlns="http://www.w3.org/2005/Atom" on its root, which puts every element in that namespace; //entry then matches nothing, because in XPath 1.0 an unprefixed name means "no namespace", not "any namespace". You must bind a prefix and write //ns:entry. This tool reads every xmlns and xmlns:prefix declaration on the root element and makes them available, binding the default namespace to ns; the badge above the query box lists what is bound. Prefixes declared deeper in the document are not automatically visible, which is a limitation of resolving from the root; local-name() works around it.

Frequently asked questions

Yes. Open Validate, pick the schema language, paste the schema and press Validate; each error is listed with its line, and clicking the line selects it in the input. XSD and RelaxNG are checked by libxml2 (the library behind xmllint), compiled to WebAssembly and loaded the first time you use it. DTD checks content models, required, fixed and enumerated attributes, and ID/IDREF links; leave the box empty to use the DOCTYPE inside the document. Schematron (ISO, XPath 1.0) runs on your browser's XPath engine and reports every failed assert and fired report with the node's path. Well-formedness is always checked as you type.

Almost always a namespace. If the document's root declares a default namespace with xmlns="...", every unprefixed element is in that namespace, and an unprefixed name in XPath 1.0 matches only elements with no namespace. Use the ns prefix this tool binds to the default namespace (//ns:entry), the prefix shown in the badge for other namespaces, or //*[local-name()='entry'] to ignore namespaces entirely.

Because whitespace inside an element that contains text is part of the data. The formatter only re-indents elements whose children are all elements, where the whitespace between them is insignificant. An element with text content, or mixed text and elements, is left exactly as written, so a document that carries meaningful spacing in its text is not corrupted by pretty-printing.

No, and no XML to JSON mapping can be in general. XML has ordered mixed content, namespaces, comments, processing instructions and a distinction between attributes and child elements; JSON objects have unordered keys and no attributes. The mapping here is designed to be readable and to round-trip the common case of element-only data with attributes, using @ for attributes and #text for text, but it is a convenience view rather than an interchange format.

XPath 1.0, because that is what document.evaluate() in browsers implements. It covers the full 1.0 axis set, predicates, and the core function library (contains, starts-with, substring, normalize-space, count, sum, position, last, local-name, name and the rest). Functions and syntax added in XPath 2.0 and later, such as regular-expression matching, sequences and for-expressions, are not available.

Yes, in the Transform tab. XSLT 1.0 runs in libxslt, the library behind xsltproc, compiled to WebAssembly and loaded on first use (Chrome is removing the XSLT engine browsers used to include). XQuery 3.1 (which includes XPath 3.1, maps, arrays and FLWOR expressions) runs in fontoxpath, an open-source engine loaded on first use. XSLT 2.0 and 3.0 are not offered: the only browser engine for them, Saxon-JS, is not openly licensed, so it cannot be bundled here. Use as input replaces the document with the result.

Both. The Compare tab lists changed, added and removed elements, attributes and text by path, ignoring attribute order and formatting, and Open in Diff Checker carries both documents to the Diff Checker's structure mode. For JSON, choose JSON → XML in the output menu and paste JSON: keys starting with @ become attributes, #text becomes text and arrays repeat their element, the same convention as XML → JSON.

Files of 8 MB and more are formatted by libxml2 in a background worker and shown a screenful of lines at a time, so the page stays responsive; a 30 MB file with 250,000 records formats in a few seconds in our tests. Validation and transforms work on these files too. XPath needs the document inside the page, so it is available for files under 8 MB.

No. Parsing uses DOMParser, XPath uses document.evaluate, schema validation runs in libxml2 compiled to WebAssembly, XQuery runs in fontoxpath, and serialisation is JavaScript in the page; the WebAssembly and script files come from this site and nothing is sent to a server. You can confirm this in the Network tab of your browser's developer tools or by using the tool offline. That matters for XML in particular, because SOAP responses, SAML assertions and configuration files routinely contain credentials and personal data.

Changelog

  • v2.0.0 Validation against XSD and RelaxNG (libxml2 2.13 in WebAssembly), DTD (content models, attributes, ID/IDREF; internal subset or pasted) and ISO Schematron, with each error's line. XSLT 1.0 (libxslt in WebAssembly, since Chrome is removing its built-in XSLT) and XQuery 3.1 transforms. Compare two documents by path, with a hand-off to the Diff Checker. JSON to XML. Files of 8 MB and more formatted in a background worker and shown virtually.
  • v1.0.0 Initial release: whitespace-aware pretty-printing and minification, well-formedness errors with line and column, XPath 1.0 with automatic namespace binding from the root element, typed results with node paths, XML to JSON, document statistics, file upload and drag-and-drop.