XML

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.

by BrainBellupdated
Advertisement: