Tuesday, 17 January 2012

Lab 8

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?

CSS is used to make pages more visually attractive by applying style-sheets. Using methods such as margins and positioning, the output could become ordered but usually an XSL is used with appropriate transformation

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

The other components will only need to have “display:none” added to them to make them rendered invisible

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 tyep=”text/css” href=”legalWrit.css”?>


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

URI (Uniform Resource Identifier) is used to identify a resource on the internet by its name, location or both.It is mostly used to define a location to a resource.

URL (Uniform Resource Locator) is a type of URI. It defines the network location of a specific resource. Unlike a URN, the URL defines how the resource can be obtained


3. Why does the XML language allow namespaces?


Namespaces help to distinguish and help avoid ambiguity between elements which have the same name but have different purposes. For example name can be used both for a person and for a place. Adding a Namespace before using name will make sure which name is being referred to.



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 wxould 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” was used to have the elements separated as “paragraphs” making use of white space above and below the element. Also “Display: block” does not allow other HTML elements next to it except when the float element is declared.

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.

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

chapter
{
font-family: Palatino, "Times New Roman", sans-serif;
font-size: 12pt; background-color: #ffffff;
color: #000000; margin-left: 1em;
text-align: justify; width:100%;
}

chapterHead
{
font-family: Palatino, "Times New Roman", sans-serif;
font-weight: bold; font-style: italic;
font-size: 24pt; color: #0000ff;
display: block; padding-bottom: 10px;
text-align: left; width:100%;
}

poem
{
font-family: Palatino, "Times New Roman", sans-serif;
font-style: italic; background-color: #FCFBC4;
width:100%;
padding-bottom:10px; padding-top:10px;
margin-bottom:10px; margin-top:10px;
}

line
{
margin-left: 2em; display: block; padding:0px;
}

Note 1: The XML document version of “Chapter 2: Volcanic winter”:
<?xml version= "1.0" ?>
<!DOCTYPE book SYSTEM "tobaChap.dtd">
<?xml-stylesheet href="stylesheet4.css" type="text/css"?>
<chapter number="2" title="Volcanic winter"><chapterHead>Chapter 2: Volcanic winter</chapterHead> A volcanic winter is very bad news. The worst eruption in recorded history happened at <indexRef>Mount Tambora</indexRef>  in 1815. It killed about 71,000 people locally, mainly because the <indexRef>pyroclastic flows</indexRef>  killed everyone on the island of <indexRef>Sumbawa</indexRef>  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 <indexRef>the year without a summer</indexRef>. 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 <indexRef>Lakeland poets</indexRef> took a holiday at Lake Geneva, and the weather was so horrible that Lord Byron was inspired to write this. <poem><line>The bright sun was extinguish'd, and the stars<line></line>Did wander darkling in the eternal space, <line></line>Rayless, and pathless, and the icy Earth<line></line>Swung blind and blackening in the moonless air; <line></line>Morn came and went and came, and brought no day. </line></poem>
Mary Shelley was inspired to write Frankenstein. The downside was that there were <indexRef>famines</indexRef> throughout Europe, India, China and North America, and perhaps 200,000 people died of starvation in Europe alone. </chapter>

b)      Type some – not all – of the XML document version of “Chapter 2: Volcanic winter” into a suitable file. Store it in the same folder as the stylesheet4.css document you have just written. View the file, using the Mozilla Firefox browser. See whether it looks as it should. If not, change the CSS file and view it again. Repeat this until you have it right.


c)   Right a different CSS file, with different display properties, and adjust your XML file so that it is displayed using this one instead. Use display properties that seem appropriate to you.

chapter
{
font-family: Arial, sans-serif;
font-size: 10pt; background-color: #ADD8E6;
color: #000000; margin-left: 1em;
text-align: left; width:100%;
}

chapterHead
{
font-family: Palatino, "Times New Roman", sans-serif;
font-weight: bold;
font-size: 20pt; color: #0000ff;
display: block; padding-bottom: 10px;
text-align: right; width:100%;
}

poem
{
font-family: Palatino, "Times New Roman", sans-serif;
background-color: #C0C0C0;
width:100%;
padding-bottom:10px; padding-top:10px;
margin-bottom:10px; margin-top:10px;
}

line
{
margin-left: 2em; display: block; padding:0px;
}

This CSS resulted in the XML being shown like:

No comments:

Post a Comment