DTD Embedded Images

To embed non-XML data (such as an image) into your XML document, you need to treat it as an external unparsed entity.

To declare an external unparsed entity, you use the <!ENTITY> declaration along with the NDATA keyword.

Syntax

You can also use public external unparsed entities by using the PUBLIC keyword along with a Formal Public Identifier (FPI):

Example

Here's an example of a private external unparsed entity. Here, we declare a new notation named JPG for the image/jpeg MIME type. Then we declare an external unparsed entity called mt_cook_1 that refers to an image file called mt_cook1_jpg. We then create a new attribute of type ENTITY — this means that we can now use this attribute in our XML document to refer to the unparsed external entity.

After declaring the external unparsed entity in our DTD (and creating an attribute of type ENTITY), we can now embed it in our XML document:

Embedding Multiple Images

If you need to embed multiple external unparsed entities via a single attribute, you simply give your attribute a type of ENTITIES (plural). This allows you to assign multiple images separated by a space.

Here's an example:

Now that we've changed the photo attribute to type ENTITIES, we can assign multiple images to it in our XML document: