Saturday, 24 December 2011

CMT3315 - Lab 08 - CSS

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?

Yes, with CSS you can use absolute positioning to position the elements anywhere on or off screen.

b. Can you write the CSS file in such a way that it will display just the title, and the judgement?

Yes, the display property of the element to be hidden should be set to none.

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 type="text/css" href="legalWrit.css"?>

2. What is the difference between a URI and a URL?

A URI (Universal Resource Identifier) is a string of characters that defines the location of a resources on a network, a URL (Universal Resource Locator) is the locator that identifies the location of a network resource. URLs are a subset of URIs.


3. Why does the XML language allow namespaces?

As with most modern languages, name-spaces are used to prevent naming conflicts from occurring. E.g. what happens if you're using 2 schemas with the element name <date>, yet both schemas validate dates differently. By using name-spaces such as <ns1:date> or <ns2:date> one could clearly identify what validations should be used.


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.
What was the point of putting “display: block” into the CSS file in each of the 6 lines?

display:block ensures that all elements are rendered on separate lines (not next to each other), all elements have different default values for the display style attribute.

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

content {font-family: Palatino, "Times New Roman", Sans-Serif;
         font-size: 12pt; 
         background-color: #FCFBC4; 
         margin-left: 1em;}
 
poem {font-style: italic;
      display:block;
      margin-left: 1em;}
 
line {display: block;}

Saturday, 17 December 2011

CMT3315 - Lab 07 - More DTD

Quick Questions

1. People who prepare XML documents sometimes put part of the document in a CDATA section.
a. Why would they do that?

Text inside the CDATA tag is used as a marker for the parser to tread the inner content as text. Special characters such as < or > which would otherwise "break" the validity of the XML document are treated as normal characters.

b. How is the CDATA section indicated?

This section may be specified as follows <![CDATA[" text goes here "]]>

c. If CDATA sections hadn’t been invented, would there be any other way to achieve the same effect?

Yes, special characters may be "escaped" such as the < character would be represented as &lt; the parser would then treat this as an actual "less-than" character and  not the open-tag character.

2. What is a parser and what does it have to do with validity?

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 DTD does not support this rule definition, you may specify either once, zero or once, zero or more & one or more. This rule may however be created in an XSD schema.



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-8"?>
<!DOCTYPE text SYSTEM "book.dtd">


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.

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.

DTD


<?xml version = "1.0" encoding="UTF-8"?>

<!NOTATION jpg PUBLIC "image/jpeg">
<!ENTITY Sumbawa SYSTEM "sumbawa.jpg" NDATA jpg>
<!ENTITY LakeGeneva SYSTEM "Geneva1816.jpg" NDATA jpg>
<!ENTITY MaryShelley SYSTEM "MaryShelley.jpg" NDATA jpg>

<!ELEMENT content (paragraph+,poem*)>
<!ELEMENT paragraph(img)
<!ELEMENT paragraph(#PCDATA)>
<!ELEMENT poem(line+)>
<!ELEMENT line(#PCDATA)
<!ELEMENT img EMPTY>
<!ATTLIST img src ENTITY #REQUIRED title CDATA #REQUIRED>


XML

<content>
<paragraph>
A volcanic winter is very bad news. The worst eruption in recorded history happened at <index>Mount Tambora</index> in 1815. It killed about 71 000 people locally, mainly because the <index>pyroclastic flows</index> killed everyone on the island of <index>Sumbawa</index> 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.
<img src="sumbawa.jpg" title="Sumbawa, after the volcanic eruption">
</paragraph>
<paragraph>
The next year was the year without a summer. 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 Lakeland <index>poets</index> took a holiday at Lake Geneva, and the weather was so horrible that Lord Byron was inspired to write this. 
<img src="Geneva1816.jpg" title="Lake Geneva, during the summer of 1816">
</paragraph>
<poem>
<line>The bright sun was extinguish'd, and the stars Did wander darkling in the eternal space,</line>
<line>Rayless, and pathless, and the icy earth Swung blind and blackening in the moonless air;</line>
<line>Morn came and went – and came, and brought no day.</line>
</poem>
<paragraph>
Mary Shelley was inspired to write Frankenstein. The downside was that there were famines throughout Europe, India, China and North America, and perhaps 200 000 people died of starvation in Europe alone.
<img src="MaryShelley.jpg" title="Mary Shelley, author of Frankenstein">
</paragraph>
</content>

Saturday, 10 December 2011

CMT3315 - Lab 06 - XML Character Encoding

Quick questions:

1. What exactly does a DTD do in XML?

A Document Type Definition (DTD) specifies the schematic rules (structure) that must be followed, after the XML has been validated successfully to be syntactically correct, the XML document is validated against the rules defined in the DTD document.

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.

change the XML declaration to <?xml version= "1.0" encoding="ISO 8859-6"?>

3. Can you use a binary graphics file in an XML document?

Binary files such as images cannot be embedded directly inside the XML document, but path references may be used.


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> ?
     b) Write a suitable prolog for this document.
     c) Write a .dtd file to act as the Document Type Description for this document.
     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?

Ref: answer in previous post http://cmt3315-danielvella.blogspot.com/2011/12/cmt3315-lab-05-well-formed-xml.html

2. I decide to produce a book called “Toba: the worst volcanic eruption of all”. I ask 3 colleagues to write three text files entitled:
“Chapter 1: The mystery of Lake Toba’s origins”. 
“Chapter 2: Volcanic winter”. 
“Chapter 3: What Toba did to the human race”. 
All three text files are placed into a folder c:\bookproject\chapters on the hard drive on my computer. I insert <text> at the start of each file, and </text> at the end. I name the three files chap1.xml, chap2.xml, and chap3.xml respectively. I draw up the title page, title page verso and contents page of the book like this:
Toba: the worst volcanic eruption of all

Toba: the worst volcanic eruption of all
John
Jack
Jill
Joe
STC Press
Malta
Copyright © 2010
STC Press
Published by STC Press Ltd., Malta
ISBN: 978-0-596-52722-0
Contents
Chapter 1: The mystery of Lake Toba’s origins
Chapter 2: Volcanic winter
Chapter 3: What Toba did to the human race

 Then I construct an XML document that encompasses the whole book. 
(a) Provide this XML document


<?xml version="1.0" ?>
<Book>
<TitlePage>
<Title>Toba: the worst volcanic eruption of all</Title>
<Authors>
<Author>John</Author>
<Author>Jack</Author>
<Author>Jill</Author>
<Author>Joe</Author>
<Authors>
<Publisher>STC Press Malta</Publisher>
</TitlePage>
<TitlePageVersio>
<Copyright>Copyright (c) 2010 STC Press</Copyright>
<Address>Published by STC Press Ltd. Malta</Address>
<Isbn>978-0-596-52722-0</Isbn>
</TitlePageVersio>
<Contents>
<Chapter ChapterNumber="1" ChapterTitle="The mystery of Lake Toba's Origins">
<Title>Chapter 1: The mystery of Lake Toba's Origins</Title>
</Chapter>
<Chapter ChapterNumber="2" ChapterTitle="Volcanic winter">
<Title>Chapter 2: Volcanic winter</Title>
</Chapter>
<Chapter ChapterNumber="3" ChapterTitle="What Toba did to the human race">
<Title>Chapter 3: What Toba did to the human race</Title>
</Chapter>
</Contents>
</Book>



(b) Provide the accompanying .dtd file



<?xml version = "1.0" encoding="UTF-8"?>

<!ENTITY chap1 SYSTEM "c:\bookproject\chapters\chap1.xml">
<!ENTITY chap2 SYSTEM "c:\bookproject\chapters\chap2.xml">
<!ENTITY chap3 SYSTEM "c:\bookproject\chapters\chap3.xml">

<!ELEMENT Book (TitlePage,TitlePageVerson,Contents)>
<!ELEMENT TitlePage(Title, Authors,Publisher)
<!ELEMENT Title (#PCDATA)>
<!ELEMENT Authors(Author+)>
<!ELEMENT Author(#PCDATA)>
<!ELEMENT Publisher (#PCDATA)>
<!ELEMENT TitlePageVerso(Copyright, Address, Isbn)>
<!ELEMENT Copyright (#PCDATA)>
<!ELEMENT Address (#PCDATA)>
<!ELEMENT Isbn (#PCDATA)>
<!ELEMENT Contents (chapter+)>
<!ELEMENT chapter (title)>
<!ATTLIST chapter ChapterNumber #REQUIRED ChapterTitle>



Saturday, 3 December 2011

CMT3315 - Lab 05 - Well formed XML

Quick Questions


1. This is a smiley. Is it also a well-formed XML document? Say why. <:-/>

An XML document must always have one root element, the "slimy" is a valid root element which is also a closed element "/" at the end. According to the XML specifications element names may start with a ":" so therefore the above XML is well-formed.

2. What is the difference between well-formed and valid XML?

Well formed XML is XML that follows the general syntactical XML rules, valid XML is XML that apart from being well-formed can also be validated against a DTD or XSD schema successfully.

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.

It is considered good practice to comment XML documents to make it clearer for humans to understand the document structure and since they are ignored by XML parsers they have no effect when the document is machine processed. It is however not advisable to include comments before the document type declaration as this may be interpreted incorrectly.


Longer Questions


1. A set of documents is to be constructed as follows. The type of document is a college textbook. Every college textbook has a title page, on which is a title and an author and the publisher; optionally, there may be an aphorism.  Every college textbook has a title page verso, on which is a publisher’s address, a copyright notice, an ISBN; there may be a dedication, or there may be more than one. Every college textbook has several chapters, and each chapter has several sections, and each section has several bodies of text. A chapter is identified by a chapter number and a chapter title. A section is identified by a section number and a section title. The name of the publisher will always be Excellent Books Ltd. The address of the publisher will always be 21 Cemetry Lane, SE1 1AA, UK. The application that will process the documents can accept Unicode.
Write a .dtd file for this specification.

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE textbooks
[
      <!ENTITY publisher_Name "Excellent Books Ltd.">
      <!ENTITY publisher_Address "21, Cemetery Lane, SE1 1AA, UK">

      <!ELEMENT text_book (title_Page, title_Page_Verso, chapter+)>
      <!ELEMENT title_Page (title, author, publisher, aphorism?)>
      <!ELEMENT title_Page_Verso (publisher_Address, copyright_Notice, ISBN, dedication*)>

      <!ELEMENT chapter (section+)>
      <!ELEMENT section (body_Text+)>

      <!ATTLIST chapter chapter_Number CDATA #REQUIRED chapter_Title CDATA #REQUIRED>
      <!ATTLIST section section_Number CDATA #REQUIRED section_Title CDATA #REQUIRED>

      <!ELEMENT title (#PCDATA)>
      <!ELEMENT author (#PCDATA)>
      <!ELEMENT publisher (#PCDATA)>
      <!ELEMENT aphorism (#PCDATA)>

      <!ELEMENT publisher_Address (#PCDATA)>
      <!ELEMENT copyright_Notice (#PCDATA)>
      <!ELEMENT ISBN (#PCDATA)>
      <!ELEMENT dedication (#PCDATA)>

      <!ELEMENT body_Text (#PCDATA)>
]>

2. Write an XML document that contains the following information: the name of a London tourist attraction. The name of the district it is in. The type of attraction it is (official building, art gallery, park etc). Whether it is in-doors or out-doors. The year it was built or founded [Feel free to make this up if you don’t know]. Choose appropriate tags. Use attributes for the type of attraction and in-doors or out-doors status.

<?xml version="1.0" ?>
<TouristAttractions>
     <TouristAttraction type="art gallery" venue="in-doors">
     <District>Central</District>
     <YearConstructed>1880</YearConstructed>
     <TouristAttraction>
</TouristAttractions>



3. 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> ?

By using the tag name <targLangPhrase> instead of <russianPhrase> the designers are keeping the XML generic, the same XML schema and subsequent application making use of this data may be reused for translations between any other two languages.


b) Write a suitable prolog for this document.


<?xml version = “1.0” encoding = “utf-8”?>
<!DOCTYPE phraseBook SYSTEM “phraseBook.dtd”>



c) Write a .dtd file to act as the Document Type Description for this document.


<?xml version="1.0" encoding="utf-8"?>
<!ELEMENT phraseBook (section+)>
<!ATTLIST phraseBook targLang CDATA #REQUIRED>
<!ELEMENT section (sectionTitle, phraseGroup+)>
<!ELEMENT sectionTitle (#PCDATA)>
<!ELEMENT phraseGroup (engPhrase, translitPhrase, targLangPhrase)>
<!ELEMENT engPhrase (#PCDATA|gloss)*>
<!ELEMENT translitPhrase (#PCDATA|gloss)*>
<!ELEMENT targLangPhrase (#PCDATA)>
<!ELEMENT gloss (#PCDATA)>



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?

It is always advised to specify the character set when dealing with XML especially when dealing with language s other than English, this ensures all systems are able to interpret the content correctly.


Saturday, 26 November 2011

CMT3315 - Lab 04 - XML Syntax

Quick Questions

1. What does XML stand for? And CSS?

XML stands for Extensible Markup Language. CSS stands for Cascading Style Sheets.

2. Is this XML line well-formed? Say why.
<b><i>This text is bold and italid</b></i>

No this XML is not well formed, the </b></i> closing tags need to be inverted to reflect the order they were opened.

3. Is this XML document well-formed? Say why.

<? xml version="1.0" ?>
<greeting>
     Hello, World!
</greeting>
<greeting>
     Hello Mars too!
</greeting>

No this XML is not well formed, a well formed XML document should only have one root element.

Longer Questions

1. Write an XML document that contains the following information: the name of this course, the name if this building, the name of this room and the start and end times of this session. Choose appropriate tags. Use attributed for the start and end times.

Answer

<?xml version="1.0" ?>
<sessions>
     <session start="2011-11-22T18:00:00" end="2011-11-22T21:00:00">
          <name>CMT3315</name>
          <building>A</building>
          <room>4<room>
     </session>
</ sessions >

2. Have a look at the XML document below, Identify all the syntax errors.

Answer

I have highlighted all lines in the XML document in RED, including a GREEN line describing what is wrong. I have also included a corrected valid XML version of this document at the end.

<?xml version= "1.0" ?>
<!DOCTYPE bookStock SYSTEM "bookstock.dtd">
<bookstore>
No corresponding </bookstore> close tag
     <book category="Cooking">
          <title lang="en">Everyday Italian</title>
          <author>Giada De Laurentiis</author>
          <1stEdition>2005</1stEdition >
          <2ndEdition>2007</2ndEdition >
          Tags may not start with numbers
          <price>19.99</price currency="pounds sterling">
          Closing tags may not contain attributes
     </book>
     <book category="Children’>
     Opening double quotes must be matched by closing double quotes
          <title lang="en">Harry Potter and the enormous pile of money</title>
          <!—best selling children’s book of the year --2009 -->
          <author>J K. Rowling</author>
          <1stEdition>2005</1stEdition>
          Tags may not start with numbers
          <price>29.99</Price>
          Opening <price> tag does not match closing </Price tag> - XML is case sensitive
     </book>
     <book category="Web">
          <title lang="en">Learning XML</title>
          <author>Erik T. Ray</author>
          <1stEdition>2003</1stEdition>
          <2ndEdition >2008</2ndEdition >
          Tags may not start with numbers
          <price>29.95</discount>
          <discount>15%</price>
          <price> tag must be closed with </price> tag, <discount> tag must be closed
           with </discount>
     </book>
     <book category="Computing">
         <title lang=en>
          Insanely great – the life and times of Macintosh, the computer that changed everything
          </title>
          Attribute values must be enclosed in either single or double quotes
          <author <!—other authors not listed -->>Steven Levy</author>
          <1stEdition>1994</1stEdition>
          Tags may not start with numbers
         <price>9.95</discount>
         <discount>15%</price>
         <price> tag should be closed with </price>, <discount> should be closed 
         with </discount>
     </book>

Corrected XML document


<?xml version= "1.0" ?>
<!DOCTYPE bookStock SYSTEM "bookstock.dtd">
<bookstore>
    <book category="Cooking">
        <title lang="en">Everyday Italian</title>
        <author>Giada De Laurentiis</author>
        <firstEdition>2005</firstEdition>
        <secondEdition>2007</secondEdition>
        <price currency="GBP">19.99</price >
    </book>
    <book category="Children">
        <title lang="en">Harry Potter and the enormous pile of money</title>
        <author>J K. Rowling</author>
   <1stEdition>2005</1stEdition>
        <price>29.99</price>
    </book>
    <book category="Web">
        <title lang="en">Learning XML</title>
        <author>Erik T. Ray</author>
        <firstEdition>2003</firstEdition>
        <secondEdition>2008</secondEdition>
        <price>29.95</price>
        <discount>15%</discount>
    </book>
    <book category="Computing">
        <title lang="en">
        Insanely great – the life and times of Macintosh, the computer that changed everything
        </title>
        <author>Steven Levy</author>
        <firstEdition>1994</firstEdition>
        <price>9.95</price>
        <discount>15%</discount>
    </book>
</bookstore>

3. You are asked to produce a Document Type Declaration for a class of XML documents called "memo". You come up with this .dtd file.

Your client says "That's all very well", but every memo has to have a date, and some of them have to have a security classification too (You might want to write "Secret" at the top). And a memo has a serial number - I think that's what you'd call an attribute, isn't it?". How would you amend this .dtd so that it did what the client wanted?

Answer


<!DOCTYPE memo
[
<!ELEMENT memo (date,to,from,heading,body,classification)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ELEMENT classification (#PCDATA)>
<!ATTLIST memo serialNumber ID #REQUIRED>
]>



Saturday, 19 November 2011

CMT3315 - Lab 03 - XML Syntax

Question 1

Write an XML document that contains the following information: your name, your email address, your student number, your home town and your date of birth. Choose appropriate tags. Use attributes for the date of birth.

Answer

<?xml version="1.0" ?>
<students>
     <student dateOfBirth="26-08-1988">
          <name>Daniel Vella</name>
          <email>daniel.vella@domain.com</email>
          <studentNumber>M123456789</studentNumber>
          <town>Zabbar</town>
     </student>
</students>

Question 2

Have a look at the XML document below. Identify all the syntax errors.

Answer

I have highlighted all lines in the XML document in RED, including a GREEN line describing what is wrong. I have also included a corrected valid XML version of this document at the end.

<?xml version= “1.0” ?>
<!DOCTYPE countryCollection SYSTEM "countryList.dtd">
<CountryList>
No corresponding closing tag </CountryList>
     <Nations TotalNations ="3"/>
     No corresponding closing tag </Nations>
     <!--Data from CIA --Year Book -->
     <Country CountryCode="1">
     Closing tag </country> does not match opening tag </country> - XML is case sensitive
          <OfficialName>United States of America</officialName>
          Opening tag <OfficialName> does not match closing tag </officialName> - XML is 
          case sensitive
          <Label>Common Names:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <CommonName>United States</commonName>
Opening tag <CommonName> does not match closing tag </commonName> - XML is
          case sensitive
         <CommonName>U.S.</commonName>
Opening tag <CommonName> does not match closing tag </commonName> - XML is
          case sensitive
          <Label>Capital:</capital>
         <Capital cityNum="1">Washington, D.C. </label>
          Label tag must be closed with a corresponding </Label> tag not </capital>
          <Capital> tag must be closed with a corresponding </Capital> tag not </label>
          <2ndCity cityNum="2">New York </2ndCity>
Tag names must always start with an alphabet character
          <Label>Major Cities:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <MajorCity cityNum="3">Los Angeles </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
          case sensitive
         <MajorCity cityNum="4">Chicago </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
         <MajorCity cityNum="5'>Dallas </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
         Opening double quotes must be closed with double quotes
         <Label>Bordering Bodies of Water:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
          <BorderingBodyOfWater> Atlantic Ocean </borderingBodyOfWater>
Opening tag < BorderingBodyOfWater> does not match closing 
tag </ borderingBodyOfWater> - XML is case sensitive
         <BorderingBodyOfWater> Pacific Ocean </borderingBodyOfWater> 
Opening tag < BorderingBodyOfWater> does not match closing
tag </ borderingBodyOfWater> - XML is case sensitive
         <BorderingBodyOfWater> Gulf of Mexico </borderingBodyOfWater>
Opening tag < BorderingBodyOfWater> does not match closing 
tag </ borderingBodyOfWater> - XML is case sensitive
          <Label>Bordering Countries:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
          <BorderingCountry CountryCode="1"> Canada </borderingCountry>
Opening tag < BorderingCountry> does not match closing
tag </ borderingCountry> - XML is case sensitive
         <BorderingCountry CountryCode ="52"> Mexico </borderingCountry>
Opening tag < BorderingCountry> does not match closing 
tag </ borderingCountry> - XML is case sensitive
     </country>
     Closing tag </country> does not match opening tag </country> - XML is case sensitive
      <Country CountryCode="81">
     Closing tag </country> does not match opening tag </country> - XML is case sensitive
         <OfficialName> Japan </officialName>
          Opening tag <OfficialName> does not match closing tag </officialName> - XML is 
          case sensitive
         <Label>Common Names:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <CommonName> Japan </commonName>
Opening tag <CommonName> does not match closing tag </commonName> - XML is
          case sensitive
         <Label>Capital:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <Capital>Tokyo</capital cityNum="1">
Opening tag < Capital> does not match closing tag </ capital > - XML is case sensitive
         attributes are not allowed in closing tags
          <2ndCity cityNum="2">Osaka </2ndCity>
Tag names must always start with an alphabet character
         <Label>Major Cities:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <MajorCity cityNum="3">Nagoya </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
         <MajorCity cityNum="4">Osaka </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
          <MajorCity cityNum="5'>Kobe </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
         Opening double quotes must be closed with double quotes
         <Label>Bordering Bodies of Water:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <BorderingBodyOfWater>Sea of Japan </borderingBodyOfWater>
Opening tag < BorderingBodyOfWater> does not match closing 
tag </ borderingBodyOfWater> - XML is case sensitive
         <BorderingBodyOfWater>Pacific Ocean </borderingBodyOfWater>
Opening tag < BorderingBodyOfWater> does not match closing 
tag </ borderingBodyOfWater> - XML is case sensitive
      </country>
     Closing tag </country> does not match opening tag </country> - XML is case sensitive
     <Country CountryCode="254">
     Closing tag </country> does not match opening tag </country> - XML is case sensitive
         <OfficialName> Republic of Kenya </officialName>
          Opening tag <OfficialName> does not match closing tag </officialName> - XML is 
          case sensitive
         <Label>Common Names:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <CommonName> Kenya </commonName>
Opening tag <CommonName> does not match closing tag </commonName> - XML is
          case sensitive
         <Label>Capital:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <Capital cityNum='1'>Nairobi </capital>
Opening tag < Capital> does not match closing tag </ capital > - XML is case sensitive
         <2ndCity cityNum='2'>Mombasa</2ndCity>
Tag names must always start with an alphabet character
         <Label>Major Cities:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <MajorCity cityNum='3'>Mombasa </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
         <MajorCity cityNum='4'>Lamu </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
         <MajorCity cityNum='5'>Malindi </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
         <MajorCity cityNum='6' cityNum='7'>Kisumu-Kericho </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
Duplicate attributed cityNum not allowed in XML
         <Label>Bordering Bodies of Water:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <BorderingBodyOfWater <!--Also Lake Victoria --> > Indian Ocean
          </borderingBodyOfWater>
Opening tag < BorderingBodyOfWater> does not match closing 
tag </ borderingBodyOfWater> - XML is case sensitive
          <BorderingBodyOfWater tag not closed properly
          Comments not allowed inside <tags>
          Special characters such as < and > need to be escaped when used in XML as text
      </country>
  Closing tag </country> does not match opening tag </country> - XML is case sensitive



Corrected XML document

<?xml version= “1.0” ?>
<!DOCTYPE countryCollection SYSTEM "countryList.dtd">
<CountryList>
    <Nations TotalNations ="3">
        <Country CountryCode="1">
            <OfficialName>United States of America</OfficialName>
            <Label>Common Names:</Label>
            <CommonName>United States</CommonName>
            <CommonName>U.S.</CommonName>
            <Label>Capital:</Label>
            <Capital cityNum="1">Washington, D.C. </Capital>
            <SecondCity cityNum="2">New York </SecondCity>
            <Label>Major Cities:</Label>
            <MajorCity cityNum="3">Los Angeles </MajorCity>
            <MajorCity cityNum="4">Chicago </MajorCity>
            <MajorCity cityNum="5">Dallas </MajorCity>
            <Label>Bordering Bodies of Water:</Label>
            <BorderingBodyOfWater> Atlantic Ocean </BorderingBodyOfWater>
            <BorderingBodyOfWater> Pacific Ocean </BorderingBodyOfWater>
            <BorderingBodyOfWater> Gulf of Mexico </BorderingBodyOfWater>
            <Label>Bordering Countries:</Label>
            <BorderingCountry CountryCode="1"> Canada </BorderingCountry>
            <BorderingCountry CountryCode ="52"> Mexico </BorderingCountry>
        </Country>
        <Country CountryCode="81">
            <OfficialName> Japan </OfficialName>
            <Label>Common Names:</Label>
            <CommonName> Japan </CommonName>
            <Label>Capital:</Label>
            <Capital cityNum="1">Tokyo</Capital>
            <SecondCity cityNum="2">Osaka </SecondCity>
            <Label>Major Cities:</Label>
            <MajorCity cityNum="3">Nagoya </MajorCity>
            <MajorCity cityNum="4">Osaka </MajorCity>
            <MajorCity cityNum="5">Kobe </MajorCity>
            <Label>Bordering Bodies of Water:</Label>
            <BorderingBodyOfWater>Sea of Japan </BorderingBodyOfWater>
            <BorderingBodyOfWater>Pacific Ocean </BorderingBodyOfWater>
        </Country>
        <Country CountryCode="254">
            <OfficialName> Republic of Kenya </OfficialName>
            <Label>Common Names:</Label>
            <CommonName> Kenya </CommonName>
            <Label>Capital:</Label>
            <Capital cityNum='1'>Nairobi </Capital>
            <SecondCity cityNum='2'>Mombasa</SecondCity>
            <Label>Major Cities:</Label>
            <MajorCity cityNum='3'>Mombasa </MajorCity>
            <MajorCity cityNum='4'>Lamu </MajorCity>
            <MajorCity cityNum='5'>Malindi </MajorCity>
            <MajorCity cityNum='6'>Kisumu-Kericho </MajorCity>
            <Label>Bordering Bodies of Water:</Label>
            <BorderingBodyOfWater>Indian Ocean </BorderingBodyOfWater>
            <BorderingBodyOfWater>Lake Victoria</BorderingBodyOfWater>
        </Country>
    </Nations>
</CountryList>

Saturday, 12 November 2011

CMT3315 - Lab 02 - HTML & XML Documents

Question 1

Have a look at the documents below, some are XML documents, some are HTML documents, some may be neither. See if you can decide which are which.

Answers
Document 1

This document is an HTML document, it is constructed with some of the well known HTML tags such as <head>, <title>, <body>, <a> etc… It also includes a <script> tag example which is used to load javascript code. Most HTML tags include attributes such as <a href=” http://ads.touregypt.net/cgi-bin/adcycle/adclick.cgi?gid=1&id=305”> which would be rendered as a hyperlink, linking to http://ads.touregypt.net/cgi-bin/adcycle/adclick.cgi?gid=1&id=305 or <table border=”0”> which would style the table with no border. The latter would be better implemented using a cascading style sheet CSS to have distinct documents for content and styling. As it is this document can not be validated as an HTML document as some obvious flaws exist such as document does not have an <HTML> tag which is the root tag for all HTML documents. There are also various tags which are not terminated properly such as the <table border=”0” width=570””> tag.

Document 2

This document is a VALID XML document, although this document follows correct XML syntax, it could not be validated against the referenced DTD schema as this was not supplied.

Document 3

This document is an HTML document, very similar to Document 1, which although makes use of valid HTML tags could not be considered valid XML because of missing <HTML> tags etc.. This document also includes an example of the <script> tag, this time in the header; this is considered better practice than loading javascript in the <body> section as it ensures the script is loaded before the document body. A <form> element is also used in this document, <form> elements allow browsers to capture and forward user inputted data.

Document 4

This document is a VALID XML document; it follows correct XML syntax but cannot be validated against the referenced DTD schema as this was not supplied with the example.

Document 5

This document is an XML document, the first section of the document is the DTD schema which defines the structure of the XML content whilst the second portion of the document is the XML document itself which references the DTD used to validate it.

Document 6

This document is a VALID XML document; it follows correct XML syntax but cannot be validated as the referenced schema was not provided with the examples.

Document 7

This is an HTML document, although most tags defined in this document do not appear to be proper HTML tags such as <OfficialName> & <commonName>, on closer inspection one would notice that these declarations are being passed as string through javascript functions which are then interpreting the data and generating the XML to be rendered to a browser.

Question 2

Make a list of the distinctive characteristics of an XML document, in terms of things that you can spot when looking at the code.

Answer

  • Unlike HTML XML is not limited by a defined set of tags, XML is customizable.
  • Although not strictly required XML documents have corresponding DTD or XSD schemas to be validated against
  • All tags should be follows by corresponding closing tags e.g. <tag>content</tag> or closed immediately e.g. <tag />.
  • XML documents should have one root element.
  • XML tags may contain attributed within the tag e.g. <tag attribute=”value”>
  • Content in XML documents escaped properly otherwise the document may become invalidated e.g. <tag>content > here</tag> is invalid XML the “>” is considered as a special character in XML and should be escaped as follows <tag>content &gt; here</tag>