Quackit Logo

FREE Hosting!

With every domain name you register with ZappyHost, you get FREE hosting.

$1.99 Domain Names

With every new non-domain purchase thru ZappyHost, you get a domain name for only $1.99.

DTD Embedded Images

Print Version

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

<!ENTITY name SYSTEM value NDATA TYPE>

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

<!ENTITY name PUBLIC FPI value NDATA TYPE>

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.

<!NOTATION JPG SYSTEM "image/jpeg">
<!ENTITY mt_cook_1 SYSTEM "mt_cook1.jpg" NDATA JPG>
<!ATTLIST mountain
  photo ENTITY #IMPLIED>

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:

<mountains>
  <mountain photo="mt_cook_1">
    <name>Mount Cook</name>
  </mountain>
  <mountain>
    <name>Cradle Mountain</name>
  </mountain>
</mountains>

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:

<!NOTATION JPG SYSTEM "image/jpeg">
<!ENTITY mt_cook_1 SYSTEM "mt_cook1.jpg" NDATA JPG>
<!ENTITY mt_cook_2 SYSTEM "mt_cook2.jpg" NDATA JPG>
<!ATTLIST mountain
  photo ENTITIES #IMPLIED>

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

<mountains>
  <mountain photo="mt_cook_1 mt_cook_2">
    <name>Mount Cook</name>
  </mountain>
  <mountain>
    <name>Cradle Mountain</name>
  </mountain>
</mountains>

Enjoy this website?

  1. Link to this page (copy/paste into your own website or blog):
  2. Add this page to your favorite social bookmarks sites:
               
  3. Add this page to your Favorites

Oh, and thank you for supporting Quackit!