Saturday, November 6, 2010

Week5

This week's lesson was about character encoding. We saw examples of different types;
UTF-8,  8bit 1byte (standard ASCII set) ISO-8859-1
UTF-16, 16bit 2bytes (Unicode)
UCS-2, 2bytes (Universal Character Set)
UCS-4, 4bytes

example:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
i.e. using ISO... character set and no external DTD file

Special characters (entities)
<   &lt;
>   &gt;
&  &amp;
'    &apos;
"   &quot;
or use <![CDATA[ ... ]]>
or you can also use the unicode as in   &#0128; for the euro symbol
or the unicode hex value as in   &#xFEA1;



CMT3315  –  Lab Session 05

Quick questions:
1.    This is a smiley. Is it also a well-formed XML document? Say why.
<:-/>
No, because its using invalid characters for the label : which should start with a character and can also contain numbers.


2. What is the difference between well-formed and valid XML?
  • well-formed when its using the correct syntax and does not raise an error
  • valid when it conforms to the schema defenition so that it is in the defined structure and declared data types

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.
No, because the first few lines are used by the parser to identify the type of file and any validation required.


Longer questions:
1)
<?xml version="1.0" encoding="UTF-16"?>
 <!DOCTYPE textbook
[
<!ELEMENT titlePage (title, author, publisher, aphorism?>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT publisher (#EMPTY)>
<!ELEMENT aphorism (#PCDATA)>


<!ELEMENT verso (pubAddress, copyright, ISBN, dedication*)>
<!ELEMENT pubAddress (#PCDATA)>
<!ELEMENT copyright (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT dedication (#PCDATA)>


<!ELEMENT chapters (chapter*)>
<!ELEMENT chapter (section*)>
<!ELEMENT section (body*)>
<!ELEMENT body (#PCDATA)>


<!ATTLLIST chapter number CDATA #REQUIRED>
<!ATTLLIST chapter title CDATA #REQUIRED>
<!ATTLLIST section number CDATA #REQUIRED>
<!ATTLLIST section title CDATA #REQUIRED>


<!ATTLIST publisher name CDATA #FIXED "Excellent Books Ltd.">
<!ATTLIST publisher address CDATA #FIXED "21 Cemetry Lane, SE1 1AA, UK.">
]>




2)
<?xml version="1.0" encoding="UTF-16"?>
<city name="London">
  <attraction type="official building" inDoors="YES">
    <name>Best Ride</name>
    <district>District1</district>
    <yearBuilt>1974</yearBuilt>
  </attraction>


  <attraction type="art gallery" inDoors="NO">
    <name>History Items</name>
    <district>District3</district>
    <yearBuilt>1847</yearBuilt>
  </attraction>
</city>


3) re xml document shown;
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> ?
So that it could easily be used for any other language by changing <phraseBook targLang=”Russian”>  to <phraseBook targLang=”other language”>

b)      Write a suitable prolog for this document.

<?xml version="1.0" encoding="UCS-4"?>


c)      Write a .dtd file to act as the Document Type Description for this document.
<?xml version="1.0" encoding="UCS-4"?>
<!DOCTYPE book
[
<!EMEMENT phraseBook (section+)>
<!ELEMENT section (sectionTitle, phraseGroup+)>
<!ELEMENT sectionTitle (#PCDATA)>

<!ELEMENT phraseGroup (engPhrase+, translitPhrase+, targLangPhrase+, gloss?)>

<!ELEMENT engPhrase (#PCDATA)>
<!ELEMENT translitPhrase (#PCDATA)>
<!ELEMENT targLangPhrase (#PCDATA)>
<!ELEMENT gloss (#PCDATA)>

<!ATTLIST phraseBook  targLang CDATA #REQUIRED>
]>

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?
No?



No comments:

Post a Comment