XML Formatter

Format or minify XML in the browser. JSON and XML have their own page: JSON to XML

What this page does

A flat XML string is hard to scan. This page indents one root element, or writes it back on one line. Turning JSON into XML stays on JSON to XML.

How to use it

  1. Paste XML. Update as you type is on, and that path formats rather than minifies.
  2. Format runs once. Show Example fills <note><to>Ada</to><body>hello</body></note>.
  3. The formatted result is note, then to with Ada, then body with hello, each child indented by two spaces.
  4. Minify writes the same document on one line: <note><to>Ada</to><body>hello</body></note>.
  5. Clear All empties both boxes. Copy Result copies the output.

Rules and edges

There must be one root element. A comment and a CDATA block are kept. An attribute is written back with double quotes. Text is trimmed. Two root elements, or a tag that never closes, stops with an error. This page does not sort elements and does not drop a default namespace.

Where people use it

  • Reading a one-line feed before editing a tag.
  • Minifying a small document to paste into a request.
  • Checking that a note still has the same text after a round trip.

Questions

Why did Update as you type ignore Minify?

Typing runs Format. Minify runs when you press Minify.

Can this page turn XML into JSON?

No. That conversion is on JSON to XML, which also converts back.