Skip to content
OddsockLocal
Local
Source text

Formatting

2 wordsRuns in this browser. Nothing is uploaded.

How to use

  1. Paste a single XML document.
  2. Read the indented tree if it is well formed and has one root.
  3. If the error names a line and column, fix that spot. A leading O means the paste was not XML.
  4. Use the validator when you only need a yes or no and do not want the reprint.

What is XML formatter?

XML formatter checks that the document is well formed, requires exactly one root element, and reprints it with a two-space indent. <note><to>Sam</to><body>Hi</body></note> becomes a note element with to and body nested inside. Attribute order and text are kept. Values are not retyped as numbers, so a text node 02 stays 02.

Read more

A document type declaration is refused. Formatting a DTD would mean expanding entities and pulling in declarations this page will not fetch. More than one root is an error, because an XML document has one. Mixed content, text and child elements in the same parent, is not given extra whitespace between inline tags, so a sentence with an <em> in the middle does not grow spaces that change the text a reader sees.

The validator is the page that stops at “Valid XML” and does not reprint. Both report the line and column when the parse fails. Pasting Odd socks in the dryer. fails at line 1, column 1, because the character O is not the start of a tag.

Use cases

  • A SOAP or config fragment is one line and you want note, to and body indented before you edit the text.
  • A file with two top-level elements should fail, so you do not ship a document parsers will reject.
  • An inline <em> inside a sentence must not gain spaces when the rest of the tree is indented.
  • You need the formatted document, not only the words Valid XML.

A note with two child elements

<note><to>Sam</to><body>Hi</body></note>

<note>\n <to>Sam</to>\n <body>Hi</body>\n</note>

Why use Oddsock

Mixed content stays tight. Indenting inside a sentence would change “Hello <em>there</em>” into something with different spaces.

Related tools

Using this tool

The formatter expects a tag. Odd socks in the dryer. fails at line 1, column 1, because O is not a legal start. Wrap text in an element if it is supposed to be XML.