OmniFeed Search

XML formatter and validator

Paste XML to format or minify it, and if it isn't well-formed, you'll see the line and column of the first error. It checks syntax only, not a DTD or XSD schema, and Format changes the layout but never the text inside elements. It runs in your browser; nothing you enter is uploaded.

What well-formed means

XML is well-formed when it follows the syntax rules of the XML 1.0 standard. An XML parser rejects a file at the first rule it breaks, so one stray character is enough to make a feed or a config file fail to load. The checker looks for these errors and reports the first one in the file:

Well-formed isn't the same as valid. A valid document also matches a schema, a DTD or XSD file that says which elements and attributes are allowed where, and the tool doesn't check that. When a file has a DOCTYPE, the tool accepts any named entity, such as ©, because the DTD might define it, and it doesn't download the DTD to find out.

HTML habits that break XML

Browsers read HTML loosely, so markup copied from a web page often fails as XML. Each of these works in HTML and is an error in XML:

To escape a block of text before you put it inside an element, use the HTML entity encoder. Its output is valid XML text too.

What Format and Minify change

Format puts each element on its own line and indents it by its depth. Minify removes that whitespace and puts the document on one line. Neither changes the text inside an element:

Most programs that read XML as data ignore whitespace between tags, but in some places it's part of the content, such as inside the <pre> element of XHTML. To keep an element's whitespace, add xml:space="preserve" to it, and Format and Minify copy that element unchanged.

Finding the mistake from the error position

The line and column point at the start of the problem the message describes. For a mismatched end tag, that's where the parser noticed it, which comes after the real mistake. In <a><b>text</a>, the error points at </a> and says it expected </b>. The message also gives the line where <b> starts, and the missing </b> belongs somewhere between that line and the error.

Checking XML on the command line

xmllint --noout data.xml                       # check; prints nothing if well-formed
xmllint --format data.xml                      # format with a 2-space indent
xmllint --noout --schema schema.xsd data.xml   # validate against an XSD schema

xmllint comes with the libxml2 library. macOS includes it, and on Debian and Ubuntu it's in the libxml2-utils package. Unlike this tool, it can check a file against a schema.

More in data and formats

Other tools