XML DTD Notations and Unparsed Entities Explained

In an XML Document Type Definition (DTD), notation declarations associate unparsed entities with external helper applications by explicitly identifying the format of non-XML data and linking it to an application or system handler capable of processing it. This mechanism allows XML parsers to handle non-textual data—such as images, audio files, or proprietary binary formats—by passing the resource location and its handler instructions to the host environment.

The Role of Unparsed Entities

An unparsed entity is an external resource that contains non-XML data or text that the XML parser should not parse. These entities are defined in the DTD using the <!ENTITY> declaration along with the NDATA (notation data) keyword:

<!ENTITY company_logo SYSTEM "https://example.com/logo.png" NDATA png>

In this declaration, company_logo is the entity name, the SYSTEM identifier points to the binary file, and NDATA png specifies that the entity conforms to a notation named png.

The Role of Notation Declarations

A notation declaration defines the format referenced by the NDATA attribute and supplies the identifier for the helper application or specification. It is declared using the <!NOTATION> keyword:

<!NOTATION png SYSTEM "viewer.exe">

Alternatively, public identifiers or MIME types can be used:

<!NOTATION png PUBLIC "image/png">

How the Association Works

The association between the raw data and the application occurs through a three-step relationship in the XML architecture:

  1. Format Identification: The <!NOTATION> declaration defines a format name (e.g., png) and assigns it an external program name, URI, or public MIME type identifier.
  2. Entity Binding: The <!ENTITY ... NDATA ...> declaration links the file resource (the unparsed entity) to the specific notation name.
  3. Application Hand-Off: In the XML document, an element references the entity using an attribute declared with the ENTITY or ENTITIES type.

When an XML processor encounters the unparsed entity attribute in the document, it validates the entity against the DTD, reads the associated notation, and exposes both the entity’s system identifier (the file path or URI) and the notation identifier (the helper application or MIME type) to the downstream processing application. The application can then launch the specified helper program or delegate the file to the appropriate media handler.