QUICK QUESTIONS
People who prepare XML documents sometimes put part of the document in a CDATA section.
Why would they do that?
The text inside the XML document is parsed by the parser. However text inside the CDATA section will be ignored by the parser.[1] That is, the symbols '&' and '>' can be inserted inside the CDATA section.
How is the CDATA section indicated?
A CDATA section will start with " <![CDATA[ " and will end with " ]]> ".[1]
If CDATA sections hadn’t been invented, would there be any other way to achieve the same effect?
If CDATA sections hadn't been invented, one could insert '&' instead of '&' or 'gt;' instead of '>'. One can also put comments inside the XML document because, comments are also ignored by the parser.
What is a parser and what does it have to do with validity?
An XML parser converts the XML document into an XML Document Object Model (DOM).[2] If the XML document will not be valid, the parsing will not occur.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, one cannot specify this in a .dtd file. For the element to be shown:
- One or more times - (+);
- Zero or more times - (*);
- Zero or one time - (?).
LONGER QUESTIONS
The following (found in the question sheet) 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.
Write a suitable prolog for this document.
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.
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.
1: <?xml version="1.0" encoding="UTF-8"?> 2: <!DOCTYPE chapter2 SYSTEM "chapter2.dtd">1: <!DOCTYPE chapters[ 2: <!ELEMENT chapters (chapter+)> 3: <!ELEMENT chapter (text)> 4: <!ELEMENT text (paragraph+)> 5: <!ELEMENT paragraph (index*, poem?)> 6: <!ELEMENT index (#PCDATA)> 7: <!ELEMENT poem (line+)> 8: <!ELEMENT line (#PCDATA)> 9: <!ATTLIST chapter num CDATA #REQUIRED> 10: <!ATTLIST chapter title CDATA #REQUIRED> 11: ]>1: <?xml version="1.0" encoding="UTF-8"?> 2: <!DOCTYPE chapters SYSTEM "chapter2.dtd"> 3: <chapters> 4: <chapter num="2" title="Volcanic Winter"> 5: <text> 6: <paragraph> 7: 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. The next year was <index>the year without a summer</index>. 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 poets took a holiday at Lake <index>Geneva</index>, and the weather was so horrible that Lord Byron was inspired to write this. 8: </paragraph> 9: <paragraph> 10: <poem> 11: <line>The bright sun was extinguish'd, and the stars</line> 12: <line>Did wander darkling in the eternal space,</line> 13: <line>Rayless, and pathless, and the icy earth</line> 14: <line>Swung blind and blackening in the moonless air;</line> 15: <line>Morn came and went – and came, and brought no day.</line> 16: </poem> 17: </paragraph> 18: <paragraph> 19: Mary Shelley was inspired to write Frankenstein. The downside was that there were <index>famines</index> throughout Europe, India, China and North America, and perhaps 200 000 people died of starvation in Europe alone. 20: </paragraph> 21: </text> 22: </chapter> 23: </chapters>- 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".
The following is the XML file:1: <!DOCTYPE chapter2[ 2: <!ELEMENT chapters (chapter+)> 3: <!ELEMENT chapter (text)> 4: <!ELEMENT text (paragraph+)> 5: <!ELEMENT paragraph (index*, poem?, image*)> 6: <!ELEMENT index (#PCDATA)> 7: <!ELEMENT poem (line+)> 8: <!ELEMENT image EMPTY> 9: <!ELEMENT line (#PCDATA)> 10: <!ATTLIST chapter num CDATA #REQUIRED> 11: <!ATTLIST chapter title CDATA #REQUIRED> 12: <!ATTLIST image source CDATA #REQUIRED> 13: <!ATTLIST image caption CDATA #REQUIRED> 14: <!NOTATION jpg PUBLIC "image/jpeg"> 15: <!ENTITY sumbawa SYSTEM "sumbawa.jpg" NDATA jpg> 16: <!ENTITY geneva SYSTEM "sumbawa.jpg" NDATA jpg> 17: <!ENTITY maryShelley SYSTEM "sumbawa.jpg" NDATA jpg> 18: ]>
The following were added:1: <?xml version="1.0" encoding="UTF-8"?> 2: <!DOCTYPE chapter2 SYSTEM "chapter2.dtd"> 3: <chapters> 4: <chapter num="2" title="Volcanic Winter"> 5: <text> 6: <paragraph> 7: 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><image source="sumbawa" caption="Sumbawa, after the volcanic eruption"/> 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. The next year was <index>the year without a summer</index>. 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 poets took a holiday at Lake <index>Geneva</index><image source="geneva" caption="Lake Geneva, during the summer of 1816"/>, and the weather was so horrible that Lord Byron was inspired to write this. 8: </paragraph> 9: <paragraph> 10: <poem> 11: <line>The bright sun was extinguish'd, and the stars</line> 12: <line>Did wander darkling in the eternal space,</line> 13: <line>Rayless, and pathless, and the icy earth</line> 14: <line>Swung blind and blackening in the moonless air;</line> 15: <line>Morn came and went – and came, and brought no day.</line> 16: </poem> 17: </paragraph> 18: <paragraph> 19: Mary Shelley <image source="maryShelley" caption="Mary Shelley, author of Frankenstein"/>was inspired to write Frankenstein. The downside was that there were <index>famines</index> throughout Europe, India, China and North America, and perhaps 200 000 people died of starvation in Europe alone. 20: </paragraph> 21: </text> 22: </chapter> 23: </chapters>
<image source="sumbawa" caption="Sumbawa, after the volcanic eruption"/>
<image source="geneva" caption="Lake Geneva, during the summer of 1816"/>
<image source="maryShelley" caption="Mary Shelley, author of Frankenstein"/>
Question Sheet:
Question Sheet: Lab 7Sources:
[1] http://www.w3schools.com/xml/xml_cdata.asp[2] http://www.w3schools.com/xml/xml_parser.asp