![]() ![]() ![]() ![]() ![]() |
Top Contents Index Glossary |
Link Summary
|
External Links Glossary Terms |
This section contains no programming exercises. Instead, it discusses the options for referencing binary files like image files and multimedia data files.
There are two ways to go about referencing an unparsed entity like a binary
image file. One is to use the DTD's NOTATION
-specification
mechanism. However, that mechanism is a complex, unintuitive holdover that mostly
exists for compatibility with SGML documents.
We will have occasion to discuss it in a bit more depth when we look at the
DTDHandler API, but suffice
it for now to say that the combination of the recently defined XML namespaces
standard, in conjunction with the MIME
data types defined for electronic messaging attachments, together provide
a much more useful, understandable, and extensible mechanism for referencing
unparsed external entities.
Note: The XML described here is in
slideshow1b.dtd
. We won't actually be echoing any images. That's beyond the scope of this tutorial's Echo program. This section is simply for understanding how such references can be made. It assumes that the application which will be processing the XML data knows how to handle such references.
To set up the slideshow to use image files, add the text highlighted below
to your slideshow.dtd
file:
<!ELEMENT slide (image?, title, item*)> <!ATTLIST slide type (tech | exec | all) #IMPLIED > <!ELEMENT title (#PCDATA)> <!ELEMENT item (#PCDATA | item)* > <!ELEMENT image EMPTY> <!ATTLIST image alt CDATA #IMPLIED src CDATA #REQUIRED type CDATA "image/gif" >
These modifications declare image
as an optional element in a
slide
, define it as empty element, and define the attributes it
requires. The image
tag is patterned after the HTML 4.0 tag, img
,
with the addition of an image-type specifier, type
. (The img
tag is defined in the HTML
4.0 Specification.)
The image
tag's attributes are defined by the ATTLIST
entry. The alt
attribute, which defines alternate text to display
in case the image can't be found, accepts character data (CDATA
).
It has an "implied" value, which means that it is optional, and that
the program processing the data knows enough to substitute something like "Image
not found". On the other hand, the src
attribute, which names
the image to display, is required.
The type
attribute is intended for the specification of a MIME
data type, as defined
at ftp://ftp.isi.edu/in-notes/iana/assignments/media-types/
.
It has a default value: image/gif
.
Note: It is understood here that the character data (
CDATA
) used for the type attribute will be one of the MIME data types. The two most common formats are:image/gif
, andimage/jpeg
. Given that fact, it might be nice to specify an attribute list here, using something like:type ("image/gif", "image/jpeg")That won't work, however, because attribute lists are restricted to name tokens. The forward slash isn't part of the valid set of name-token characters, so this declaration fails. Besides that, creating an attribute list in the DTD would limit the valid MIME types to those defined today. Leaving it as
CDATA
leaves things more open ended, so that the declaration will continue to be valid as additional types are defined.
In the document, a reference to an image named "intro-pic" might look something like this:
<image src="image/intro-pic.gif", alt="Intro Pic", type="image/gif" />
Using a MIME data type as an attribute of an element is a mechanism that is
flexible and expandable. To create an external ENTITY
reference
using the notation mechanism, you need DTD NOTATION
elements for
jpeg and gif data. Those can of course be obtained from some central repository.
But then you need to define a different ENTITY
element for each
image you intend to reference! In other words, adding a new image to your document
always requires both a new entity definition in the DTD and a reference to it
in the document. Given the anticipated ubiquity of the HTML 4.0 specification,
the newer standard is to use the MIME data types and a declaration like image
,
which assumes the application knows how to process such elements.
![]() ![]() ![]() ![]() ![]() |
Top Contents Index Glossary |