Introduction
This week we tackled XPath.
What is Xpath? This is a query language where, one can navigate through elements and attributes in an XML Document. It can also be used for computation of certain values, like Boolean. Xpath is based on a tree of a document and goes round that document searching for nodes. In other words it is choosing a path within multiple paths. To specify a path one can use:
/bookstock/book. This means that the root node is bookstock and it will go down to the next directory which in this case is book.
Quick Questions
Question 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.
- 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?
- Can you write the CSS file in such a way that it will display just the title, and the judgement?
- If the CSS file is called legalWrit.css, what processing instruction should you put in the prolog of the XML document(s)?
Answers:
1.a
CSS is used for applying style-sheets to pages for making them more visually attractive, like enhancing font size and colour. Using margins and positioning, can place certain orders but only to enhance the order in which they are visually viewed. In this case an XSL should be used to arrange the order of the document.
1.b
Yes one can hide certain parts of a document by using either:
display:none or display:hidden
1.c
One can do this by using the href. Href points to something you want to "add"
<?xml-stylesheet type="text/css" href ="legalWrit.css"?>
Question 2
What is the difference between URI and URL?
Answer
URI stands for Uniform Resource Identifier. This is used to identify a name or resource on the Internet and is made of a string of characters. This identification is used to interact with representations of a resource over a network using specific protocols.
What does a URI do? It describes how the resource is accessed where the computer is housed which contains the resource and the specific file name of the resource
While on the other hand URL stands for Uniform Resource Locator defines and specifies the location of a resource. It is a type of URI.
Question 3
Why does the XML language allow namespaces?
Answer:
When giving names to elements and attributes developers might use the same names by mistakes. In XML this can be fixed by using a sort of name prefix, this way conflicts in names are avoided. For example:
Question 3
Why does the XML language allow namespaces?
Answer:
When giving names to elements and attributes developers might use the same names by mistakes. In XML this can be fixed by using a sort of name prefix, this way conflicts in names are avoided. For example:
<s:school xmlns:s="http://linkgoeshere.com">
<s:name> STC </s:name>
</s:school>
<l:location xmlns:l = "http://linkgoeshere.com">
<s:name> STC </s:name>
</l:location>
Longer Questions:
Question 1
Now use the Mozilla Firefox browser to view the file memo1.xml. Answer 1:
Question 1.b
What was the point of putting “display: block” into the CSS file in each of the 6 lines?
Question 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. 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;}
Question 1.b
What was the point of putting “display: block” into the CSS file in each of the 6 lines?
Answer 1.b
This is a CSS styling which allows you to define how you are going to display your HTML. In this case block which will put one beneath another. This doesn't allow HTML elements next to it, except if the float element is declared.
There are other display methods like inline, none, list-item and inline-block.
Question 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
1. chapter
2. {
3. display:block;
4. font-family: Palatino, "Times New Roman", serif;
5. font-size:12px;
6. background-color:#FCFBC4;
7. padding-left: 1em;
8. }
9. chapterHead
10. {
11. display:block;
12. font-size:24px;
13. font-weight: bold;
14. font-style: italic;
15. color:blue;
16. }
17. poem
18. {
19. font-style: italic;
20. }
21. line
22. {
23. padding-left: 2em;
24. display:block;
25. }
Question 2.2
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.
Answer 2.2
Question 3
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.
Answer
The below is an arranged version of the XML document. Where some of the style was changed like; margins, colors, font-sizes, font-face, padding and other things to improve the look.
http://www.w3schools.com/xpath/
http://searchsoa.techtarget.com/definition/URI
http://www.quirksmode.org/css/display.html
No comments:
Post a Comment