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">
  <!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
  <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.

External Parameter Entities

External parameter entities are just like internal parameter entities except that they retrieve the replacement text from external files.

Declaring an external parameter entity

The syntax for declaring an external parameter entity is similar to the declarations for internal parameter entities, except that the SYSTEM keyword or the PUBLIC keyword is used. The syntax for the declaration is shown here:

<!ENTITY % name SYSTEM  "string_of_characters">

To use the external parameter entity, you could place all of the parameter entities that were defined in the example DTD in a file named Parameter.dtd. To do so, you would add the following code to the XML document:

  <!ENTITY % parameterentities SYSTEM "Parameter.dtd">
  <!--================ Document Structure=========================-->
  <!ELEMENT html  (head , body)>
  <!ATTLIST html  %i18n;
                  xmlns CDATA #FIXED 'http://www.w3.org/1999/xhtml'>
  <!--Rest of DTD here-->

First we declare the parameterentities entity, which links to the external Parameter.dtd, and then we use parameterentities to insert this document into the XML document. This external parameter entity could be used to create several DTDs. External parameter entities are useful when parts of your DTD will be used by several other DTDs.

by BrainBellupdated