ToolBit

Format and validate XML in your browser

Formatted XML
Press Format

Runs in your browser. Nothing is uploaded.

Paste XML into the input and press Format, or Ctrl+Enter (Cmd+Enter on a Mac). Minify puts the document on one line. Changing Indent (2 spaces, 4 spaces or Tab) repeats your last action.

The tool checks that the document is well-formed and changes only whitespace that contains a line break. Tags, entities, CDATA, comments, the declaration and the DOCTYPE stay as written. Under the output you see its size in bytes, the root element, the element count and the nesting depth. If the input is not well-formed, the message appears under it as “Line L, column C: …”, the cursor jumps there and the character is selected. The previous output stays, marked as from the previous input.

Example

Input:

<?xml version="1.0" encoding="UTF-8"?><catalog><book id="1"><title>Tom &amp; Jerry</title><note>Use <b>care</b>.</note></book><empty/></catalog>

Output with 2 spaces:

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book id="1">
    <title>Tom &amp; Jerry</title>
    <note>Use <b>care</b>.</note>
  </book>
  <empty/>
</catalog>

The status line shows root catalog and 6 elements. <note> mixes text and a child element without a line break, so it stays on one line.

Limitations

  • Input is limited to 1,000,000 bytes of UTF-8. Output is capped at 10,000,000 characters.
  • Only well-formedness is checked. There is no DTD or XSD validation and no namespace prefix check. The version and encoding in the declaration are not checked, and the encoding is not applied.
  • Without a DOCTYPE, only the five predefined entities and numeric references are accepted. With a DOCTYPE, any named entity is accepted and left as written. Entities are never expanded and nothing is fetched.
  • Minify drops a line break between two tags or at the edge of an element’s content; next to text it becomes a space.
  • Line breaks under xml:space="preserve", in CDATA, comments and inside tags are kept, so Minify output can still contain them.
  • A byte order mark is dropped. CRLF and CR become LF.
  • The XML declaration must come first. Even a space before <?xml is an error.

FAQ

Why does & break my XML, and how do I escape it?

XML 1.0 forbids a literal ampersand or left angle bracket in text. Write &amp; for & and &lt; for <. The tool reports a bare & at its position.

What is the difference between XML and HTML? Why is HTML often not valid XML?

HTML allows <br> and <img> with no end tag, omitted end tags (</li> before another <li>) and unquoted attribute values. XML requires an end tag with a matching name for every start tag, or a self-closing tag such as <br/>, and quoted attribute values.

Does formatting change my XML?

Only whitespace that contains a line break, including empty lines. Spaces on a line, as in <p>Hello <b>world</b>!</p>, stay. Format puts each line of text on its own indented line; Minify joins them with single spaces. If a program reads one value per line, such as a list of addresses, use Format.

What is CDATA for?

A CDATA section, <![CDATA[ ... ]]>, holds text where < and & need no escaping, such as a code snippet. Only the closing ]]> counts as markup, and sections cannot nest. The tool never changes the inside of a CDATA section, line breaks included.

What is the difference between well-formed and valid XML?

Well-formed means the syntax rules are met: matched tags, quoted attributes, one root element. Valid means the document also has a document type declaration and complies with its constraints. This tool checks well-formedness only. For a DTD or XSD check, use a schema validator.