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.
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 author (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT aphorism (#PCDATA)>
<!ELEMENT aphorism (#PCDATA)>
<!ELEMENT titlePageVerso (publisherAddress, copyrightNotice, ISBN, dedication*)>
<!ELEMENT address (#PCDATA)>
<!ELEMENT copyrightNotice (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT dedication (#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">
<!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>
</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>
</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)>
<!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.