Embedding Unparsed Entities in Documents

The DTD only declares the existence, location, and type of the unparsed entity. To actually include the entity in the document at one or more locations, you insert an element with an ENTITY type attribute whose value is the name of an unparsed entity declared in the DTD. You do not use an entity reference like &turing_getting_off_bus;. Entity references can only refer to parsed entities.

Suppose the image element and its source attribute are declared like this:

<!ELEMENT image EMPTY>
<!ATTLIST image source ENTITY #REQUIRED>

Then, this image element would refer to the photograph at http://www.turing.org.uk/turing/pi1/busgroup.jpg:

<image source="turing_getting_off_bus"/>

We should warn you that XML doesn’t guarantee any particular behavior from an application that encounters this type of unparsed entity. It very well may not display the image to the user. Indeed, the parser may be running in an environment where there’s no user to display the image to. It may not even understand that this is an image. The parser might not load or make any sort of connection with the server where the actual image resides. At most, it will tell the application on whose behalf it’s parsing that there is an unparsed entity at a particular URL with a particular notation and let the application decide what, if anything, it wants to do with that information.

Tip

Unparsed general entities are not the only plausible way to embed non-XML content in XML documents. In particular, ...

Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.