XML Formatter and Validator

Beautify or minify XML, find the exact line of any error, browse it as a tree, test XPath and convert it to JSON – with comments, CDATA and namespaces kept.

  • Validates as you type
  • Tree and XPath
  • XML to JSON
  • Runs in your browser
Open

              
              

Processed in your browser – your XML is never uploaded.

How to format XML

  1. Paste or open XMLPaste XML, open a file (.xml, .svg, .rss, .xsd, .config and more) or press Sample.
  2. Format or minifyIt’s checked as you type. Choose the indent, collapse empty elements, keep or drop comments, or put long attribute lists on separate lines.
  3. Explore and convertSwitch to Tree to browse elements, XPath to query them, or JSON to convert. Copy or download the result.

Common XML errors and fixes

ErrorExampleFix
Unescaped &<co>Smith & Sons</co>Write &amp;
Unescaped < in text<if>a < b</if>Write &lt; or use CDATA
Mismatched tags<b><i>text</b></i>Close in reverse order
Unquoted attribute<item id=5>id="5"
More than one root<a/><b/>Wrap everything in one root element
Text before the declarationSpaces before <?xml …?>The declaration must be the very first thing
Undeclared prefix<dc:title>Add xmlns:dc="…" to an ancestor

Frequently asked questions

What does “not well-formed” mean?

The XML breaks a basic rule – a tag isn’t closed, tags are closed in the wrong order, an attribute value isn’t quoted, or a character like & isn’t escaped (write &amp;amp;). The message shows the line and column; press Show line to jump there.

Does formatting change my data?

Elements, attributes, comments, CDATA sections, the XML declaration and doctype are kept exactly. Whitespace between elements is replaced by indentation, and runs of spaces inside text are collapsed – so for documents where whitespace matters (like xml:space="preserve"), check the result.

Does it validate against an XSD schema?

It checks that the XML is well-formed using your browser’s XML parser. Validation against an XSD or DTD isn’t supported in the browser.

How do I use XPath with namespaces?

Prefixes declared in the document, like dc: in the sample, work directly. If the root element has a default namespace (xmlns="…"), use the prefix d: for it – for example //d:item/d:title.

How is XML converted to JSON?

Each element becomes a key; attributes become keys starting with @; repeated elements become arrays; and text inside an element with attributes or children goes in #text. An element with only text becomes a plain string.

Is my XML uploaded?

No. Formatting, validation and conversion all happen in your browser.

Last updated: