Wednesday 23 November 2011

Task 5


Write an XML document that contains the following information: your name. Your email address. Your student number. Your home town. Your date of birth. Choose appropriate tags. Use Attributes for the date of birth.
<?xml version="1.0"?>
<student>
    <name>Mihai</name>
    <surname>Rotaru</surname>
    <email>MR917@live.mdx.ac.uk</email>
    <student_id>M00292261</student_id>
    <home_town>Iasi</home_town>
    <date_of_birth day="16" month="August" year="1988"></date_of_birth>
</student>
Have a look at the XML document below. Identify all the syntax errors.


<?xml version= “1.0” ?>
<!DOCTYPE countryCollection SYSTEM "countryList.dtd">
<CountryList>
<Nations TotalNations =”3”/>
<!--Data from CIA --Year Book -->
            <Country CountryCode=”1”>
                        <OfficialName>United States of America</officialName>
                        <Label>Common Names:</label>                
                        <CommonName>United States</commonName>
                        <CommonName>U.S.</commonName>
                        <Label>Capital:</capital>                  
                        <Capital cityNum=”1”>Washington, D.C. </label>
                        <2ndCity cityNum=”2”>New York </2ndCity>         
                        <Label>Major Cities:</label> 
                        <MajorCity cityNum=”3”>Los Angeles </majorCity>
                        <MajorCity cityNum=”4”>Chicago </majorCity>                  
                        <MajorCity cityNum=”5’>Dallas </majorCity>                      
                        <Label>Bordering Bodies of Water:</label>                                     
                        <BorderingBodyOfWater> Atlantic Ocean </borderingBodyOfWater>
                        <BorderingBodyOfWater> Pacific Ocean </borderingBodyOfWater>                    
                        <BorderingBodyOfWater> Gulf of Mexico </borderingBodyOfWater>       
                        <Label>Bordering Countries:</label>                        
                        <BorderingCountry CountryCode=”1”> Canada </borderingCountry>                                            
                        <BorderingCountry CountryCode =”52”> Mexico </borderingCountry>
</country>
            <Country CountryCode=”81”>
                        <OfficialName> Japan </officialName>
                        <Label>Common Names:</label>                                        
                        <CommonName> Japan </commonName>
                        <Label>Capital:</label>                     
                        <Capital>Tokyo</capital cityNum=”1”>
                        <2ndCity cityNum=”2”>Osaka </2ndCity>
                        <Label>Major Cities:</label>                                     
                        <MajorCity cityNum=”3”>Nagoya </majorCity>
                        <MajorCity cityNum=”4”>Osaka </majorCity>                    
                        <MajorCity cityNum=”5’>Kobe </majorCity>                       
                        <Label>Bordering Bodies of Water:</label>
                        <BorderingBodyOfWater>Sea of Japan </borderingBodyOfWater>
                        <BorderingBodyOfWater>Pacific Ocean </borderingBodyOfWater>                     
            </country>
            <Country CountryCode=”254”>
                        <OfficialName> Republic of Kenya </officialName>
                        <Label>Common Names:</label>                                        
                        <CommonName> Kenya </commonName>
                        <Label>Capital:</label>                     
                        <Capital cityNum=’1’>Nairobi </capital>
                        <2ndCity cityNum=’2’>Mombasa</2ndCity>
                        <Label>Major Cities:</label>                                     
                        <MajorCity cityNum=’3’>Mombasa </majorCity>
                        <MajorCity cityNum=’4’>Lamu </majorCity>
                        <MajorCity cityNum=’5’>Malindi </majorCity>                     
                        <MajorCity cityNum=’6’ cityNum=’7’>Kisumu-Kericho </majorCity>          
                        <Label>Bordering Bodies of Water:</label>
                        <BorderingBodyOfWater <!--Also Lake Victoria --> > Indian Ocean </borderingBodyOfWater>
            </country>
                                                        
-         wrong type of quotes used throughout the document; ASCII-type quotes should be used ( U+0022 and U+0027 ), instead of the directional quotation marks.
-         The file “countryList.dtd” should be present in the same folder as the XML document, otherwise it cannot be a valid document
-         The word following DOCTYPE must be the same as the root element
-         one type of opening quote, different type used for closing on L17, L36
-         a sequence of more than one dash characters is not allowed within comments ( L5 )
-         On L7, the element “OfficialName” is terminated in the wrong casing, as “officialName”; it should be terminated as “</OfficialName>” – uppercase ‘O’, same as the starting tag.
-         On L11, the <Label> element is opened, but for closing the </capital> tag is used; the closing tag should be </label>
-         On L12, the <Capital> tag should have a matching </Capital> closing tag, instead of </Label>
-         On L13, the element name “2ndCity” is invalid; element names must not begin with numbers (http://www.w3.org/TR/REC-xml/#NT-NameStartChar )
-         Almost all elements in the document have incorrect ending tags – with the first letter in lowercase; the element name should be exactly the same, in both the starting and the ending tags.
-         On L31, the ending tag of the “Capital” element has an attribute – which is illegal. The attribute should be moved in the starting tag.
-         On L52, the “cityNum” attribute is listed twice for the “MajorCity” element; this is illegal, each attribute is allowed to appear only once ( http://www.w3.org/TR/REC-xml/#sec-starttags ).
-         On L54, a comment appears inside markup; this is illegal (http://www.w3.org/TR/REC-xml/#sec-comments ), it should be moved outside the tag, into the element’s contents.
-         The document should contain one root element, which must have starting and closing tags – so the “CountryList” element must be closed with it’s respective closing tag.

After correcting the errors, the following well-formed document results:
<?xml version= "1.0" ?>
<!--<!DOCTYPE countryCollection SYSTEM "countryList.dtd">-->
<CountryList>
<Nations TotalNations ="3"/>
<!--Data from CIA -Year Book -->
<Country CountryCode="1">
    <OfficialName>United States of America</OfficialName>
    <Label>Common Names:</Label>          
    <CommonName>United States</CommonName>
    <CommonName>U.S.</CommonName>
    <Label>Capital:</Label>         
    <Capital cityNum="1">Washington, D.C. </Capital>
    <SecondCity cityNum="2">New York </SecondCity>  
    <Label>Major Cities:</Label>    
    <MajorCity cityNum="3">Los Angeles </MajorCity>
    <MajorCity cityNum="4">Chicago </MajorCity>     
    <MajorCity cityNum="5">Dallas </MajorCity>      
    <Label>Bordering Bodies of Water:</Label>                  
    <BorderingBodyOfWater> Atlantic Ocean </BorderingBodyOfWater>
    <BorderingBodyOfWater> Pacific Ocean </BorderingBodyOfWater>          
    <BorderingBodyOfWater> Gulf of Mexico </BorderingBodyOfWater>   
    <Label>Bordering Countries:</Label>             
    <BorderingCountry CountryCode="1"> Canada </BorderingCountry>                   
    <BorderingCountry CountryCode ="52"> Mexico </BorderingCountry>
</Country>
<Country CountryCode="81">
    <OfficialName> Japan </OfficialName>
    <Label>Common Names:</Label>                    
    <CommonName> Japan </CommonName>
    <Label>Capital:</Label>         
    <Capital cityNum="1">Tokyo</Capital>
    <SecondCity cityNum="2">Osaka </SecondCity>
    <Label>Major Cities:</Label>                     
    <MajorCity cityNum="3">Nagoya </MajorCity>
    <MajorCity cityNum="4">Osaka </MajorCity>       
    <MajorCity cityNum="5">Kobe </MajorCity>        
    <Label>Bordering Bodies of Water:</Label>
    <BorderingBodyOfWater>Sea of Japan </BorderingBodyOfWater>
    <BorderingBodyOfWater>Pacific Ocean </BorderingBodyOfWater>     
</Country>
<Country CountryCode="254">
    <OfficialName> Republic of Kenya </OfficialName>
    <Label>Common Names:</Label>                    
    <CommonName> Kenya </CommonName>
    <Label>Capital:</Label>         
    <Capital cityNum='1'>Nairobi </Capital>
    <SecondCity cityNum='2'>Mombasa</SecondCity>
    <Label>Major Cities:</Label>                    
    <MajorCity cityNum='3'>Mombasa </MajorCity>
    <MajorCity cityNum='4'>Lamu </MajorCity>
    <MajorCity cityNum='5'>Malindi </MajorCity>     
    <MajorCity cityNum='6'>Kisumu-Kericho </MajorCity>    
    <Label>Bordering Bodies of Water:</Label>
    <BorderingBodyOfWater > <!--Also Lake Victoria -->Indian Ocean</BorderingBodyOfWater>
</Country>
</CountryList>