Wednesday, 21 December 2011

Lab 7

Quick questions:

1.    People who prepare XML documents sometimes put part of the document in a CDATA section.

    1. Why would they do that?

              CDATA  (Character Data) is used for any data that is to be ignored  by an XML parser.  Any type of text that is not to be parsed, such as some parts of code, can be put in a CDATA section.


    1. How is the CDATA section indicated?

A CDATA section is starts with “<![CDATA[“ and ends with “]]>” with the text wanted in between the 2 parts.


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

Multi-line commenting is another simple way to have text which is ignored by the XML parser. A multi-line comment section starts with “<!--“ and ends with “-->”, again with the text between the 2 parts.

A disadvantage of using multi-line commenting instead of CDATA is that comments cannot be declared in a DTD.


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

An XML parser converts an XML document into an XML DOM object, this is done to read and extract data from the elements in the XML document.

Before any processing, an XML parser validates the XML document against a DTD to ensure that the XML is in the correct structure and format.


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

By defining the tag <trinity> three times, you need to build DTD to take not of the number of occurrence of this element, in this case “trinity” will be declared only once but have it appear three times in the root element:

For example taking this xml:

<theRootElement>
            <trinity>1</trinity>
<trinity>2</trinity>
<trinity>3</trinity>
</theRootElement>
The DTD would be as follows:

<!DOCTYPE theRootElement[
            <!ELEMENT theRootElement (trinity, trinity, trinity)>
            <!ELEMENT trinity (#PCDATA)
]>

The element trinity wasn’t done with the notations of * or + as it always will occur three times in the XML document and is not variable


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 chapter SYSTEM “chptr.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.

<!DOCTYPE chptr
[
            <!ELEMENT chapter (title, material)>
                        <!ATTLIST chapter number CDATA #REQUIRED>
<!ELEMENT material (paragraph+, poem*)>
            <!ELEMENT paragraph (#PCDATA)>
            <!ELEMENT poem (poemVerse+)>
                        <!ELEMENT poemVerse (#PCDATA)>
]



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.

<?xml version=”1.0” encoding=”UTF-8?”>
            <!DOCTYPE chapter SYSTEM “chptr.dtd”>
            <chapter number = “2”>
                        <title>Volcanic Winter</title?>
                        <material>
                                    <paragraph>
A volcanic winter is very bad news. The worst eruption in recorded history happened at Mount Tambora in 1815. It killed about 71 000 people locally, mainly because the pyroclastic flows killed everyone on the island of Sumbawa 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. 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 poets took a holiday at Lake Geneva, and the weather was so horrible that Lord Byron was inspired to write this.
                                    </paragraph>
                                    <poem>
                                                <poemVerse>
The bright sun was extinguish'd, and the stars
</poemVerse>
<poemVerse>
Did wander darkling in the eternal space,
</poemVerse>
<poemVerse>
Rayless, and pathless, and the icy earth
</poemVerse>
<poemVerse>
Swung blind and blackening in the moonless air;
</poemVerse>
<poemVerse>
Morn came and went – and came, and brought no day.
</poemVerse>
                                    </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.
                                                </paragraph>
                                    </material>
                        </chapter>




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:


<!DOCTYPE chptr
[
            <!ELEMENT chapter (title, material)>
                        <!ATTLIST chapter number CDATA #REQUIRED>
<!ELEMENT material (paragraph+, poem*, image*)>
            <!ELEMENT paragraph (#PCDATA)>
            <!ELEMENT poem (poemVerse+)>
                        <!ELEMENT poemVerse (#PCDATA)>
            <!NOTATION JPG SYSTEM “image/JPG”>
<!ENTITY sumbawa SYSTEM "sumbawa.jpg" NDATA JPG>
<!ENTITY lakeGeneva SYSTEM "geneva1816.jpg" NDATA JPG>
<!ENTITY maryShelley SYSTEM "maryShelley.jpg" NDATA JPG>

<!ELEMENT image (#PCDATA)>
<!ATTLIST image
    source ENTITY #IMPLIED
    caption CDATA #REQUIRED
>
]



XML:


<?xml version=”1.0” encoding=”UTF-8?”>
            <!DOCTYPE chapter SYSTEM “chptr.dtd”>
            <chapter number = “2”>
                        <title>Volcanic Winter</title?>
                        <material>
                                    <paragraph>
A volcanic winter is very bad news. The worst eruption in recorded history happened at Mount Tambora in 1815. It killed about 71 000 people locally, mainly because the pyroclastic flows killed everyone on the island of Sumbawa 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. .</paragraph>
        <image source="sumbawa" caption="Sumbawa, after the volcanic eruption"/>
        <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 poets took a holiday at Lake Geneva, and the weather was so horrible that Lord Byron was inspired to write this.
                                    </paragraph>
        <image source="lakeGeneva" caption="Lake Geneva during the summer of 1816"/>
                                    <poem>
                                                <poemVerse>
The bright sun was extinguish'd, and the stars
</poemVerse>
<poemVerse>
Did wander darkling in the eternal space,
</poemVerse>
<poemVerse>
Rayless, and pathless, and the icy earth
</poemVerse>
<poemVerse>
Swung blind and blackening in the moonless air;
</poemVerse>
<poemVerse>
Morn came and went – and came, and brought no day.
</poemVerse>
                                    </poem>
                                    <paragraph>
<image source="maryShelley" caption="Mary Shelley, author of Frankenstein"/>
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.
                                                </paragraph>
                                    </material>
                        </chapter>

Thursday, 15 December 2011

Lab 6

Quick questions:

1.    What exactly does a DTD do in XML?
A DTD provides a template to indicate the presence, order and placement of elements and their attributes in an XML documents for document mark-up. Also it may contain other data such as entity definitions.

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.

The answer is C). This is because the XML parser will use UTF-8 encoding by default  if the encoding is not specified and that includes all the Arabic characters.

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

Yes if the following steps are taken it is possible:
A) The file is made as an external entity
B) NDATA is used followed by a format code in the entity declaration
C) The Notation is declared
D) The Entity is made the source of an attribute value for another element
E) The Entity is used with that attribute value as the graphic.


Longer questions:
1.        The following is the document element (root element) of an XML document.
This question is exactly the same as question 3 in my previous blog, please refer to it.

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
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" encoding="UTF-8"?>
<!DOCTYPE book SYSTEM "book.dtd">
<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>&pblshr</publisher>
        <country>Malta</country>
    </titlePage>

    <verso>
        <copyright>Copyright © 2010</copyright>
        <publishedBy> Published by STC Press Ltd., Malta</publishedBy>
        <ISBN>ISBN: 978-0-596-52722-0</ISBN>
    </verso>

    <contents> Contents
        <chName number="1" title="The mystery of Lake Toba's origins"/>
        <chName number="2" title="Volcanic winter"/>
        <chName number="3" title="What Toba did to the human race"/>
    </contents>

    <chapters>
        <chapter number="1" title="The mystery of Lake Toba's origins">&chapter1</chapter>
        <chapter number="2" title="Volcanic winter">&chapter2</chapter>
        <chapter number="3" title="What Toba did to the human race">&chapter3</chapter>
    </chapters>

</book>

(b)   Provide the accompanying .dtd file


<?xml version="1.0" ?>
<DOCTYPE book [
 
    <!ELEMENT book (titlePage, verso, contents, chapters)>

    <!ELEMENT titlePage (title, authors, publisher, country)>
        <!ELEMENT title (#PCDATA)>
        <!ELEMENT authors (author+)>
            <!ELEMENT author (#PCDATA)>
        <!ELEMENT publisher (#PCDATA)>
        <!ELEMENT country (#PCDATA)>
      
    <!ELEMENT verso (copyright, publishedBy ,ISBN)>
        <!ELEMENT copyright (#PCDATA)>
        <!ELEMENT publishedBy (#PCDATA)>
        <!ELEMENT ISBN (#PCDATA)>

    <!ELEMENT contents (chName+)>
        <!ELEMENT chName (#PCDATA)>
        <!ATTLIST chName number CDATA #REQUIRED title CDATA #REQUIRED>

    <!ELEMENT chapters (chapter+)>
        <!ELEMENT chapter (#PCDATA)>
        <!ATTLIST chapter number CDATA #REQUIRED title CDATA #REQUIRED>


<!ENTITY pblshr "STC Press">
<!ENTITY chapter1 SYSTEM "chapter1.xml">
<!ENTITY chapter2 SYSTEM "chapter2.xml">
<!ENTITY chapter3 SYSTEM "chapter3.xml">

Sunday, 27 November 2011

Lab 5: DTDs

Quick questions:

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

Although it is not recommended to used “:” and “-“ in an XML as they may cause confusion with namespaces and the mathematical subtraction symbol, theoretically this is well formed XML, since it does not break any rules of XML syntax and since it ends with ‘/>’ the XML is closing the element. So this XML is an empty element name ‘:-‘

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

A well-formed XML follows the syntax rules and its elements are properly nested.
A Valid XML is an XML that is well formed and ensures that the DTD or XML Schemas conform with the XML document.

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.

The comment will make the document easier if it is to be maintained, especially when it is not the original writer of the document. Also comments will not inter fear with the code and thus will not affect the document in anyway such as performance or readability from the parser. The only place a comment should not be placed is before the declaration as some XML parsers do not work correctly if the declaration is not the first line in the code.


 Longer questions:

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 collegeTextbooks [

<!ELEMENT collegeTextbook (titlePage, titlePageVerso, chapter+)>

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

<!ELEMENT titlePageVerso (publisherAddress, copyrightNotice, ISBN, dedication*)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT copyrightNotice (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT dedication (#PCDATA)>

<!ELEMENT chapter (section+)>
<!ELEMENT section (bodyOfText+)>
 <!ELEMENT bodyOfText (#PCDATA)>
<!ATTLIST chapter
chapterNumber CDATA #REQUIRED
chapterTitle CDATA #REQUIRED
> 

<!ATTLIST section
sectionNumber CDATA #REQUIRED
sectionTitle CDATA #REQUIRED
> 

<!ENTITY publisherName "Excellent Books Ltd">
<!ENTITY publisherAddress "21, Cemetery Lane, SE1 1AA, UK"> 
]>



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.

<attraction type = “Gallery” indoorOrOutdoor = “Indoor”>
            <name>TheAttraction</name>
            <district>District Name</district>
            <yearFounded>2000</yearFounded>
</attraction>



The following is the document element (root element) of an XML document.



<phraseBook targLang=”Russian”>
<section><sectionTitle>Greetings</sectionTitle>
<phraseGroup><engPhrase>Hi! </engPhrase><translitPhrase>privEt </translitPhrase><targLangPhrase>Привет! <phraseGroup><engPhrase>Good morning! dObraye Utra Доброе утро! <phraseGroup><engPhrase>Good evening! </engPhrase><translitPhrase>dObriy dEn/ vEcher <gloss>(day/evening) </gloss> </translitPhrase><targLangPhrase>Добрый день/ вечер! <phraseGroup><engPhrase>Welcome! <gloss>(to greet someone)</gloss></engPhrase><translitPhrase>dabrO pazhAlavat’ </translitPhrase><targLangPhrase>Добро пожаловать! <phraseGroup><engPhrase>How are you? </engPhrase><translitPhrase>kak dela? </translitPhrase><targLangPhrase>Как дела? <phraseGroup><engPhrase>I'm fine, thanks! </engPhrase><translitPhrase>harashO! Spasiba </translitPhrase><targLangPhrase>Хорошо, спасибо! <phraseGroup><engPhrase>And you? </engPhrase><translitPhrase>a u tibyA? А у тебя? <phraseGroup><engPhrase>Good/ So-So. </engPhrase><translitPhrase>harashO/ tAk sibe </translitPhrase><targLangPhrase>Хорошо/Так себе <phraseGroup><engPhrase>Thank you <gloss>(very much)</gloss>! </engPhrase><translitPhrase>spasiba </translitPhrase><targLangPhrase>Спасибо! <phraseGroup><engPhrase>You're welcome! <gloss>(for "thank you")</gloss> </engPhrase><translitPhrase>pazhAlusta </translitPhrase><targLangPhrase>пожалуйста! <phraseGroup><engPhrase>Hey! Friend! </engPhrase><translitPhrase>Ey, drug! </translitPhrase><targLangPhrase>Эй, друг\ Эй, приятель. <phraseGroup><engPhrase>I missed you so much! </engPhrase><translitPhrase>Ya tak sil'no skuchAl/a <gloss>(female)</gloss> pa tibE
</translitPhrase><targLangPhrase>Я так сильно скучал/a по тебе <phraseGroup><engPhrase>What's new? </engPhrase><translitPhrase>Chto nOvava? </translitPhrase><targLangPhrase>Что нового? <phraseGroup><engPhrase>Nothing much </engPhrase><translitPhrase>NiplOha/ NichivO </translitPhrase><targLangPhrase>Неплохо\ Ничего. <phraseGroup><engPhrase>Good night! </engPhrase><translitPhrase>spakOynay nOchi </translitPhrase><targLangPhrase>спокойной ночи <phraseGroup><engPhrase>See you later! </engPhrase><translitPhrase>da vstrEchi/ da svidAn’ya </translitPhrase><targLangPhrase>до встречи/ до свидания <phraseGroup><engPhrase>Good bye! </engPhrase><translitPhrase>pakA/ da svidAn’ya </translitPhrase><targLangPhrase>Пока/до свидания </targLangPhrase></phraseGroup>  </section>
<section><sectionTitle>Asking for Help and Directions</sectionTitle>  <phraseGroup><engPhrase>  I'm lost </engPhrase><translitPhrase>ya zabludils’a </translitPhrase><targLangPhrase>Я заблудился </targLangPhrase></phraseGroup><phraseGroup>  <engPhrase>  Can I help you? </engPhrase><translitPhrase>Ya magU vam pamOch? </translitPhrase><targLangPhrase>Я могу вам помочь? </targLangPhrase></phraseGroup><phraseGroup>  <engPhrase>  Can you help me? </engPhrase><translitPhrase>Vy mOzhite mne pamOch? </translitPhrase><targLangPhrase>Вы можете мне помочь? </targLangPhrase></phraseGroup><phraseGroup>  <engPhrase>  Where is the (bathroom/ pharmacy)? </engPhrase><translitPhrase>Gde nahOditsa (vAnnaya/ aptEka)?
</translitPhrase><targLangPhrase>Где находится (Ванная/ Аптека) </targLangPhrase></phraseGroup><phraseGroup>  <engPhrase>  Go straight! then turn left/ right! </engPhrase><translitPhrase>idite pryAmo, patOm nalEva/ naprAva
</translitPhrase><targLangPhrase>Идите прямо, потом налево/направо </targLangPhrase></phraseGroup><phraseGroup>  <engPhrase>  I'm looking for john. </engPhrase><translitPhrase>Ya ichU DzhOna </translitPhrase><targLangPhrase>Я ищу Джона. </targLangPhrase></phraseGroup><phraseGroup>  <engPhrase>  One moment please! </engPhrase><translitPhrase>MinUtu, pazhAlusta </translitPhrase><targLangPhrase>Минуту, пожалуйста. </targLangPhrase></phraseGroup><phraseGroup>  <engPhrase>  Hold on please! <gloss>(phone)</gloss> </engPhrase><translitPhrase>PadazhdIte, pazhAlusta! </translitPhrase><targLangPhrase>Подождите, пожалуйста! </targLangPhrase></phraseGroup><phraseGroup>  <engPhrase>  How much is this? </engPhrase><translitPhrase>SkOl'ka Eta stOit? </translitPhrase><targLangPhrase>Сколько это стоит? </targLangPhrase></phraseGroup><phraseGroup>  <engPhrase>  Excuse me ...! <gloss>(to ask for something)</gloss> </engPhrase><translitPhrase>izvinite! / prastite </translitPhrase><targLangPhrase>Извините\Простите </targLangPhrase></phraseGroup><phraseGroup>  <engPhrase>  Excuse me! <gloss>(to pass by)</gloss> </engPhrase><translitPhrase>izvinite! </translitPhrase><targLangPhrase>Извините! Come with me! </engPhrase><translitPhrase>PaidyOmte sa mnOy! </translitPhrase><targLangPhrase>Пойдемте со мной! </targLangPhrase></phraseGroup>  </section> </PhraseBook>




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>?
This is to make the document more flexible so that it can be used to for other languages as well and not only Russian.

Write a suitable prolog for this document.
<?xml version=”1.0” encoding=”UTF-8”?>
<!DOCTYPE phraseBook SYSTEM “translation.dtd”>

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)>



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?

This will not make a difference as UTF-8 fully supports the Cyrillic characters which are used in the Russian language.

Wednesday, 23 November 2011

Lab 4: Well-Formed XML

Here are the Questions given in the 4th Lab session of this course. These questions mostly dealt with well-formness of XML


Quick questions:

  1. What does XML stand for? And CSS?

XML stands for Extensible Markup Language and is designed to transport and store data.
CSS stands for  Cascading Style Sheets which is used to store formatting information of HTML pages.


  1. Is this XML line well-formed? Say why.

<b><i>This text is bold and italic</b></i>

No, this is not a well-formed XML line as the closing tags do not match well with the opening tags. To be well-formed this XML line must be changed to:

<b><i>This text is bold and italic</i></b>


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

<?xml version= “1.0” ?>
<greeting>
Hello, world!
</greeting>
<greeting>
Hello Mars too!
</greeting>

No, this isn’t a well formed XML document either as there is no root element in this XML. For the document to be well formed it has to be changed to something like:

<?xml version= “1.0” ?>
<differentGreetings>
<greeting>Hello, world!</greeting>
<greeting>Hello Mars too!</greeting>
</differentGreetings>



Longer questions:

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

<course>
     <name>Advanced Web Technologies</name>
<building>STC</building>
     <session starttime=”18:00” endtime=”21:00”>
         <room>1</room>
     </session>
</course>

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

<?xml version= “1.0” ?>
<!DOCTYPE bookStock SYSTEM "bookstock.dtd">
<bookstore>
  <book category="Cooking">
    <title lang="en">Everyday Italian</title>
    <author>Giada De Laurentiis</author>
    <1stEdition>2005</1stEdition >
    <2ndEdition>2007</2ndEdition >
    <price>19.99</price currency=”pounds sterling”>
  </book>
  <book category="Children’>
    <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>
    <price>29.99</Price>
  </book>
  <book category="Web">
    <title lang="en">Learning XML</title>
    <author>Erik T. Ray</author>
   <1stEdition>2003</1stEdition>
   <2ndEdition >2008</2ndEdition >
    <price>29.95</discount>
    <discount>15%</price>
  </book>
  <book category="Computing">
    <title lang=en>Insanely great – the life and times of Macintosh, the computer that changed everything </title>
    <author 
<!—other authors not listed -->>Steven Levy</author>
   <1stEdition>1994</1stEdition>
    <price>9.95</discount>
    <discount>15%</price>
  </book>



Error 1: Tags cannot start with a numeric value
Ex: <1stEdition>2005</1stEdition >

Error 2:  Attributes cannot be placed at closing tags
Ex: <price>19.99</price currency=”pounds sterling”>

Error 3:     XML tags are Case sensitive
Ex:<price>29.99</Price>

Error 4 :   Tags are not correctly matched
Ex:  <price>29.95</discount>
       <discount>15%</price>

Error 5 : Attributes must be declared in qoutes
Ex :<title lang=en >Insanely great – the life and times of Macintosh, the computer that changed everything </title>

Error 6:   A comment cannot be place inside a tag
Ex: <author <!—other authors not listed -->>Steven Levy</author>

Error 7: There is no closing tag for <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:

<!DOCTYPE memo
[
<!ELEMENT memo (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>

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 file so that it did what the client wanted?

Basically we have to add 3 things to the DTD provided:

First we have to add another element for the Date, so this:

<!ELEMENT memo (to,from,heading,body)>

Has to be changed to:

<!ELEMENT memo (to,from,heading,body,date)>

Also after the last element we have to add:

<!ELEMENT date (#PCDATA)>


The 2nd item to add is the serial number attribute. This is acheived by creating an ATTLIST after declaring all the Elements as follow:

<!ATTLIST memo
     serialNumber ID #REQUIRED
> 


The last item to add is the classification attribute to know if the memo is a secret. Again we have to add this in the ATTLIST but this attribute will be an enumerator, so only specific values will be accepted:

Classification (Secret|Public) “Security”

So the final DTD will look like this:

<!DOCTYPE memo
[
<!ELEMENT memo (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ATTLIST memo
     serialNumber ID #REQUIRED
     classification (Secret|Public) “Security”
>
]>