1. This is a smiley. Is it also a well-formed XML document? Say why. <:-/>
An XML document must always have one root element, the "slimy" is a valid root element which is also a closed element "/" at the end. According to the XML specifications element names may start with a ":" so therefore the above XML is well-formed.
2. What is the difference between well-formed and valid XML?
Well formed XML is XML that follows the general syntactical XML rules, valid XML is XML that apart from being well-formed can also be validated against a DTD or XSD schema successfully.
3. 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.
It is considered good practice to comment XML documents to make it clearer for humans to understand the document structure and since they are ignored by XML parsers they have no effect when the document is machine processed. It is however not advisable to include comments before the document type declaration as this may be interpreted incorrectly.
Longer Questions
1. 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.
<!DOCTYPE textbooks
[
<!ENTITY publisher_Name "Excellent Books Ltd.">
<!ENTITY publisher_Address "21, Cemetery Lane, SE1 1AA, UK">
<!ELEMENT text_book (title_Page, title_Page_Verso, chapter+)>
<!ELEMENT title_Page (title, author, publisher, aphorism?)>
<!ELEMENT title_Page_Verso (publisher_Address, copyright_Notice, ISBN, dedication*)>
<!ELEMENT chapter (section+)>
<!ELEMENT section (body_Text+)>
<!ATTLIST chapter chapter_Number CDATA #REQUIRED chapter_Title CDATA #REQUIRED>
<!ATTLIST section section_Number CDATA #REQUIRED section_Title CDATA #REQUIRED>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT aphorism (#PCDATA)>
<!ELEMENT publisher_Address (#PCDATA)>
<!ELEMENT copyright_Notice (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT dedication (#PCDATA)>
<!ELEMENT body_Text (#PCDATA)>
]>
2. 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.
<?xml version="1.0" ?>
<TouristAttractions>
<TouristAttraction type="art gallery" venue="in-doors">
<District>Central</District>
<YearConstructed>1880</YearConstructed>
<TouristAttraction>
</TouristAttractions>
3. The following is the document element (root element) of an XML document.
a) 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> ?
By using the tag name <targLangPhrase> instead of <russianPhrase> the designers are keeping the XML generic, the same XML schema and subsequent application making use of this data may be reused for translations between any other two languages.
b) Write a suitable prolog for this document.
<?xml version = “1.0” encoding = “utf-8”?>
<!DOCTYPE phraseBook SYSTEM “phraseBook.dtd”>
c) 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)>
d) 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?
It is always advised to specify the character set when dealing with XML especially when dealing with language s other than English, this ensures all systems are able to interpret the content correctly.
No comments:
Post a Comment