ToolGlint

XML Formatter

Format and validate XML in your browser. Indent messy markup, spot syntax errors, and keep your data on your device.

Paste or type, or drop a file on the box.

Runs in your browser. Nothing you enter is uploaded or stored.

How to use the XML Formatter

  1. Paste or type your XML into the input box, or load the sample to try it.
  2. The indented result appears as you type. Pick 2 spaces, 4 spaces or tabs for the indent.
  3. Switch to Minify to remove the whitespace between tags and put the document on one line.
  4. If the XML is not well formed, read the message under the boxes for the line and column of the problem.
  5. Switch the output to Tree to close and open any element that holds other elements, which makes a large document easier to explore.
  6. Copy the result or download it as an .xml file.

Questions and answers

Can I collapse XML elements?
Yes. Switch the output from Text to Tree, then click the arrow beside an element to close or open it. A closed element shows how many children it holds. Open all and Close all change the whole document at once. Copy and Download always give you the complete XML, whatever is closed.
Is my XML sent to a server?
No. The XML is parsed and formatted by your own browser. Nothing you paste is uploaded, stored or logged, so you can use it with configuration files, API responses and other private data.
What does the validation check?
It checks that the document is well formed: one root element, every tag closed and correctly nested, attribute values in quotes, and special characters such as & written as entities. It does not check the document against a DTD or an XSD schema.
Why is my XML reported as invalid?
The usual causes are a tag that is never closed, tags closed in the wrong order, a bare & or < inside text, an attribute value without quotes, or more than one root element. Tag names are also case sensitive, so <Item> cannot be closed with </item>.
Does formatting change my data?
Only whitespace between tags is changed, and only inside elements that hold nothing but other elements. An element that contains text, CDATA or xml:space="preserve" is written exactly as it was, so spaces and line breaks that could matter are kept. Comments and processing instructions are kept too.
What small differences might I see in the output?
An element with no content is written in its short form, so <note></note> becomes <note/>. Attribute values are written in double quotes, and character references such as &#65; are shown as the character they stand for. An XML parser reads the result the same way as the original.
Can it format HTML?
Only if the HTML is also valid XML, as XHTML is. Ordinary HTML allows unclosed tags such as <br> and attributes without values, which XML does not, so it is reported as invalid here.

Related tools