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]/*

No comments:

Post a Comment