session iii chapter 7 – entities and notation in dtd’s
TRANSCRIPT
CMP 051XML Introduction
Session III Chapter 7 – Entities and Notation in DTD’s
http://www.profburnett.com
Copyright © Carl M. Burnett 2
OutlineIntroductionGeneral EntitiesCreating Unparsed ContentEmbedding Unparsed ContentParameter Entities
8/1/2014
Copyright © Carl M. Burnett 3
IntroductionEntities are used to define shortcuts to special
characters.Entities can be two types: general and parameterGeneral entities can be declared internal or external,
parsed or unparsedParameters can be declared internal or external, but are
always parsed.
8/1/2014
Copyright © Carl M. Burnett 4
Creating & Using General Entities
8/1/2014
1. Type <!ENTITY2. Type ent_name where ent_name is name of the entity.3. Type “content” where content is the shortcut text.4. Type > to close out the entity definition.
<!ENTITY wow "Wonders of the World">
Creating General Entities
Using General Entities
1. Type in the XML document the “&”2. Type ent_name where ent_name is name of the entity. 3. Type a ; after the entity name.
<story> The first and most interesting fact about the gardens is that there is significant controversy about whether the gardens existed at all.<para/>
. . .
Regardless of the final outcome, it is interesting to note that the imagination of the poets and ancient historians have created one of the &wow;.
</story>
Copyright © Carl M. Burnett 5
Creating and Using External General Entities
8/1/2014
Creating External General Entities
Using External General Entities
1. Type <!ENTITY2. Type ent_name where ent_name is name of the entity.3. Type “SYSTEM ” to indicate the entity is external. 4. Type “entity.uri” where the entity.uri file is located.5. Type > to close out the entity definition.
<!ENTITY garden_story SYSTEM “garden.ent.>
entity.ent file
<story> The first and most interesting fact about the gardens is that there is significant controversy about whether the gardens existed at all.<para/>. . . ancient historians have created one of the &wow;.</story>
1. Add <standalone=“no” to the XML declaration.2. Type & in the XML document where the ent_name is to be used.3. Type ent_name where ent_name is name of the entity.4. Type ; to close out the entity definition.
<?xml version="1.0" standalone="no"?>. . . <history> <year_built era="BC">600</year_built> <year_destroyed era="BC">226</year_destroyed> <how_destroyed>earthquake</how_destroyed> &gardens_story;</history>
Copyright © Carl M. Burnett 6
Creating Unparsed Content
8/1/2014
1. In the DTD where you want to embed the content type <!NOTATION_n_name where n_name is the content.
2. Type SYSTEM. 3. Type “notation.instr” where notation.instr is the
URI for the unparsed content. 4. Type > to complete the notation.
<!ELEMENT ancient_wonders (wonder*)> <!ELEMENT wonder (name+, photo)> <!ELEMENT name (#PCDATA) ><!ATTLIST name language CDATA #REQUIRED>
<!NOTATION jpg SYSTEM "image/jpeg">
To Create a Notation
To define an entity for the unparsed content 1. After the notation declaration type, <!ENTITY2. Type ent_name where ent_name is the name for the
external entity3. Type SYSTEM. 4. Type “entity.uri” where entity.uri is the location of
the file.5. Type SNDATA n_name where n_name is the unparsed
content name. 6. Type > to complete the definition.
<!ELEMENT ancient_wonders (wonder*)> <!ELEMENT wonder (name+, photo)> <!ELEMENT name (#PCDATA) ><!ATTLIST name language CDATA #REQUIRED>
<!NOTATION jpg SYSTEM "image/jpeg">
<!ENTITY lighthouse_pic SYSTEM "lighthouse.jpg" NDATA jpg>
Copyright © Carl M. Burnett 7
Embedding Unparsed Content
8/1/2014
1. In the DTD first define and declare an element. 2. Type <!ATTLIST tag where tag is the element you defined. 3. Type att_name where att_name is the name of the attribute. 4. Type ENTITY or ENTITIES to reference that this is an
unparsed entity.5. Type > to complete the attribute definition.
To Declare the Attribute for the Unparsed Entity
To Embed an Unparsed Entity into a XML Document1. In the XML document that referes to the DTD add:
standalone=“no”2. In the body of the XML document within the attribute
declared with an ENTITY type,att_name=“ent_name” where att_name is the name of the unparsed entity declared.
<!ELEMENT ancient_wonders (wonder*)> <!ELEMENT wonder (name+, photo)> <!ELEMENT name (#PCDATA) ><!ATTLIST name language CDATA #REQUIRED><!NOTATION jpg SYSTEM "image/jpeg"><!ENTITY lighthouse_pic SYSTEM “lighthouse.jpg" NDATA jpg><!ELEMENT photo EMPTY><!ATTLIST photo source ENTITY #REQUIRED>
<?xml version="1.0" standalone="no"?>. . .<ancient_wonders> <wonder> <name language="English"> Lighthouse of Alexandria</name> <name language="Greek"> ὁ Φάρος τῆς Ἀλεξανδρείας</name> <photo source="lighthouse_pic"/> </wonder></ancient_wonders>
Copyright © Carl M. Burnett 8
Creating and Using Parameter Entities
8/1/2014
1. In the DTD type <!ENTITY to begin the definition. 2. Type % (space) to note that the entity is a parameter. 3. Type ent_name where ent_name is the name of the entity. 4. Type “content” where “content” is the shortcut text.5. Type > to complete the entity definition.
To Create a Parameter Entity
To Use a Parameter Entity
1. In the DTD type % to begin the definition. 2. Then Type ent_name where ent_name is the name of the
entity. 3. Finally type ; to close out the expression.
<!ENTITY % p "(#PCDATA)">
<!ELEMENT name %p;><!ATTLIST name
language CDATA #REQUIRED><!ELEMENT location %p;><!ELEMENT height %p;>. . .<!ELEMENT year_built %p;><!ATTLIST year_built
era (BC | AD) #REQUIRED><!ELEMENT year_destroyed %p;><!ATTLIST year_destroyed
era (BC | AD) #REQUIRED><!ELEMENT how_destroyed %p;>
Copyright © Carl M. Burnett 9
Creating an External Parameter Entity
8/1/2014
1. Create the entity’s content in an external text file and save it with the extension .ent.
To Create an External Parameter Entity
To Define an External Parameter Entity 1. In the DTD type <!ENTITY to begin the entity definition. 2. Then type % to indicate that this is for a parameter entity. 3. Type ent_name where ent_name is the name of the
entity. 4. Then type SYSTEM to indicate that the is defined externally. 5. Type “entity.uri” where “entity.uri” is the location of the
external file with the content. 6. Finally type > to close out the entity definition.
<!ELEMENT main_image EMPTY><!ATTLIST main_image file CDATA #REQUIRED w CDATA #REQUIRED h CDATA #REQUIRED>
pic.ent file
<!ENTITY % full_pic SYSTEM "pic.ent">
<!ENTITY % p "(#PCDATA)"><!ENTITY % full_pic SYSTEM "pic.ent">. . .<!ELEMENT story (#PCDATA | para)*><!ELEMENT para EMPTY>%full_pic;
<!ELEMENT source EMPTY><!ATTLIST source
sectionid CDATA #REQUIREDnewspaperid CDATA #REQUIRED>
Copyright © Carl M. Burnett 10
ReviewIntroductionGeneral EntitiesCreating Unparsed ContentEmbedding Unparsed ContentParameter Entities
8/1/2014
Next: Chapter 8 – Validation and Using DTDs