Wednesday, November 30, 2011

6 - DTDs

Quick questions:

1) What exactly does a DTD do in XML?

A DTD file is used to validate and XML document. It validates the elements and their attributes of the XML file as well as their order.

2) You’ve written an XML document, with the XML declaration  <?xml version= “1.0”?>
  1. change the XML declaration to <?xml version= “1.0” encoding=”ISO 8859-6”?>
  2. change the XML declaration to <?xml version= “1.0” encoding=”UTF-8”?>
  3. do nothing: the declaration is fine as it is.
The declaration is fine as it is, since if the character set is not declared, it is assumed to be "UTF-8". "UTF-8" supports the Arabic characters in encoding=”ISO 8859-6”.

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

An image can be defined as an external entity in an XML document. The image format must be specified and the data must be non-parsable.

Longer questions:


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 at the start of each file, and 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: 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 "Lab06_book.dtd">
<book>
            <titlePage>
                        <bookTitle>Toba: the worst volcanic eruption of all</bookTitle>
                        <author>John</author>
                        <author>Jack</author>
                        <author>Jill</author>
                        <author>Joe</author>
                        <publisher>&pub;</publisher>
            </titlePage>
            <titlePageVerso>
                        <copyright>Copyright 2010 STC Press</copyright>
                        <publishedBy>&pub;</publishedBy>
                        <ISBN>978-0-596-52722-0</ISBN>
            </titlePageVerso>
            <contents>
                        <chapterName number="1">The Mystery of Lake Toba's origins</chapterName>
                        <chapterName number="2">Volcanic Winter</chapterName>
                        <chapterName number="3">What Toba did to the human race</chapterName>
            </contents>
            <chapter number="1" name="The Mystery of Lake Toba's origins">&chap1;</chapter>
            <chapter number="2" name="Volcanic Winter">&chap2;</chapter>
            <chapter number="3" name="What Toba did to the human race">&chap3;</chapter>
</book>

b.  Provide the accompanying .dtd file
<?xml version="1.0" encoding="UTF-8"?>
        <!ENTITY pub "STC Press, Malta">
        <!ENTITY chap1 SYSTEM "chap1.xml">
        <!ENTITY chap2 SYSTEM "chap2.xml">
        <!ENTITY chap3 SYSTEM "chap3.xml">
        <!ELEMENT book (titlePage, titlePageVerso, contents, chapter+)>
        <!ELEMENT titlePage (bookTitle, author+, publisher)>
        <!ELEMENT bookTitle (#PCDATA)>
        <!ELEMENT author (#PCDATA)>
        <!ELEMENT publisher (#PCDATA)>
        <!ELEMENT titlePageVerso (copyright, publishedBy, ISBN)>
        <!ELEMENT copyright (#PCDATA)>
        <!ELEMENT publishedBy (#PCDATA)>
        <!ELEMENT ISBN (#PCDATA)>
        <!ELEMENT contents (chapterName+)>
        <!ELEMENT chapterName (#PCDATA)>
        <!ATTLIST chapterName number CDATA #REQUIRED>
        <!ELEMENT chapter (text)>
        <!ATTLIST chapter number CDATA #REQUIRED name CDATA #REQUIRED>
        <!ELEMENT text (#PCDATA)>


No comments:

Post a Comment