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
- &, <, >, ", ', 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 to an entity, replaced by that entity's replacement text during parsing.
- Character referenceA &#nnn; or &#xhhhh; escape naming a Unicode code point directly, rather than by an entity name.
- 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.
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.