Sunday, 5 February 2012

Lab 10b

Quick questions:

  1. The following passage is to be found in the middle of a particular XML document:
The heavily-used<service xlink:type = "simple" xlink:href ="http://www.thetrams.co.uk/croydon"
> Croydon Tramlink </service> provides a cross link to nearby <location>Wimbledon</location>, <location>Addington</location> and <location>Beckenham</location>.
What can you say about how the text Croydon Tramlink will be treated by a browser such  as Mozilla Firefox?

The Mozilla Firefox browser would open a link to the resource http://www.thetrams.co.uk/croydon as the text will be considered as a hyper-link and the user will be directed to the website address.

  1. It’s possible to provide validation for a class of XML document using a Document Type Definition (.dtd) file, or using an XML schema. The DTD approach is easier. Why might you want to use the XML schema approach?

Although DTD use a different language from XML they are simpler and easier to use but they are limited in the validation they can do, like in the case that one cannot specify data types of elements in DTDs. XML schemas are written in XML code and offer more complex validation options which would not be possible with DTDs. Also XML Schemas have the ability to declare Data Types (such as integer, string or Date), are compatible with other XML Technologies and support namespaces.


Longer question:

Here is an XML document:

<?xml version="1.0" encoding="UTF-8"?>
<book isbn="0836217462">
 <title>
  Being a Dog Is a Full-Time Job
 </title>
 <author>Charles M. Schulz</author>
 <character>
  <name>Snoopy</name>
  <friend-of>Peppermint Patty</friend-of>
  <since>1950-10-04</since>
  <qualification>
    extroverted beagle
  </qualification>
 </character>
 <character>
  <name>Peppermint Patty</name>
  <since>1966-08-22</since>
  <qualification>bold, brash and tomboyish</qualification>
 </character>
</book>

An XML schema is to be constructed, which will validate this document and other similar documents. Make notes on the elements etc that this document contains, and record any significant factors about them.

Here is the XML Schema for the XML above:

<?xml version=”1.0” encoding=”UTF-8”?>
      <xs:element name = “book”>
           <xs:complexType>
              <xs:sequence>
                 <xs:element name="title" type="xs:string"/>
                 <xs:element name="author" type="xs:string"/>
                 <xs:element name="character" maxOccurs="unbounded">
                      <xs:complexType>
                          <xs:sequence>
                             <xs:element name="name" type="xs:string"/>
                             <xs:element name="friend-of" type="xs:string" minOccurs="0"/>
                             <xs:element name="since" type="xs:date"/>
                             <xs:element name="qualification" type="xs:string"/>
                           </xs:sequence>
                       </xs:complexType>
                   </xs:element>
                </xs:sequence>
                <xs:attribute name="isbn" type="xs:string" use="required"/>
             </xs:complexType>
         </xs:element>
     </xs:schema>

The Root Note is “Book” and since it has multiple elements it is a complex type. The Elements “title” and “author” are simple types and will contain a string. The element “character” is a complex type as it contains 4 elements (“name”, “friend-of”, “since” and “qualification”). The Elements “name”, “friend-of” and “qualification” are all simple types and contain a string. “Friend-of” can occur 0 or more times in the XMl document. “Since” is also a simple type but contains a date. “character” can also appear more than once in the XML as it has the property maxOccurs set at “unbounded”. The Attribute “ISBN” is required and is of type string. In “book” all the elements are in a sequence.

Monday, 30 January 2012

Lab 10a

Quick questions:

1.      One of the advantages claimed for the “extended links”, that the W3C consortium intended to be part of the XLink language, was that the definition of a particular hyperlink could be located, not in the local resource (the document where the link starts), or the remote resource (the document where the link ends), but in a quite different “third party” document. Why might this be an advantage?

With “Extended links” one can define multiple links, enabling to add resources from multiple locations.

  1. The XLink language provides an attribute for a hyperlink called show – it has several possible values. What is the effect of providing such a link with each of the following attribute values?
show=”replace”
show=”new”
show=”embed”

        Which of these three attribute values is the default?

           
show=”replace”: The current window or space will be replaced with the target source

show=”new”:   The target source will be opened in a new window or space

show=”embed”: The target source will be embedded in the current window or space.


The Default value is Replace as the by default the target source replaces the current window
  


Longer questions:
1.        Here is an XML document:
<?xml version="1.0"?>
<!DOCTYPE memo SYSTEM memo.dtd">
<?xml-stylesheet href="stylesheet02.css" type="text/css"?>
</memo>
  <heading>memo 1334</heading>
   <date>date: 11 November 09</date>
   <time>time: 09:30</time>
   <sender>from: The Managing Director</sender>
   <addressee>to: Heads of all Departments</addressee>
  <message>I think we should be making wind-turbines. Have a look at this website. Tell me what you think. </message>
</memo>

The accompanying .dtd file looks like this:
<?xml version= "1.0" ?>
<!DOCTYPE memo [
<!ELEMENT memo (heading, date, time, sender, addressee, message)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT time (#PCDATA)>
<!ELEMENT sender (#PCDATA)>
<!ELEMENT addressee (#PCDATA)>
<!ELEMENT message (#PCDATA)>
]>
At the point where the document says this website, there is supposed to be a hyperlink that takes the reader to the website:


a)        Amend the document, so that the link is in fact there. Make any necessary changes to the .dtd file as well.

XML:
<?xml version="1.0"?>
<!DOCTYPE memo SYSTEM memo.dtd">
<?xml-stylesheet href="stylesheet02.css" type="text/css"?>
</memo>
  <heading>memo 1334</heading>
   <date>date: 11 November 09</date>
   <time>time: 09:30</time>
   <sender>from: The Managing Director</sender>
   <addressee>to: Heads of all Departments</addressee>
   <message>I think we should be making wind-turbines. Have a look at        <link xlink:type="simple"xlink:href="http://engineering.suite101.com/article.cfm/wind_power">
        this website. </link>
    Tell me what you think. </message>
</memo>

  DTD: 
       <?xml version= "1.0" ?>
<!DOCTYPE memo [
<!ELEMENT memo (heading, date, time, sender, addressee, message)>
<!ATTLIST memo xmlns:xlink CDATA #REQUIRED>
 <!ELEMENT heading (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT time (#PCDATA)>
<!ELEMENT sender (#PCDATA)>
<!ELEMENT addressee (#PCDATA)>
<!ELEMENT message (#PCDATA)>
<!ELEMENT  link (#PCDATA)>
<!ATTLIST link
xlink:href CDATA #REQUIRED
xlink:type (simple | extended) "simple">
]>
  
b)            Suppose that the heading of one of the sections in the target website is <A NAME=“WE Elec Facts”>Wind Energy Electricity Facts</A>, including the tags as shown. What changes would you have to make to the link in the managing director’s memo, to make the hyperlink finish at that point rather than at the wind_power document as a whole?
  
By using a “#” after the link, the XLink will link to the specific part of the document. So the XLink will look like:

<mylink xlink:type="simple" link:href="http://engineering.suite101.com/article.cfm/wind_power#WE Elec Facts"xlink:show="new">website</mylink>


 2.         Here is another XML document:
<?xml version="1.0"?>
<!DOCTYPE memo SYSTEM memo.dtd">
<?xml-stylesheet href="stylesheet02.css" type="text/css"?>
</memo>
  <heading>memo 1335</heading>
   <date>date: 11 November 09</date>
   <time>time: 09:45</time>
   <sender>from: The Managing Director</sender>
   <addressee>to: Heads of all Departments</addressee>
  <message>I think we should be making solar panels. Have a look at this website. Tell me what you think. </message>
</memo>

At the point where the document says this website, there is supposed to be a hyperlink that takes the reader to a suitable website. Find one, and amend the document, so that the link is in fact there. Is it necessary to make any changes to the .dtd file, or can we use the file as you amended it before?

<?xml version="1.0"?>
<!DOCTYPE memo SYSTEM memo.dtd">
<?xml-stylesheet href="stylesheet02.css" type="text/css"?>
</memo>
  <heading>memo 1335</heading>
   <date>date: 11 November 09</date>
   <time>time: 09:45</time>
   <sender>from: The Managing Director</sender>
   <addressee>to: Heads of all Departments</addressee>
  <message>I think we should be making solar panels. Have a look at
<link xlink:type=”simple” xlink:href=”http://www.solarenergy.org/” xlink:show=”new”>this website.</link>
 Tell me what you think. </message>
</memo>

 No changes are needed in the DTD file as it still matches the structure of   the XML and only its values have been changed.

Tuesday, 24 January 2012

Lab 9

Quick question:

  1. Suppose that a CSS file is used to determine how an XML document will appear when viewed in a browser. Suppose that the CSS file contains two rules, one dictating that a particular piece of text will appear in bold type, the other dictating that it will not. What will happen?

CSS works using the overwriting method, meaning that the last rule which is declared is used to display the text in this case not bold.


  1. An XML document contains the sentence “The grand old Duke of York, he had 10000 men.” Would XPath be able to extract the piece of data “10000” from such a document?

With XPath one will not be able to get the 10000 part as a number, but it could extract the “10000” as a substring of the whole “grand old Duke of York, he had 10000 men.” By telling it to start from the character “1” and get 5 characters.



Longer question:



  1. Download the following file from the OasisPlus CMT3315 web page for Unit 10 Learning Materials:
chemElements2.xml
Download it to H:/work/docs (or somewhere else in your account that you consider more suitable).
View the file using Mozilla Firefox, by inserting into the address window under the menu bar. You will notice that a message


file:///H:/work/docs/chemElements2.xml


This XML file does not appear to have any style information associated with it.
The document tree is shown below.


However, the file is supposed to be displayed as a table, with five columns. The top row of the table is supposed to be headings for the 5 columns: this row is supposed to have a distinctive background colour. The next 99 rows are supposed to show details of 99 of the chemical elements – these rows are also supposed to have a distinctive background colour, different from the heading.

a)    Open JCreator and open the chemElements2.xml file in it. Add a line to the document that will cause it to be viewed (in the browser) in conjunction with a CSS file called stylesheet01.css

<?xml-stylesheet href=”stylesheet01.css” type=”text/css”?>

b)      Write the file, stylesheet01.css, and store it in the same folder. The content of this CSS file should cause the table to appear in the Mozilla Firefox browser, as described above. Make your own decisions about suitable typefaces, borders, background colours, alignment, etc.

chemElements {display:table; border: thin solid black;}
tableHead {display:table-row;}
tableHead *{display:table-cell; padding: 1px; border: thin solid black; background-color: #00FFFF;}
element {display:table-row; background-color: #C0C0C0;}
element *{display:table-cell; padding: 1px; border: thin solid black; }


  1. Consider the following XML document:

<?xml version= "1.0" ?>
<!DOCTYPE book SYSTEM "musicList.dtd">
<?xml-stylesheet href="stylesheet04.css" type="text/css"?>
<musicList
number="2" title="miscellaneous CDs"
xmlns:cdlist=http://middlesex_press.co.uk/CDcollection ”>

<cd number=”711”>
<title>The Best of Ivor Cutler</title >
<artist>Ivor Cutler</artist >
<tracks total=”19”/>
<cdlist:refnum> POL767 </ cdlist:refnum >
</cd>
<cd number=”712”>
<title>Penderecki’s First Symphony</title >
<artist>Middlesex Symphony Orchestra</artist >
<tracks total=”5”/>
<cdlist:refnum> DGM987 </ cdlist:refnum >
</cd>
<cd number=”713”>
<title>Penderecki’s Last Symphony</title >
<artist>Middlesex Symphony Orchestra</artist >
<cdlist:refnum> DGM988 </ cdlist:refnum >
<tracks total=”5”/>
</cd>
<cd number=”714”>
<title>Boris the Spider Rides Again</title >
<artist>The Renegades</artist >
<cdlist:refnum> CHR328 </ cdlist:refnum >
<tracks total=”19”/>
</cd>
</musicList>

Provide XPath expressions which will do the following:

a)        Select all the elements subordinate to the root node.
/musicList/*

b)        Select all track elements that have a total attribute with the value of 5.
//tracks[@total=5]

c)        Select all elements that contain the word “Penderecki” in their title.
/title[contains(.,”Penderecki”)]

d)       Select any elements that have titles with greater than 11 characters.
      //title[string-length()>11]

e)        Select all the siblings of the first cd element.
       //cd[1]/*

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: