[Previous] [Contents] [Next]

External Unparsed General Entities


External unparsed general entities are similar to other entities, except that the XML parser will not try to parse the information within them. Essentially, the data within an external unparsed general entity is ignored by the XML parser and passed on to the application that is using the document in its original format. This is exactly what we want done for non-XML files such as images.

Notations

External unparsed general entities contain one additional component: notations. Notations are used by the application to identify the data in the external unparsed general entity or to identify what application needs to be used to interpret the data. For example, if the data contained in the entity is a GIF image file, the following notation would identify it:


  <!NOTATION GIF89a SYSTEM
      "-//Compuserve//NOTATION Graphic Interchange Format 89a//EN">

It would be up to the application to determine how to interpret this information and present the image properly.

Notations can be declared in two different ways. The first method is used when the notation is not public and is located at some URI. It uses the syntax shown here:


<!NOTATION notation_name SYSTEM resource_URI>

The second method is used for a notation that has been registered as public and given a unique ID. It uses the following syntax:


<!NOTATION notation_name PUBLIC public_ID resource_URI>

Examples of the two types of declarations are shown here:


  <!NOTATION GIF89a SYSTEM
      "-//Compuserver//NOTATION Graphic Interchange Format 89a//EN">
  <!NOTATION GIF SYSTEM "GIF">
  <!NOTATION BMP SYSTEM "MSPAINT.EXE">
  <!NOTATION GIF89a PUBLIC "-//Compuserve//NOTATION Graphic
      Interchange Format 89a//EN" "ps4prp.exe">

Declaring an external unparsed general entity

Once you have created a notation, you can use the notation to declare external unparsed general entities. The format for these declarations is similar to the declarations for external parsed general entities, except that in this case a notation appears at the end of the declaration. The NDATA keyword is used to associate the external unparsed general entity with a particular notation. The syntax for the declaration is shown here:


<!ENTITY entity_name SYSTEM URI NDATA  notation_name>

Using our second notation definition, you could create the following declaration:


  <!ENTITY image.topnav SYSTEM "topnav.gif" NDATA GIF>

Now that you have defined the notation and then defined an external unparsed general entity that uses this notation, you will want to use this external unparsed general entity in your XML document body. For example, you might want to insert this GIF image at the top of a Web page.

Using external unparsed general entities

When you are using an external unparsed general entity as a value for an attribute in your XML document, you will want the XML parser to ignore the data returned by the entity. To accomplish this, you must tell the XML parser that you are referencing an external unparsed general entity in the declaration of the attribute. The ENTITY or ENTITIES keyword will be used in the attribute declaration to mark an attribute as containing an external unparsed general entity reference, as shown here:


  <!--Part of the DTD-->
  <!NOTATION gif SYSTEM "gif">
  <!NOTATION jpeg SYSTEM "jpg">
  <!NOTATION bmp SYSTEM "bmp">
  <!ENTITY image.topimage SYSTEM "topimage.gif" NDATA gif>
  <!ENTITY image.topnav1 SYSTEM "topnav1.gif" NDATA gif>
  <!ENTITY image.topnav2 SYSTEM "topnav2.gif" NDATA gif>
  <!ENTITY Welcome SYSTEM "Welcome.jpg" NDATA jpg>
  <!ELEMENT topimages EMPTY>
  <!ATTLIST topimages
      topimage ENTITY #FIXED "image.topimage"
      topnav ENTITIES "image.topnav1 image.topnav2">
  <!ELEMENT img EMPTY>
  <!ATTLIST img  %attrs;
                align  CDATA  #IMPLIED
                border CDATA  #IMPLIED
                width  CDATA  #IMPLIED
                height CDATA  #IMPLIED
                hspace CDATA  #IMPLIED
                vspace CDATA  #IMPLIED
                src    ENTITY #REQUIRED
                type   NOTATION (gif|jpg|bmp) "jpg">
  <!--XML Body-->
  <topimages topimage="image.topimage" topnav="image.topnav1
      image.topnav2"></topimages>
  <img src = "Welcome"></img>

This code declares two elements: topimages and img. The topimages element has two attributes associated with it: topimage and topnav. The img element is the one used in the DTD example discussed in the "Rewriting the sample DTD using parameter entities" section, except that here it contains the type attribute. The type attribute is a notation attribute, as it contains the keyword NOTATION. The items listed in the enumerated type must be defined in the DTD as notations, as is done in the above declaration.

[Previous] [Contents] [Next]