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

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.

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.