QUICK QUESTIONS
What exactly does a DTD do in XML?
In XML, DTD is used to define the structure of the XML document[1]. In order to have a valid XML document, it should follow the restrictions which have been specified in the DTD.[2]You’ve written an XML document, with the XML declaration <?xml version= "1.0"?> at the start. You realize that the text contains some arabic characters. Which of the following should you do:
Do nothing, the declaration is fine as it is. This is because if the encoding attribute is left out, by default it will be UTF-8.
- change the XML declaration to <?xml version= "1.0" encoding="ISO 8859-6"?>
- change the XML declaration to <?xml version= "1.0" encoding="UTF-8"?>
- do nothing: the declaration is fine as it is.
- change the XML declaration to <?xml version= "1.0" encoding="ISO 8859-6"?>
Can you use a binary graphics file in an XML document?
Yes binary graphics can be used in an XML document. This will be done by using the NDATA keyword and the format code (gif, jpeg etc). Example:[3]<!ENTITY colliepic SYSTEM "lassie.jpg" NDATA JPEG>
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:
Toba: the worst volcanic eruption of all
John Platts
Jack Brilliant
Jill Bright
Joe Clever
STC Press
Malta
Copyright © 2010
STC Press
Published by STC Press Ltd., Malta
ISBN: 978-0-596-52722-0Contents
Chapter 1: The mystery of Lake Toba’s origins
Chapter 2: Volcanic winter
Chapter 3: What Toba did to the human raceThen I construct an XML document that encompasses the whole book.
To avoid conflicts on element names, namespaces have been used. The following is the XML file:- Provide this XML document
- Provide the accompanying .dtd file
The following is the DTD file:1: <?xml version="1.0" ?> 2: <!DOCTYPE b:book SYSTEM "book.dtd"> 3: <b:book xmlns:b="http://middlesex_press.co.uk/book"> 4: <tp:titlePage xmlns:tp="http://middlesex_press.co.uk/title_page"> 5: <tp:title>Toba: the worst volcanic eruption of all</tp:title> 6: <tp:authors> 7: <tp:author> 8: <tp:firstName>John</tp:firstName> 9: <tp:lastName>Platts</tp:lastName> 10: </tp:author> 11: <tp:author> 12: <tp:firstName>Jack</tp:firstName> 13: <tp:lastName>Brlliant</tp:lastName> 14: </tp:author> 15: <tp:author> 16: <tp:firstName>Jill</tp:firstName> 17: <tp:lastName>Bright</tp:lastName> 18: </author> 19: <tp:author> 20: <tp:firstName>Joe</tp:firstName> 21: <tp:lastName>Clever</tp:lastName> 22: </tp:author> 23: </tp:authors> 24: <tp:publisher>STC Press</tp:publisher> 25: <tp:location>Malta</tp:location> 26: </tp:titlePage> 27: <tps:titlePageVerso xmlns:tpv="http://middlesex_press.co.uk/title_page_verso> 28: <tps:copyright>Copyright © 2010</tps:copyright> 29: <tps:publisher>STC Press</tps:publisher> 30: <tps:publishedBy>STC Press Ltd, Malta</tps:publishedBy> 31: <tps:ISBN>978-0-596-52722-0</tps:ISBN> 32: </tps:titlePageVerso> 33: <c:contents xmlns:c="http://middlesex_press.co.uk/conents> 34: <c:chapter num="1" title="The mystery of Lake Toba's origins"/> 35: <c:chapter num="2" title="Volcanic winter"/> 36: <c:chapter num="3" title="What Toba did to the human race"/> 37: </c:contents> 38: <ch:chapters xmlns:ch="http://middlesex_press.co.uk/chapters 39: <ch:chapter num="1" title="The mystery of Lake Toba's origins"> &ch1; <ch:chapter> 40: <ch:chapter num="2" title="Volcanic winter"/> &ch2; </ch:chapter> 41: <ch:chapter num="3" title="What Toba did to the human race"/> &ch3; </ch:chapter> 42: </ch:chapters> 43: </b:book>1: <!DOCTYPE b:book [ 2: <!ELEMENT b:book (tp:titlePage, tpv:titlePageVerso, c:contents)> 3: <!ELEMENT tp:titlePage (tp:title, tp:authors, tp:publisher, tp:location)> 4: <!ELEMENT tpv:titlePageVerso (tpv:copyright, tpv:publisher, tpv:publishedBy, tpv:ISBN) 5: <!ELEMENT c:contents (c:chapter+)> 6: <!ELEMENT ch:chapters(c:chapter+)> 7: <!ELEMENT tp:title (#PCDATA)> 8: <!ELEMENT tp:authors (tp:author+)> 9: <!ELEMENT tp:publisher (#PCDATA)> 10: <!ELEMENT tp:location (#PCDATA)> 11: <!ELEMENT tp:author (tp:firstName, tp:lastName)> 12: <!ELEMENT tp:firstName (#PCDATA)> 13: <!ELEMENT tp:lastName (#PCDATA)> 14: <!ELEMENT tpv:copyright (#PCDATA)> 15: <!ELEMENT tpv:publisher (#PCDATA)> 16: <!ELEMENT tpv:publishedBy (#PCDATA)> 17: <!ELEMENT tpv:ISBN (#PCDATA)> 18: <!ELEMENT c:chapter (#PCDATA)> 19: <!ELEMENT ch:chapter (#PCDATA)> 20: <!ATTLIST b:book xmlns:b CDATA #FIXED "http://middlesex_press.co.uk/book"> 21: <!ATTLIST tp:titlePage xmlns:tp CDATA #FIXED "http://middlesex_press.co.uk/title_page"> 22: <!ATTLIST tpv:titlePageVerso xmlns:tpv CDATA #FIXED "http://middlesex_press.co.uktitle_page_verso/"> 23: <!ATTLIST c:contents xmlns:c CDATA #FIXED "http://middlesex_press.co.uk/contents"> 24: <!ATTLIST ch:chapters xmlns:ch CDATA #FIXED "http://middlesex_press.co.uk/chapters"> 25: <!ATTLIST c:chapter num CDATA #REQUIRED> 26: <!ATTLIST c:chapter title CDATA #REQUIRED> 27: <!ATTLIST ch:chapter num CDATA #REQUIRED> 28: <!ATTLIST ch:chapter title CDATA #REQUIRED> 29: <!ENTITY ch1 SYSTEM "chap1.xml"> 30: <!ENTITY ch2 SYSTEM "chap2.xml"> 31: <!ENTITY ch3 SYSTEM "chap3.xml"> 32: ]>
Question Sheet:
Question Sheet: Lab 6Sources:
[1] http://www.w3schools.com/xml/xml_dtd.asp[2] http://www.informit.com/guides/content.aspx?g=xml&seqNum=223
[3] http://xml.silmaril.ie/graphics.html