XML Formatter and Validator

Paste XML to indent it, check that it is well-formed and see it as a tree. Comments, CDATA and the XML declaration are kept.

Editor (Formatted View)
1
Ready — paste or type XML here
Viewer
Tree view will appear here after formatting
Ready

How to format XML

  1. Paste XML into the editor, drop a file on it, or click Upload.
  2. Click Format (or Ctrl + Enter). Child elements are indented under their parent.
  3. If the document isn't well-formed, the status bar shows the line, the column and what went wrong.
  4. Use the arrows next to the line numbers to fold elements you don't need to see.

What "well-formed" means

The validator checks that your XML follows the basic rules every XML parser requires. It does not check the document against an XSD or DTD schema.

Common error messages and what they mean

These are the messages Chrome and Edge show. Firefox words them a little differently, but the line and column work the same way.

MessageUsual cause
Opening and ending tag mismatchAn element was closed in the wrong order, never closed, or closed with a different spelling or capitalisation.
AttValue: " or ' expectedAn attribute value has no quotes, as in <a id=7>.
xmlParseEntityRef: no nameA bare & in text, such as "fish & chips". Write &amp;.
StartTag: invalid element nameA < that doesn't start a tag, often from a comparison like 1 < 2 in text.
Extra content at the end of the documentThere is more than one root element.
Premature end of dataThe document stops before all elements are closed. Often a copy-paste that missed the last lines.

What formatting changes and what it keeps

Each element goes on its own line, indented by two spaces, four spaces or a tab. An element that only holds text stays on one line, like <city>Boston</city>. The XML declaration, comments, CDATA sections, processing instructions and namespace prefixes such as soap:Envelope are all kept. Whitespace between elements is replaced by the new indentation, and character references like &#65; are written out as the character they stand for.

Sorting XML

Sort XML puts child elements in alphabetical order at every level, which makes two versions of a document easy to compare side by side. Only the order of elements changes: attributes, text, comments, CDATA and namespace prefixes stay as they were. Elements that share a name, like a list of <item> entries, keep their original order relative to each other. Documents that contain a <!DOCTYPE> are rejected for security reasons, so remove it before sorting.

Converting XML to JSON

Convert to JSON turns elements into keys. Elements that repeat become an array, attributes become ordinary keys, and all values come out as strings, because XML has no number or boolean type. The root element becomes the outer object. For example:

<order id="7">
  <item>pen</item>
  <item>ink</item>
</order>

becomes

{
  "id": "7",
  "item": [
    "pen",
    "ink"
  ]
}

Frequently asked questions

Does the validator check my XML against a schema (XSD)?

No. It checks that the XML is well-formed. A document can be well-formed and still fail schema validation, for example when a required element is missing.

Will formatting change my data?

Only the whitespace between elements and the way character references are written. Text content, attribute values, comments and CDATA stay the same.

Can I format SOAP messages, RSS feeds or Android layout files?

Yes. They are all XML, and namespaced names like soap:Envelope or android:layout_width are left exactly as they are.

How do I minify XML?

Click Minify. The whitespace between tags is removed and the document is written on a single line. Text inside elements is trimmed.

Other tools

Share Content

Choose what to share and generate an instant link

🔥 One-time link Content deleted from server after first view
✉️
Uploading to server…