Wednesday, 30 November 2011

Week 6 - XML Namespaces and Questions

Introduction
This week namespaces in XML. In XML you create your own element names and might happen that there would be clashes between names meaninig you use the same element name for different purposes. For example say that you are declaring if its a Ms. Or a Mr. In this case you can use element as <title> but when declaring the book name you may also use the element name <title>. As XML documents continue to grow they become more complex and might originate this problem. To limit this kind of clashes namespaces where created, these are a collection of nams which belong together. URI's are usefull so that your elememt names are different from anyones else. Namespaces consist of a prefix and the local part.(Middlesex lecture notes, lecture 6) Ex:

book:title
name:title

Quick questions
Question 1
What exactly does a DTD do in XML?
DTD's are made out of markup language, and stands for Document Type Definition.DTD's define a well structure of XML. To define which elements and attributes are and where they appear DTD's are used, these use formal syntax. DTD explains statements like every school element must have a course_name attribute. XML documents have to be validate in order to meet the rules defined in the DTD

Question 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.

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

Question 3 
Can you use a binary graphics file in an XML document?
Binary graphics cannot be used however if you specify that entity with the keyword "NDATA" this can be used, by assigning the path. Below is an example:

<!NOTATION JPG SYSTEM "myfile/jpg">
    <!ENTITY employee SYSTEM "employee.jpg" NDATA JPG>
Long Questions
Question 1. Answer
Refer to the previous blog (week 5) question 3.
Question 2
I decided to produce a book called "Toba: the worst volcanic eruption of all". I ask a colleague to write" Chapter: The mystery of Lake Toba's origins".
I ask another colleague to write "Chapter 2: Volcanic Winter".
I ask another colleage to write "Chapter 3: What Toba did to the human race".
I thank them, and put all three text files 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 respectivley. 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
b) Provide the accompanying .dtd file


Answer 2a
<?xml version ="1.0" encoding ="UTF-8"?>
<!DOCTYPE book SYSTEM "book.dtd">
<!--This is the root element-->
<book> 
       <titlePage>
                 <title> Toba: the worst volcanic eruption of all </title>
                     <authors>
                       <author>
                                 <name>John</name>
                                 <surname>Johns</surname>
                       </author>
                       <author>
                                 <name>Jack</name>
                                 <surname>Jacks</surname>
                       </author>
                       <author>
                                 <name>Jill</name>
                                 <surname>Jills</surname>
                       </author>
                       <author>
                                 <name>Joe</name>
                                 <surname>Joes</surname>
                       <author>
                     </authors>
                       <published>STC Press</published>
                       <publishedCountry> Malta </publishedCountry>
      </titlePage>
      <titlePageVerso>
                            <disclamer> &copyright; </disclamer>
                            <address>Published by STC Press Ltd., Malta </address>
                            <isbnNumber>978-0-596-52722-0</isbnNumber>
                   
      </titlePageVerso>
      <contentsPage>
                                <cp:chapter chapterId="c1"
                                <cp:title> Chapter1: The mystery of Lake Toba's origins</title>
                                </chapter>

                                <cp:chapter chapterId="c2"
                                <cp:title> Chapter2: Volcanic Winter</title>
                                </chapter>

                                <cp:chapter chapterId="c3"
                                <cp:title> Chapter3: What Toba did to the human race</title>
                                </chapter>


      </contentsPage>
</book>


Answer 2b


<?xml version = "1.0" encoding ="UTF-8"?>
<!ELEMENT book (titlePage,titlePageVerson,contentsPage)>
<!ELEMENT titlePage(title, authors,published,publishedCountry)
<!ELEMENT title (#PCDATA)>
<!ELEMENT authors(author+)>
<!ELEMENT author (name, surname)
<!ELEMENT name(#PCDATA)>
<!ELEMENT surname(#PCDATA)>
<!ELEMENT published (#PCDATA)>
<!ELEMENT publishedCountry (#PCDATA)>
<!ELEMENT titlePageVerso(disclamer, address, isbnNumber)>
<!ELEMENT disclamer (#PCDATA)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT isbnNumber (#PCDATA)>
<!ELEMENT contentsPage (chapter+)>
<!ELEMENT cp:chapter (title)>
<!ATTLIST cp:chapter chapterId #REQUIRED>
<!ELEMENT cp:title (#PCDATA)
<!ENTITY ch1 SYSTEM "c:\bookproject\chapters\champ1.xml">
<!ENTITY ch2 SYSTEM "c:\bookproject\chapters\champ2.xml">
<!ENTITY ch3 SYSTEM "c:\bookproject\chapters\champ3.xml">


References:

No comments:

Post a Comment