Sunday, December 19, 2010

Week9 (2)

Second Task
1) "X" in XML stands for extensible (b). The "X" is significant because is means that XML can have user defined tags and is NOT predefined like HTML. It has a set of rules which define the meta-language but which allows it to evolve.

2) A markup language is a system of embedded codes to make an electronic document display on a web page as required (c). It defines the presentation and structure (and meaning) of the document in which it is. An example would be the html <h1> or <b> tags which define the size and boldness of the text following them.


3) SGML stands for Standard Generalized Markup Language (b). SGML prescribes a standard format for embedding descriptive markup within a document first used so that standards could be established for computers carrying out mark-up. SGML also specifies a standard method for describing the structure of a document. SGML proved unwieldy and too large so a subset of this, HTML was used for the mark-up commonly seen on the web today.

4) The relationship between SGML & XML can be said to be "XML is a slimmed-down, streamlined version of SGML" (d). XML is a simple subset of SGML designed for ease and interoperability with SGML and HTML. SGML is an ISO standard published in 1986 while XML was developed by the W3C in 1996.

Friday, December 17, 2010

Week9

This week's lesson was on XLinks & XPointers which are a richer form of hyperlinks with more properties (attributes) and can be bidirectional. Ordinary tags can point to another document (or within the same document) by using the 'name' anchor in the destination as follows:

the source link; <A href="www.....com/page1.html # location1">click</A>
the destination link; <A name="location1">destination text</A>

The above are 'simple links' but XML allows also 'extended' links which provide much more functionality.
  • outbound links have a local starting resource and a remote ending resource
  • inbound links have a remote starting resource and a local ending resource
  • third-party if starting and ending resource are both remote
Extended links;
  • can be bi-directional
  • may connect more than 2 documents
  • the specification of the link may be in either of the 2 documents or in another one
Some important atributes of extended links;
  • type: simple, extended, arc, locator
  • href: URL
  • label: identifier
  • to: destination location
  • from: source location
  • show: replace, new, embed
  • actuate: onRequest, onLoad
  • role: points to a description URL
  • title: a description

revised xml & css with these;
xml file:
<?xml version="1.0" ?>
<?xml-stylesheet href="t3.css" type="text/css"?>
<!--<!DOCTYPE legalDoc>-->
<legalDoc>
 <title>my title</title>
 <case>my case</case>
 <background>my background</background>
 <judjement>my judjement</judjement>
</legalDoc>

css file:
case {
color: #FF0000;
}
judjement {
color: #0000FF;
}


CMT3315  –  Lab Session 09

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?
       The latter rule (NOT bold) will be executed
  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?
       I think NO?


Longer question:
Provide XPath expressions which will do the following:
a)        Select all the elements subordinate to the root node.
//*
b)        Select all track elements that have a total attribute with the value of 5.
//track/[@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.
//CD[string-length(title())>5]
e)        Select all the siblings of the first cd element.
//CD[1]/following-sibling::*

Saturday, December 4, 2010

Week8

Today we discussed XPath which is used to model/describe (and query) xml documents. We also discussed Onthology (ES Expert Systems) and how it is shown in a triangel with KB (Knowledge Base), IR (Inference Rules), WM (Working Memory) and ;
> Concept (class)
> Slots (Roles & Properties)
> Facts (Property Restrictions-cardinality,domain,range..)
>Instances of classes

At home I revised XPath and its 7 node types;
root,
element,
attribute,
text,
namespace,
processing-instruction,
comment


CMT3315  –  Lab Session 08 

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.
    1. 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?
HTML file
<html>

  <head>
    <link rel="stylesheet" type="text/css" href="./t1.css" />
  </head>

  <body>
  
   <p class="p1">
      <atitle>my title</atitle>
   </p>
  
   <p class="p2">
      <acase>my case</acase>
   </p>
  
   <p class="p3">
      <abackground>my background</abackground>
   </p>
  
   <p class="p4">
      <ajudjement>my judjement</ajudjement>
   </p>
  
  </body>

</html>

CSS file
  .p1
  {
  position:absolute;
  top:10px;
  }

  .p4
  {
  position:absolute;
  top:40px;
  }

  .p3
  {
  position:absolute;
  top:70px;
  }

  .p2
  {
  position:absolute;
  top:100px;
  }


    1. Can you write the CSS file in such a way that it will display just the title, and the judgement?
  .p2
  {
  display:none;
  }

  .p3
  {
  display:none;
  }


    1. If the CSS file is called legalWrit.css, what processing instruction should you put in the prolog of the XML document(s)?
<?xml-stylesheet href="legalWrit.css" type="text/css"?>


  1. What is the difference between a URI and a URL?
A URI represents a name or identifier possibly with namespace etc. which may or may not really point to a real resource, while a URL identifies an actual resource location or path.


  1. Why does the XML language allow namespaces?
To identify tags that have the same name within an XML file but which refer to a different item of data example an xml file with students and tutors the tag “ID” could reference both a student or a tutor so we can use student:ID and tutor:ID to distinguish between the two.



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 would 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.
XML
<?xml version="1.0"?>
<?xml-stylesheet href="tt2.css" type="text/css"?>

<!-- this breaks it on IE8 -->
<!--<!DOCTYPE memo>-->

<html>
  <head>
  </head>

  <body>
    <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 would be no bad thing either.</message>
    </memo>
  </body>
</html>

CSS
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;}

What was the point of putting “display: block” into the CSS file in each of the 6 lines?
To format the way that each data item is displayed.



Wednesday, November 17, 2010

Week7

First part of lesson was about thesis writing - some really useful suggestions and guidelines. Discussed basic formatting/structure, standards and other rules and academic ways + some handy tips, DOs and DONTs.

Then we discussed CSS and how this is used to style HTML and even XML documents. CSS provides properties for text style, fonts, color/background, border and display. We also briefly dicussed AJAX and its use.


CMT3315  –  Lab Session 07
Quick questions:
1.    People who prepare XML documents sometimes put part of the document in a CDATA section.
    1. Why would they do that?
So that it is  ignored and NOT parsed

    1. How is the CDATA section indicated?
<![CDATA[ anything can be placed here ]]>

    1. If CDATA sections hadn’t been invented, would there be any other way to achieve the same effect?
Use the &lt; &gt; &apos; &quot; &amp for special characters in a normal PCDATA tag

2. What is a parser and what does it have to do with validity?
A parser is a computer program that extracts (parses) and displays the content within the tags of an xml file. It does so while validating the content by comparing the structure and types to a DTD documant.

3. You write a .dtd file to accompany a class of XML documents. You want one of the elements, with the tag <trinity>, to appear exactly three times within the document element of every document in this class. Is it possible for the .dtd file to specify this?
No

Longer questions:
1.        The following is one of the documents that featured in last week’s exercises. As mentioned before, this is to be “Chapter 2: Volcanic winter” in a book.
a)      Write a suitable prolog for this document.
<?xml version="1.0" encoding="UTF-16"?>
 <!DOCTYPE Chapter2
[

b)      Write a .dtd file to act as the Document Type Description for this document. Or modify the one you wrote last week, if you wrote one.
           see ans. 2b of Lab Session 06

c)      Put tags into the document. Obviously, there must be a document element. But also, the poem needs special treatment (because of the way it will be displayed) and, in fact, each line of the poem needs special treatment (you can spot the places where the lines start, by the capital letters). The mention of the poets at Geneva needs to be identified, because it will feature in the index, and so do the pyroclastic flows and Mount Tambora and Sumbawa and the year without a summer and the famines.


2. This chapter obviously needs some pictures. You have available the following, and you decide to include them in the chapter, at appropriate places:
-       a picture of Sumbawa, after the volcanic eruption. It’s in a file sumbawa.jpg. Caption: “Sumbawa, after the volcanic eruption”.
-       a picture of Lake Geneva, in 1816. It’s in a file Geneva1816.jpg. Caption: “Lake Geneva, during the summer of 1816”.
-       a picture of Mary Shelley. It’s in a file MaryShelley.jpg. Caption: “Mary Shelley, author of Frankenstein”.
Amend your two files so that they can cope with these pictures and captions.

Week6 (2)

Read part book called "Fuzzy Thinking: The New Science of Fuzzy Logic" by Bart Kosko.

Research on maths behind Fuzzy Logic (simultanoues equations etc) - very interesting but sometimes a bit toooo deep.

Thursday, November 11, 2010

Week6

This week's lesson was quite interesting. First we saw some videos on semantic web and intelligent objects that communicate with each other. Of particular interest was a device which you wear on your chest and which projects images and information about the objects in front of it. It is still being developed in a university.

Then we discussed namespaces in xml. We saw the importance of identifying conflicting or duplicate elements' names by prefixing them with a declared namespace. An example would be;

<tr:book
  xmlns:tr="http://URI 1..."
  xmlns:cust="http://URI 2...">

<tr:title>The Great Book</tr:title>
<cust:title>Mr</cust:title>
</tr:book>


CMT3315  –  Lab Session 06

Quick questions:

1.    What exactly does a DTD do in XML?
A DTD serves as a template for the elements, structure, optionality, cardinality and types in the XML file. It serves to validate the xml data.

2. You’ve written an XML document, with the XML declaration  <?xml version= “1.0”?> at the start. You realise that the text contains some arabic characters. Which of the following should you do:
a)        change the XML declaration to <?xml version= “1.0” encoding=”ISO 8859-6”?>
b)        change the XML declaration to <?xml version= “1.0” encoding=”UTF-8”?>
c)        do nothing: the declaration is fine as it is.
 c is correct since this already supports some arabic characters

3. Can you use a binary graphics file in an XML document?
 No not directly. But you can specify a link to it



Longer questions:

1.        The following is the document element (root element) of an XML document.
a)      It’s clear that it’s concerned with English phrases and their Russian translations. One of the start tags is <targLangPhrase> with </targLangPhrase> as its end tag. Why do you suppose this isn’t <russianPhrase> with </russianPhrase> ?
Refer to ans. 3a of Lab Session 05

b)      Write a suitable prolog for this document.
<?xml version="1.0" encoding="UTF-16"?>
 <!DOCTYPE textbook (see also ans. 3b of Lab Session 05)

c)      Write a .dtd file to act as the Document Type Description for this document.
see ans. 3c of Lab Session 05

d)      The application that is to use this document runs on a Unix system, and was written some years ago. Is that likely to make any difference to the XML declaration?
     see ans. 3d of Lab Session 05


2)
(a)    Provide this XML document
<?xml version="1.0" encoding="UTF-16"?>
<book name="Toba - the worst volcanic eruption of all.">

 <authors>
  <author>John</author>
  <author>Jack</author>
  <author>Jill</author>
  <author>Joe</author>
 </authors>
 <by>STC Press Malta</by>
 <copyright>Copyright © 2010 STC Press</copyright>
 <published>Published by STC Press Ltd., Malta</published>
 <ISBN>978-0-596-52722-0</ISBN>
 <contents>
  <section no="1">The mystery of Lake Toba's origins</chapter>
  <section no="2">Volcanic winter</chapter>
  <section no="3">What Toba did to the human race</chapter>
 </contents>
 <body>
  <chapter no="1">C:\bookproject\chapters\chap1.xml</chapter>
  <chapter no="2">C:\bookproject\chapters\chap2.xml</chapter>  <chapter no="3">C:\bookproject\chapters\chap3.xml</chapter>
 </body

</book>

(b)   Provide the accompanying .dtd file
<?xml version="1.0" encoding="UTF-16"?><!DOCTYPE books
[
<!ELEMENT book (authors,by,copyright,published,ISBN,contents,body)


<!ELEMENT authors (author+)
<!ELEMENT author (#PCDATA)>
<!ELEMENT by (#PCDATA)>
<!ELEMENT copyright (#PCDATA)>
<!ELEMENT published (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>

<!ELEMENT contents (section+)>
<!ELEMENT section (#PCDATA)>


<!ELEMENT body (chapter+)>
<!ELEMENT chapter (#PCDATA)>


<!ATTLIST book  name CDATA #REQUIRED>
<!ATTLIST section  no CDATA #REQUIRED>
<!ATTLIST chapter  no CDATA #REQUIRED>
]>

Saturday, November 6, 2010

Week5

This week's lesson was about character encoding. We saw examples of different types;
UTF-8,  8bit 1byte (standard ASCII set) ISO-8859-1
UTF-16, 16bit 2bytes (Unicode)
UCS-2, 2bytes (Universal Character Set)
UCS-4, 4bytes

example:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
i.e. using ISO... character set and no external DTD file

Special characters (entities)
<   &lt;
>   &gt;
&  &amp;
'    &apos;
"   &quot;
or use <![CDATA[ ... ]]>
or you can also use the unicode as in   &#0128; for the euro symbol
or the unicode hex value as in   &#xFEA1;



CMT3315  –  Lab Session 05

Quick questions:
1.    This is a smiley. Is it also a well-formed XML document? Say why.
<:-/>
No, because its using invalid characters for the label : which should start with a character and can also contain numbers.


2. What is the difference between well-formed and valid XML?
  • well-formed when its using the correct syntax and does not raise an error
  • valid when it conforms to the schema defenition so that it is in the defined structure and declared data types

3. Is it a good idea to start an XML document with a comment, explaining what the document is and what it’s for? Say why.
No, because the first few lines are used by the parser to identify the type of file and any validation required.


Longer questions:
1)
<?xml version="1.0" encoding="UTF-16"?>
 <!DOCTYPE textbook
[
<!ELEMENT titlePage (title, author, publisher, aphorism?>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT publisher (#EMPTY)>
<!ELEMENT aphorism (#PCDATA)>


<!ELEMENT verso (pubAddress, copyright, ISBN, dedication*)>
<!ELEMENT pubAddress (#PCDATA)>
<!ELEMENT copyright (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT dedication (#PCDATA)>


<!ELEMENT chapters (chapter*)>
<!ELEMENT chapter (section*)>
<!ELEMENT section (body*)>
<!ELEMENT body (#PCDATA)>


<!ATTLLIST chapter number CDATA #REQUIRED>
<!ATTLLIST chapter title CDATA #REQUIRED>
<!ATTLLIST section number CDATA #REQUIRED>
<!ATTLLIST section title CDATA #REQUIRED>


<!ATTLIST publisher name CDATA #FIXED "Excellent Books Ltd.">
<!ATTLIST publisher address CDATA #FIXED "21 Cemetry Lane, SE1 1AA, UK.">
]>




2)
<?xml version="1.0" encoding="UTF-16"?>
<city name="London">
  <attraction type="official building" inDoors="YES">
    <name>Best Ride</name>
    <district>District1</district>
    <yearBuilt>1974</yearBuilt>
  </attraction>


  <attraction type="art gallery" inDoors="NO">
    <name>History Items</name>
    <district>District3</district>
    <yearBuilt>1847</yearBuilt>
  </attraction>
</city>


3) re xml document shown;
a)      It’s clear that it’s concerned with English phrases and their Russian translations. One of the start tags is <targLangPhrase> with </targLangPhrase> as its end tag. Why do you suppose this isn’t <russianPhrase> with </russianPhrase> ?
So that it could easily be used for any other language by changing <phraseBook targLang=”Russian”>  to <phraseBook targLang=”other language”>

b)      Write a suitable prolog for this document.

<?xml version="1.0" encoding="UCS-4"?>


c)      Write a .dtd file to act as the Document Type Description for this document.
<?xml version="1.0" encoding="UCS-4"?>
<!DOCTYPE book
[
<!EMEMENT phraseBook (section+)>
<!ELEMENT section (sectionTitle, phraseGroup+)>
<!ELEMENT sectionTitle (#PCDATA)>

<!ELEMENT phraseGroup (engPhrase+, translitPhrase+, targLangPhrase+, gloss?)>

<!ELEMENT engPhrase (#PCDATA)>
<!ELEMENT translitPhrase (#PCDATA)>
<!ELEMENT targLangPhrase (#PCDATA)>
<!ELEMENT gloss (#PCDATA)>

<!ATTLIST phraseBook  targLang CDATA #REQUIRED>
]>

d)      The application that is to use this document runs on a Unix system, and was written some years ago. Is that likely to make any difference to the XML declaration?
No?