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>
<!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 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">
<!ENTITY chapter1 SYSTEM "chapter1.xml">
<!ENTITY chapter2 SYSTEM "chapter2.xml">
<!ENTITY chapter3 SYSTEM "chapter3.xml">
No comments:
Post a Comment