Tuesday, November 8, 2011

3 - XML Syntax

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" encoding="UTF-8"?>
<StudentList>
<Student DateOfBirth="03/01/1990">
<Name>Joseph</Name>
<Email>josephpspiteri@gmail.com</Email>
<StudentNo>4444</StudentNo>
<HomeTown>Mosta</HomeTown>
</Student>
</StudentList>

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>       

Corrected version, with some remarks:
  • Line 5 contains an extra "--" which is not permitted
  • Mismatching tags in lines 11 and 12 with "Label" and "Capital"
  • In line 13 and 32, tags cannot start with a number: "2ndCity"
  • Incorrent quotation tags use of ' instead of " at line 17, 36, 46, 47, 49-52.
  • In line 31, the "cityNum" attribute must be placed in the start tag and not the end tag
  • Incorrent use of ";" in line 43. tags must be identical and cannot start with a ";"
  • You cannot have the same attribute twice, as seen in line 52
  • You cannot have comments in a starting tag, as seen in line 54
<?xml version= "1.0" ?>
<!DOCTYPE countryCollection>
<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> Indian Ocean </BorderingBodyOfWater>
                        <!--Also Lake Victoria -->
            </Country>       

No comments:

Post a Comment