Skip to main content
XMLDir

Search 311 pages — tools, formats, elements, namespaces, directory, comparisons, XPath, datatypes, glossary, parse errors, schema errors, use cases, blog and product.

Comparison

XML vs HTML

They look alike and behave in opposite ways: HTML forgives everything, XML forgives nothing. Feeding one to the other's parser is the most common way this bites.

HTML has a specified error-recovery algorithm — a browser handed broken markup must produce a tree anyway, and every browser produces the same one. XML has the opposite requirement: a well-formedness error is fatal, and a conforming parser must stop rather than guess.

That single difference explains the rest. HTML has void elements you never close, optional end tags, unquoted attribute values and boolean attributes. All four are well-formedness errors in XML, and a template that emits HTML habits into an XML document produces a file no parser will read.

XHTML was the attempt to have both, and it lost — but the XHTML namespace is still how a sitemap declares hreflang alternates, so you will meet it whether or not you ever write a page in it.

What actually differs

XML compared with HTML, one row per aspect
AspectXMLHTML
On a syntax errorFatal. The parser stopsRecovers, with a specified algorithm
Void elementsNone. <br> must be <br/><br>, <img>, <meta> are never closed
End tagsAlways requiredOptional for many elements
Attribute quotingRequiredOptional in many cases
Boolean attributesNot permitted — every attribute has a valuePermitted: <input disabled>
CaseSensitiveTag and attribute names are not
VocabularyWhatever you defineFixed by the HTML specification

Shown, not asserted

The differences above are claims, so here they are being made. Every one of these runs on each test run, against the same engines the tools use — the outputs are what came back, not what we expected.

  • An unclosed <br> — perfectly ordinary HTML — makes the whole document unreadable as XML.

    document.xml
    <p>line one<br>line two</p>

    What came back

    Opening and ending tag mismatch: br line 1 and p (line 1)
  • Self-closed, the same markup is fine. That slash is the entire difference.

    document.xml
    <p>line one<br/>line two</p>

    What came back

    Well-formed. XML accepts it.
  • So is an unquoted attribute value, which HTML permits and XML does not.

    document.xml
    <img width=100/>

    What came back

    AttValue: " or ' expected (line 1)

Which to pick

XML, when

  • The consumer is a machine and you would rather it refuse bad input than guess at it.
  • You need your own vocabulary, or someone else's — a feed, an invoice, a schema.
  • The data is going to be validated, transformed, or signed.

HTML, when

  • The consumer is a browser rendering a page for a person.
  • Robustness matters more than strictness: a broken tag should degrade rather than blank the page.

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.