{ } Format & Compare

XML Formatter, Validator & XPath Tester

Pretty-print or minify XML while preserving comments, CDATA, entities and xml:space; validate with line and column; test XPath; convert XML to JSON.

Keeps comments & CDATA Errors with line/column XPath tester XML → JSON

Loading XML Formatter…

What this page sends

  • Your input: Processed in this tab and not sent to a server.
  • Share links: Share links put a Base64 copy of your input and output in the URL itself (after #d=). Anyone with the link can read it, so don't share a link that contains secrets.
  • Editor: On desktop screens the code editor (Monaco) is downloaded from cdn.jsdelivr.net; phones get a built-in lightweight editor instead.
  • Page load: Loading the page requests HTML, scripts and images from ByteKiln, fonts from Google Fonts, and sends Google Analytics page views, tool-usage events and catalog interactions (tool/category IDs, result status and whether a click followed search — never your input, output or search terms). Privacy & sharing

How the XML Formatter, Validator & XPath Tester Works

SOAP responses, sitemaps, RSS feeds, .csproj and .resx files, Android layouts, Maven POMs — XML is still everywhere, usually either minified on one line or indented inconsistently. This formatter pretty-prints XML with 2 or 4 spaces or tabs, optionally one attribute per line, and minifies it back. Unlike formatters that parse and re-serialize, it works from the original tokens, so comments, CDATA, processing instructions, the XML declaration, the DOCTYPE and entity references are kept exactly as written, text inside elements is never reflowed, and xml:space="preserve" is respected. Formatting is idempotent: formatting, minifying and formatting again gives the same result. Validation checks well-formedness — matching tags, a single root, quoted and unique attributes, defined entities, declared namespace prefixes — and reports errors with line and column. An XPath tester runs XPath 1.0 expressions with the browser's engine and lists the matches, and an XML-to-JSON mode converts documents using the common @attribute convention. External DTDs and entities are never fetched.

Formatting rules

Elements that contain only other elements are indented, one child per line. Elements with text or mixed content are written on one line exactly as in the source. Empty elements stay as written — <a/> or <a></a>. Whitespace between tags inside a tag is normalized; attribute values and quotes are not touched.

Well-formedness

The parser checks the XML 1.0 rules and namespace prefixes and stops at the first error with its line and column — for example "Expected </b> (opened on line 2) but found </a>" — rather than producing half-formatted output.

Safety

The tokenizer never resolves external entities or fetches DTDs, and entities declared in an internal DTD are kept as references rather than expanded, which also avoids "billion laughs" expansion attacks. A byte order mark is removed and noted.

XPath

Expressions are evaluated by the browser's built-in XPath 1.0 engine (document.evaluate). Node-set results are listed as serialized XML, attributes as name="value", and number, string and boolean results are shown directly.

Limitations

  • Well-formedness only: no validation against an XSD or DTD, and entities from a DTD are left as references.
  • XPath is XPath 1.0 through the browser's engine; XPath 2.0/3.1 functions and XQuery are not available.
  • XML to JSON uses one convention (attributes as "@name", text as "#text"); other libraries use different conventions, so JSON from here won't round-trip through every library.
  • Very large documents are formatted in a worker but still held in memory.

FAQ

Short answers for the things developers usually ask before trusting a tool.

Is my XML uploaded?

No. It's parsed and formatted in your browser; very large files are processed in a background worker. DTDs and external entities are never fetched.

Will formatting change my data?

Only whitespace between elements. Text content is kept exactly: elements that contain text — including mixed content like <p>Hello <b>world</b></p> — are left on one line as written, and anything inside xml:space="preserve" is untouched. Comments, CDATA sections, processing instructions, the XML declaration, the DOCTYPE and entity references like &amp; and &#169; come out exactly as you wrote them.

Why does validation fail on &nbsp;?

XML only predefines five entities: &amp; &lt; &gt; &quot; &apos;. &nbsp; is an HTML entity. Use the numeric reference &#160; instead, or declare the entity in a DTD — declared entities are accepted and kept as written, not expanded.

How do I use XPath with namespaces?

XPath 1.0 has no default namespace, so //item won't match <item> inside xmlns="urn:…". The tester maps the document's default namespace to the prefix d:, so write //d:item. Other prefixes (soap:, xs:) work as declared in the document.

How is XML converted to JSON?

With the common convention: attributes become "@name" keys, element text becomes a string (or "#text" when the element also has attributes or children), and repeated child elements become arrays. XML and JSON don't map one-to-one, so check the result for elements that appear once in one document and several times in another.

Related tools

Useful follow-ups when one conversion usually turns into three more.