Saturday, 17 December 2011

CMT3315 - Lab 07 - More DTD

Quick Questions

1. People who prepare XML documents sometimes put part of the document in a CDATA section.
a. Why would they do that?

Text inside the CDATA tag is used as a marker for the parser to tread the inner content as text. Special characters such as < or > which would otherwise "break" the validity of the XML document are treated as normal characters.

b. How is the CDATA section indicated?

This section may be specified as follows <![CDATA[" text goes here "]]>

c. If CDATA sections hadn’t been invented, would there be any other way to achieve the same effect?

Yes, special characters may be "escaped" such as the < character would be represented as &lt; the parser would then treat this as an actual "less-than" character and  not the open-tag character.

2. What is a parser and what does it have to do with validity?

3. You write a .dtd file to accompany a class of XML documents. You want one of the elements, with the tag <trinity>, to appear exactly three times within the document element of every document in this class. Is it possible for the .dtd file to specify this?

No DTD does not support this rule definition, you may specify either once, zero or once, zero or more & one or more. This rule may however be created in an XSD schema.



Longer Questions

1. The following is one of the documents that featured in last week’s exercises. As mentioned before, this is to be “Chapter 2: Volcanic winter” in a book.
a) Write a suitable prolog for this document.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE text SYSTEM "book.dtd">


b) Write a .dtd file to act as the Document Type Description for this document. Or modify the one you wrote last week, if you wrote one.

c) Put tags into the document. Obviously, there must be a document element. But also, the poem needs special treatment (because of the way it will be displayed) and, in fact, each line of the poem needs special treatment (you can spot the places where the lines start, by the capital letters). The mention of the poets at Geneva needs to be identified, because it will feature in the index, and so do the pyroclastic flows and Mount Tambora and Sumbawa and the year without a summer and the famines.

2. This chapter obviously needs some pictures. You have available the following, and you decide to include them in the chapter, at appropriate places:
a picture of Sumbawa, after the volcanic eruption. It’s in a file sumbawa.jpg. Caption: “Sumbawa, after the volcanic eruption”.
a picture of Lake Geneva, in 1816. It’s in a file Geneva1816.jpg. Caption: “Lake Geneva, during the summer of 1816”.
a picture of Mary Shelley. It’s in a file MaryShelley.jpg. Caption: “Mary Shelley, author of Frankenstein”.
Amend your two files so that they can cope with these pictures and captions.

DTD


<?xml version = "1.0" encoding="UTF-8"?>

<!NOTATION jpg PUBLIC "image/jpeg">
<!ENTITY Sumbawa SYSTEM "sumbawa.jpg" NDATA jpg>
<!ENTITY LakeGeneva SYSTEM "Geneva1816.jpg" NDATA jpg>
<!ENTITY MaryShelley SYSTEM "MaryShelley.jpg" NDATA jpg>

<!ELEMENT content (paragraph+,poem*)>
<!ELEMENT paragraph(img)
<!ELEMENT paragraph(#PCDATA)>
<!ELEMENT poem(line+)>
<!ELEMENT line(#PCDATA)
<!ELEMENT img EMPTY>
<!ATTLIST img src ENTITY #REQUIRED title CDATA #REQUIRED>


XML

<content>
<paragraph>
A volcanic winter is very bad news. The worst eruption in recorded history happened at <index>Mount Tambora</index> in 1815. It killed about 71 000 people locally, mainly because the <index>pyroclastic flows</index> killed everyone on the island of <index>Sumbawa</index> and the tsunamis drowned the neighbouring islands, but also because the ash blanketed many other islands and killed the vegetation. It also put about 160 cubic kilometres of dust and ash, and about 150 million tons of sulphuric acid mist, into the sky, which started a volcanic winter throughout the northern hemisphere.
<img src="sumbawa.jpg" title="Sumbawa, after the volcanic eruption">
</paragraph>
<paragraph>
The next year was the year without a summer. No spring, no summer – it stayed dark and cold all the year round. This had its upside. In due course, all that ash and mist in the upper atmosphere made for some lovely sunsets, and Turner was inspired to paint this. The Lakeland <index>poets</index> took a holiday at Lake Geneva, and the weather was so horrible that Lord Byron was inspired to write this. 
<img src="Geneva1816.jpg" title="Lake Geneva, during the summer of 1816">
</paragraph>
<poem>
<line>The bright sun was extinguish'd, and the stars Did wander darkling in the eternal space,</line>
<line>Rayless, and pathless, and the icy earth Swung blind and blackening in the moonless air;</line>
<line>Morn came and went – and came, and brought no day.</line>
</poem>
<paragraph>
Mary Shelley was inspired to write Frankenstein. The downside was that there were famines throughout Europe, India, China and North America, and perhaps 200 000 people died of starvation in Europe alone.
<img src="MaryShelley.jpg" title="Mary Shelley, author of Frankenstein">
</paragraph>
</content>

No comments:

Post a Comment