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 will first set the text to bold, and then will set it to normal. Ultimately, the result will be a text in normal font style since it is the last instruction to be executed.
2. 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?
Assuming that the XML document contains:
<book>
<text>The grand old Duke of York, he had 10000 men.</text>
</book>
This XPath statement would extract "10000" from the text:
substring(/book/text,36,5)
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 file:///H:/work/docs/chemElements2.xml into the address window under the menu bar. You will notice that a message " This XML file does not appear to have any style information associated with it. The document tree is shown below." appears at the top of the screen.
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
Adding this line will cause it to be viewed: <?xml-stylesheet type="text/css" href="stylesheet01.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.
chemElements2.xml can be found here. The following is the CSS file used to style it, followed by a picture showing the result.
chemElements{
display:table;
margin:20px;
font-family: Palatino, "Times New Roman", Serif;
font-size:12pt;
border:black thin solid;
}
tableHead{
display:table-row;
border:black thin solid;
}
element{
display:table-row;
border:black thin solid;
}
anumHead, nameHead, symbolHead, mptHead, bptHead{
display:table-cell;
padding:10px;
border:black thin solid;
text-align:center;
font-weight:bold;
color:White;
background-color:Black
}
anum{
display:table-cell;
padding:10px;
border:black thin solid;
text-align:left;
}
name{
display:table-cell;
padding:10px;
border:black thin solid;
font-weight:bold;
color:Maroon;
}
symbol{
display:table-cell;
padding:10px;
border:black thin solid;
font-weight:bold;
color:Green;
text-align:center;
}
mp, bp{
display:table-cell;
padding:10px;
border:black thin solid;
text-align:right;
}
2. 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.
//cd[contains(title,"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