Toolvore

XML Formatter

Validate and format XML without rewriting attributes, CDATA or meaningful text spacing.

This tool runs entirely in your browser. Your data is never uploaded, never stored, and never leaves your device.

Validate and format XML while preserving CDATA, attribute spelling and meaningful text boundaries, with an explicit choice about structural whitespace.

How to use it

  1. 1Paste XML or open a local XML file.
  2. 2Choose whitespace-preserving or structural formatting, then validate or format.
  3. 3Review any parsing error and copy or download the valid result; DTDs are not supported.

What happens to your data

XML validation and token-aware formatting happen locally. Markup is displayed as text, not executed HTML, and documents containing DTDs are refused rather than fetching external entities or schemas.

Last updated September 2026

Make XML readable without treating meaningful text as expendable whitespace. This XML formatter and validator checks the document before formatting and preserves original attribute spelling, CDATA and content spacing. That matters when XML contains prose, SOAP payloads or configuration where a generic split-on-angle-brackets formatter changes the data.

Mixed content is the important trap: in <p>Hello <b>world</b>!</p>, inserting line breaks around the b element changes the text seen by a consumer. Both formatting modes preserve those text boundaries. Structural whitespace mode makes a deliberate assumption for element-oriented data, not a universal lossless transformation. xml:space=preserve is respected when deciding where whitespace may change.

An XML validator checks whether the document is well formed. It does not prove that an invoice satisfies a business rule, validate an XSD, or check that a SOAP endpoint accepts it. This page refuses DTDs and external entity declarations instead of resolving them, keeping formatting independent of external files and servers.

How it works

The document is parsed for well-formedness and scanned with XML-aware token boundaries. Quoted > characters do not end a tag, and CDATA, comments and processing instructions are distinguished from ordinary markup. Formatting changes permitted separators rather than serializing the document through an object representation that can erase original spelling or text.

Input is limited to 500,000 characters, a 1 MB UTF-8 file, 25,000 nodes, 100 nesting levels and two million output characters. XML declaring another encoding is rejected because downloads are UTF-8. Neither mode is XML canonicalization or safe for editing a digitally signed document. Use preservation mode when spacing itself can carry meaning. Only choose structural mode when you know the consumer treats inter-element whitespace as insignificant. Namespaces and xml:space are document semantics, not decoration. XML displayed in the editor is text, not HTML injected into the page; opening it here does not execute its markup.

Worked example: a quoted angle bracket is not a tag boundary

Input
<r note="x > y"><a/></r>
Result
<r note="x > y"> <a/> </r>

The attribute spelling is retained. Mixed text such as <p>Hello <b>world</b>!</p> stays unchanged in both modes.

Common use cases

  • Inspecting a SOAP request while retaining its mixed-content text
  • Formatting an XML configuration before reviewing a change
  • Checking a quoted attribute containing > without corrupting its tag
  • Reading CDATA and namespace-qualified elements in a local document

Frequently asked questions

Is XML pretty print always lossless?+

No. Whitespace can be meaningful, especially in mixed content and xml:space=preserve regions. Use the safer preservation mode, and only allow structural whitespace changes when your document's consumer permits them.

Does this XML validator validate an XSD or DTD?+

No. It checks XML well-formedness, not schema validity or business rules. DTD-bearing documents are refused here, and no external entity or schema resource is fetched.

Will the formatter rewrite attributes or CDATA?+

The formatting pipeline preserves the source spelling of attribute values and CDATA instead of rebuilding them through a generic object serializer. Invalid XML must be corrected before a formatted result can be generated.

Why does an attribute containing > matter?+

A greater-than sign inside a quoted attribute is not the end of the tag. XML-aware tokenization treats it as part of the value; splitting the document at every > would corrupt it.

Can I beautify XML that contains embedded text?+

Yes. Both modes preserve mixed-content text boundaries. Preservation mode also retains existing whitespace-only text, so an already-indented document may remain unchanged. A line break inserted between words and child elements can alter a sentence even when markup remains valid.

Is an XML formatter the same as a JSON-to-XML converter?+

No. A formatter works on an existing XML document. JSON-to-XML must define how arrays, attributes and text map between formats; use the separate converter and review its loss boundaries.