Saturday, 24 December 2011

CMT3315 - Lab 08 - CSS

Quick Questions

1. You have a set of legal documents. Each has four sections: the title, the case, the background, and the judgement, in that order. Each has been made into an XML document by inserting a prolog and suitable tags. You want to write a CSS file that will display these documents using a suitable browser.

a. Can you write the CSS file in such a way that it will display the title, then the judgement, then the background, then the case?

Yes, with CSS you can use absolute positioning to position the elements anywhere on or off screen.

b. Can you write the CSS file in such a way that it will display just the title, and the judgement?

Yes, the display property of the element to be hidden should be set to none.

c. If the CSS file is called legalWrit.css, what processing instruction should you put in the prolog of the XML document(s)?

<?xml-stylesheet type="text/css" href="legalWrit.css"?>

2. What is the difference between a URI and a URL?

A URI (Universal Resource Identifier) is a string of characters that defines the location of a resources on a network, a URL (Universal Resource Locator) is the locator that identifies the location of a network resource. URLs are a subset of URIs.


3. Why does the XML language allow namespaces?

As with most modern languages, name-spaces are used to prevent naming conflicts from occurring. E.g. what happens if you're using 2 schemas with the element name <date>, yet both schemas validate dates differently. By using name-spaces such as <ns1:date> or <ns2:date> one could clearly identify what validations should be used.


Longer questions

1. Here is a short XML document. Type it out, as a new file in JCreator. Save it under the name memo1.xml in a suitable directory in your file system. Notice that the JCreator editor picks out the different components in different colours, to aid you in detecting errors.
<?xml version="1.0"?>
<?xml-stylesheet href="stylesheet01.css" type="text/css"?>
<!DOCTYPE memo>
<memo>
<id>Message: 1334</id>
<date>18 November 09</date>
<time>09:30</time>
<from>From: The Managing Director</from>
<to>To: Heads of all Departments</to>
<message>We must increase production. And increasing sales would be no bad thing either.</message>
</memo>
Now open another tab in JCreator and type the following style sheet out. Save it under the name stylesheet01.css in the same folder as memo1.xml. Notice that, this time, the editor does not pick out the different components in different colours.
memo {display: block; margin: 1em;}
id {display: block; margin: 1em; font-style: italic; font-size:200%}
date {display: block; margin: 1em;color: "dark blue"; text-align: left;}
time {display: block; margin: 1em;color: aqua; text-align: left;}
from, to {display: block; margin: 1em;color: green; text-align: left;}
message {display: block; margin: 1em;color: blue; text-align: left;}

Now use the Mozilla Firefox browser to view the file memo1.xml.
What was the point of putting “display: block” into the CSS file in each of the 6 lines?

display:block ensures that all elements are rendered on separate lines (not next to each other), all elements have different default values for the display style attribute.

2. We want the chapter we were working on last week (“Chapter 2: Volcanic winter”) to be displayed on screen in a web browser. Here are some of the features we would like it to have: the font for the text to be Palatino, or failing that Times New Roman, or failing that any serif face. Type size to be 12 pt. The chapter heading to be the same font, but 24 pt and bold and italic and blue. The poem lines to be the same font, but italic. Background colour to be parchment: use the colour #FCFBC4. Both the chapter heading and the main text are to be indented from the left margin by 1 em. The lines of poetry are to be indented from the left margin by 2 ems.

Write a CSS file that will enable the chapter to be displayed in this way. Call it stylesheet4.css

content {font-family: Palatino, "Times New Roman", Sans-Serif;
         font-size: 12pt; 
         background-color: #FCFBC4; 
         margin-left: 1em;}
 
poem {font-style: italic;
      display:block;
      margin-left: 1em;}
 
line {display: block;}

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>

Saturday, 10 December 2011

CMT3315 - Lab 06 - XML Character Encoding

Quick questions:

1. What exactly does a DTD do in XML?

A Document Type Definition (DTD) specifies the schematic rules (structure) that must be followed, after the XML has been validated successfully to be syntactically correct, the XML document is validated against the rules defined in the DTD document.

2. You’ve written an XML document, with the XML declaration  <?xml version= “1.0”?> at the start. You realise that the text contains some arabic characters. Which of the following should you do:
     a) change the XML declaration to <?xml version= "1.0" encoding="ISO 8859-6"?>
     b) change the XML declaration to <?xml version= "1.0" encoding="UTF-8"?>
     c) do nothing: the declaration is fine as it is.

change the XML declaration to <?xml version= "1.0" encoding="ISO 8859-6"?>

3. Can you use a binary graphics file in an XML document?

Binary files such as images cannot be embedded directly inside the XML document, but path references may be used.


Longer Questions

1. The following is the document element (root element) of an XML document. 
     a) It’s clear that it’s concerned with English phrases and their Russian translations. One of the start tags is <targLangPhrase> with </targLangPhrase> as its end tag. Why do you suppose this isn’t <russianPhrase> with </russianPhrase> ?
     b) Write a suitable prolog for this document.
     c) Write a .dtd file to act as the Document Type Description for this document.
     d) The application that is to use this document runs on a Unix system, and was written some years ago. Is that likely to make any difference to the XML declaration?

Ref: answer in previous post http://cmt3315-danielvella.blogspot.com/2011/12/cmt3315-lab-05-well-formed-xml.html

2. I decide to produce a book called “Toba: the worst volcanic eruption of all”. I ask 3 colleagues to write three text files entitled:
“Chapter 1: The mystery of Lake Toba’s origins”. 
“Chapter 2: Volcanic winter”. 
“Chapter 3: What Toba did to the human race”. 
All three text files are placed into a folder c:\bookproject\chapters on the hard drive on my computer. I insert <text> at the start of each file, and </text> at the end. I name the three files chap1.xml, chap2.xml, and chap3.xml respectively. I draw up the title page, title page verso and contents page of the book like this:
Toba: the worst volcanic eruption of all

Toba: the worst volcanic eruption of all
John
Jack
Jill
Joe
STC Press
Malta
Copyright © 2010
STC Press
Published by STC Press Ltd., Malta
ISBN: 978-0-596-52722-0
Contents
Chapter 1: The mystery of Lake Toba’s origins
Chapter 2: Volcanic winter
Chapter 3: What Toba did to the human race

 Then I construct an XML document that encompasses the whole book. 
(a) Provide this XML document


<?xml version="1.0" ?>
<Book>
<TitlePage>
<Title>Toba: the worst volcanic eruption of all</Title>
<Authors>
<Author>John</Author>
<Author>Jack</Author>
<Author>Jill</Author>
<Author>Joe</Author>
<Authors>
<Publisher>STC Press Malta</Publisher>
</TitlePage>
<TitlePageVersio>
<Copyright>Copyright (c) 2010 STC Press</Copyright>
<Address>Published by STC Press Ltd. Malta</Address>
<Isbn>978-0-596-52722-0</Isbn>
</TitlePageVersio>
<Contents>
<Chapter ChapterNumber="1" ChapterTitle="The mystery of Lake Toba's Origins">
<Title>Chapter 1: The mystery of Lake Toba's Origins</Title>
</Chapter>
<Chapter ChapterNumber="2" ChapterTitle="Volcanic winter">
<Title>Chapter 2: Volcanic winter</Title>
</Chapter>
<Chapter ChapterNumber="3" ChapterTitle="What Toba did to the human race">
<Title>Chapter 3: What Toba did to the human race</Title>
</Chapter>
</Contents>
</Book>



(b) Provide the accompanying .dtd file



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

<!ENTITY chap1 SYSTEM "c:\bookproject\chapters\chap1.xml">
<!ENTITY chap2 SYSTEM "c:\bookproject\chapters\chap2.xml">
<!ENTITY chap3 SYSTEM "c:\bookproject\chapters\chap3.xml">

<!ELEMENT Book (TitlePage,TitlePageVerson,Contents)>
<!ELEMENT TitlePage(Title, Authors,Publisher)
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Authors(Author+)>
<!ELEMENT Author(#PCDATA)>
<!ELEMENT Publisher (#PCDATA)>
<!ELEMENT TitlePageVerso(Copyright, Address, Isbn)>
<!ELEMENT Copyright (#PCDATA)>
<!ELEMENT Address (#PCDATA)>
<!ELEMENT Isbn (#PCDATA)>
<!ELEMENT Contents (chapter+)>
<!ELEMENT chapter (title)>
<!ATTLIST chapter ChapterNumber #REQUIRED ChapterTitle>



Saturday, 3 December 2011

CMT3315 - Lab 05 - Well formed XML

Quick Questions


1. This is a smiley. Is it also a well-formed XML document? Say why. <:-/>

An XML document must always have one root element, the "slimy" is a valid root element which is also a closed element "/" at the end. According to the XML specifications element names may start with a ":" so therefore the above XML is well-formed.

2. What is the difference between well-formed and valid XML?

Well formed XML is XML that follows the general syntactical XML rules, valid XML is XML that apart from being well-formed can also be validated against a DTD or XSD schema successfully.

3. Is it a good idea to start an XML document with a comment, explaining what the document is and what it’s for? Say why.

It is considered good practice to comment XML documents to make it clearer for humans to understand the document structure and since they are ignored by XML parsers they have no effect when the document is machine processed. It is however not advisable to include comments before the document type declaration as this may be interpreted incorrectly.


Longer Questions


1. A set of documents is to be constructed as follows. The type of document is a college textbook. Every college textbook has a title page, on which is a title and an author and the publisher; optionally, there may be an aphorism.  Every college textbook has a title page verso, on which is a publisher’s address, a copyright notice, an ISBN; there may be a dedication, or there may be more than one. Every college textbook has several chapters, and each chapter has several sections, and each section has several bodies of text. A chapter is identified by a chapter number and a chapter title. A section is identified by a section number and a section title. The name of the publisher will always be Excellent Books Ltd. The address of the publisher will always be 21 Cemetry Lane, SE1 1AA, UK. The application that will process the documents can accept Unicode.
Write a .dtd file for this specification.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE textbooks
[
      <!ENTITY publisher_Name "Excellent Books Ltd.">
      <!ENTITY publisher_Address "21, Cemetery Lane, SE1 1AA, UK">

      <!ELEMENT text_book (title_Page, title_Page_Verso, chapter+)>
      <!ELEMENT title_Page (title, author, publisher, aphorism?)>
      <!ELEMENT title_Page_Verso (publisher_Address, copyright_Notice, ISBN, dedication*)>

      <!ELEMENT chapter (section+)>
      <!ELEMENT section (body_Text+)>

      <!ATTLIST chapter chapter_Number CDATA #REQUIRED chapter_Title CDATA #REQUIRED>
      <!ATTLIST section section_Number CDATA #REQUIRED section_Title CDATA #REQUIRED>

      <!ELEMENT title (#PCDATA)>
      <!ELEMENT author (#PCDATA)>
      <!ELEMENT publisher (#PCDATA)>
      <!ELEMENT aphorism (#PCDATA)>

      <!ELEMENT publisher_Address (#PCDATA)>
      <!ELEMENT copyright_Notice (#PCDATA)>
      <!ELEMENT ISBN (#PCDATA)>
      <!ELEMENT dedication (#PCDATA)>

      <!ELEMENT body_Text (#PCDATA)>
]>

2. Write an XML document that contains the following information: the name of a London tourist attraction. The name of the district it is in. The type of attraction it is (official building, art gallery, park etc). Whether it is in-doors or out-doors. The year it was built or founded [Feel free to make this up if you don’t know]. Choose appropriate tags. Use attributes for the type of attraction and in-doors or out-doors status.

<?xml version="1.0" ?>
<TouristAttractions>
     <TouristAttraction type="art gallery" venue="in-doors">
     <District>Central</District>
     <YearConstructed>1880</YearConstructed>
     <TouristAttraction>
</TouristAttractions>



3. The following is the document element (root element) of an XML document.
a) It’s clear that it’s concerned with English phrases and their Russian translations. One of the start tags is <targLangPhrase> with </targLangPhrase> as its end tag. Why do you suppose this isn’t <russianPhrase> with </russianPhrase> ?

By using the tag name <targLangPhrase> instead of <russianPhrase> the designers are keeping the XML generic, the same XML schema and subsequent application making use of this data may be reused for translations between any other two languages.


b) Write a suitable prolog for this document.


<?xml version = “1.0” encoding = “utf-8”?>
<!DOCTYPE phraseBook SYSTEM “phraseBook.dtd”>



c) Write a .dtd file to act as the Document Type Description for this document.


<?xml version="1.0" encoding="utf-8"?>
<!ELEMENT phraseBook (section+)>
<!ATTLIST phraseBook targLang CDATA #REQUIRED>
<!ELEMENT section (sectionTitle, phraseGroup+)>
<!ELEMENT sectionTitle (#PCDATA)>
<!ELEMENT phraseGroup (engPhrase, translitPhrase, targLangPhrase)>
<!ELEMENT engPhrase (#PCDATA|gloss)*>
<!ELEMENT translitPhrase (#PCDATA|gloss)*>
<!ELEMENT targLangPhrase (#PCDATA)>
<!ELEMENT gloss (#PCDATA)>



d) The application that is to use this document runs on a Unix system, and was written some years ago. Is that likely to make any difference to the XML declaration?

It is always advised to specify the character set when dealing with XML especially when dealing with language s other than English, this ensures all systems are able to interpret the content correctly.