Skip to main content
XMLDir

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

Document syntax

Predefined entity

One of the five entities every XML parser knows without a declaration: &, <, >, ' and ".

These five exist because the characters they escape would otherwise start markup or close a quoted value. Two of them — & and < — genuinely must be escaped in content. The other three are situational: > only inside a ]]> sequence, and the quote characters only inside an attribute delimited by that same quote.

Escaping all five unconditionally is the usual advice and costs nothing. Escaping fewer is legal but requires knowing which context you are in, which generated code rarely does.

Defined in
XML 1.0 §4.6
Category
Document syntax
Also written
&amp;, &lt;, &gt;, &quot;, &apos;, built-in entity

Shown, not asserted

All 2 claims are executed on every test run, against the same engines the tools use. If the behaviour changes, the test fails rather than this page quietly becoming wrong.

  • All five resolve without any declaration.

    document.xml
    <x>&amp; &lt; &gt; &apos; &quot;</x>
    expression
    string(/x)

    What the engine returns

    & < > ' "
  • A quote character is only a problem inside an attribute using that same quote.

    document.xml
    <x a='he said "hi"' b="it's fine"/>

    What the engine returns

    Well-formed.

What catches people out

  • &apos; is the one HTML did not have for years. If your consumer is an HTML parser, prefer &#39;.
  • In content, only & and < strictly require escaping. That does not make escaping the others wrong.
  • These five are the only entity names that work in a document with no DOCTYPE.

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.