Entity Declarations, Attributes and Expansion

Entities must be declared before they can be used. They may be declared
in the DTD, if your XML parser processes the DTD (also known as the external
subset), or the internal subset. Note: if the same entity is declared more
than once, only the first declaration applies and the
internal subset is processed before the external subset.

All entities are declared with the "ENTITY" declaration. The exact format of the declaration
distinguishes between internal, external, and parameter entities.

The system identifier must point to an instance of a resource via a URI, most commonly
a simple filename. The public identifier, if supplied, may be used by an XML
system to generate an alternate URI (this provides a handy level of indirection
on systems that support public identifiers).

An external entity that incorporates chap1.xml
into your document might be declared like this:

<!ENTITY chap1 SYSTEM "chap1.xml">

Despite the growing trend to store everything in
XML, there are some legacy systems that still store data in non-XML formats.
Graphics are sometimes stored in odd formats like PNG and GIF, for example
;-).

External entities that refer to these files must declare that data they
contain is not XML. They accomplish this by indicating the format of the external
entity in a notation:

External entities can be further classified as either "parsed"
or "unparsed". Entities which refer to external files that contain
XML are called "parsed entities;" entities which refer to other
types of data, identified by a notation, are "unparsed."

The parser inserts the replacement text of a parsed entity into the
document wherever a reference to that entity occurs. It is an error to insert
an entity reference to an unparsed entity directly into the flow of an XML
document. Unparsed entities can only be used as attribute values on elements
with ENTITY attributes.

Unparsed entities are used most frequently on XML elements that incorporate
graphics into a document. Consider the following brief document:

There is a somewhat subtle distinction between entity attributes and
entity references in attribute values. An "ordinary" (CDATA) attribute contains text. You can put internal entity references
in that text, just as you can in any other content. An ENTITY
attribute can only contain the name of an external, unparsed entity. In particular,
note that it contains the name of the entity, not a reference to the entity.