Document syntax
Predefined entity
The five entities every XML parser knows without a declaration: &, <, >, ' and ". Only two of them must always be escaped.
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
- &, <, >, ", ', 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>& < > ' "</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.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- Parse errorsUnescaped ampersand (EntityRef: expecting ';')What an unescaped < in content reports.
- Parse errorsUnescaped '<' in an attribute valueThe same character, inside an attribute value, with a different message.
- ToolsXML escape & unescapeApplies exactly these five, in either direction.
Related terms
- Entity referenceAn &name; reference replaced by that entity's replacement text during parsing. Only five names are predefined, which is why fails in XML.
- Character referenceA &#nnn; or &#xhhhh; escape naming a Unicode code point directly rather than by an entity name. It needs no declaration, unlike an entity reference.
- PCDATAParsed character data: text content that the parser scans for markup, so < and & in it have meaning and must be escaped.
- AttributeA name–value pair on an element's start tag, whose value is always a quoted string. Attributes are unordered, unique per element, and never nested.
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.