Document syntax
Internal subset
The markup declarations written inline between square brackets in a DOCTYPE, rather than fetched from an external DTD file.
The internal subset is the part of a DTD that travels inside the document. In practice it is used for one thing far more than any other: declaring the general entities a document wants to reference, since XML predefines only five.
Declarations in the internal subset take precedence over ones in the external DTD, which makes it useful for overriding a single entity without copying a whole grammar. It is also what makes it dangerous — anyone who can inject an internal subset can redefine entities the document was expected to inherit.
- Defined in
- XML 1.0 §2.8
- Category
- Document syntax
- Also written
- internal DTD subset, DOCTYPE brackets
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.
An entity declared in the internal subset resolves in content.
document.xml <!DOCTYPE doc [<!ENTITY product "XMLDir">]> <doc>Built with &product;.</doc>expression string(/doc)What the engine returns
Built with XMLDir.Entities may reference other entities, and expansion is recursive.
document.xml <!DOCTYPE x [<!ENTITY a "&b;"><!ENTITY b "boom">]> <x>&a;</x>expression string(/x)What the engine returns
boom
What catches people out
- An entity must be declared before it is referenced in content, though the declarations themselves may be in any order relative to each other.
- A recursive entity — one that references itself, directly or through a chain — is a fatal error rather than an infinite loop.
- Parameter entities are legal in the internal subset only in limited positions, and several parsers, ours included, refuse them.
Where it bites
A definition on its own is trivia. These are the pages where this term decides whether a document works.
- Parse errorsDetected an entity reference loopWhat a self-referencing entity chain in the internal subset reports.
- Parse errorsEntity is not definedThe failure when the reference is there but the declaration is not.
Related terms
- Document type declarationThe <!DOCTYPE root …> in the prolog that names the document's root element and points at, or contains, its markup declarations.
- General entityAn entity declared with <!ENTITY name "text"> whose replacement text is substituted wherever &name; appears in content.
- Parameter entityAn entity declared with <!ENTITY % name "…"> and referenced as %name;, usable only inside markup declarations rather than in document content.
- Entity expansion attackA denial of service in which nested entity definitions expand exponentially, turning a few hundred bytes of document into gigabytes of text.
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.