Saturday, 19 November 2011

CMT3315 - Lab 03 - XML Syntax

Question 1

Write an XML document that contains the following information: your name, your email address, your student number, your home town and your date of birth. Choose appropriate tags. Use attributes for the date of birth.

Answer

<?xml version="1.0" ?>
<students>
     <student dateOfBirth="26-08-1988">
          <name>Daniel Vella</name>
          <email>daniel.vella@domain.com</email>
          <studentNumber>M123456789</studentNumber>
          <town>Zabbar</town>
     </student>
</students>

Question 2

Have a look at the XML document below. Identify all the syntax errors.

Answer

I have highlighted all lines in the XML document in RED, including a GREEN line describing what is wrong. I have also included a corrected valid XML version of this document at the end.

<?xml version= “1.0” ?>
<!DOCTYPE countryCollection SYSTEM "countryList.dtd">
<CountryList>
No corresponding closing tag </CountryList>
     <Nations TotalNations ="3"/>
     No corresponding closing tag </Nations>
     <!--Data from CIA --Year Book -->
     <Country CountryCode="1">
     Closing tag </country> does not match opening tag </country> - XML is case sensitive
          <OfficialName>United States of America</officialName>
          Opening tag <OfficialName> does not match closing tag </officialName> - XML is 
          case sensitive
          <Label>Common Names:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <CommonName>United States</commonName>
Opening tag <CommonName> does not match closing tag </commonName> - XML is
          case sensitive
         <CommonName>U.S.</commonName>
Opening tag <CommonName> does not match closing tag </commonName> - XML is
          case sensitive
          <Label>Capital:</capital>
         <Capital cityNum="1">Washington, D.C. </label>
          Label tag must be closed with a corresponding </Label> tag not </capital>
          <Capital> tag must be closed with a corresponding </Capital> tag not </label>
          <2ndCity cityNum="2">New York </2ndCity>
Tag names must always start with an alphabet character
          <Label>Major Cities:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <MajorCity cityNum="3">Los Angeles </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
          case sensitive
         <MajorCity cityNum="4">Chicago </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
         <MajorCity cityNum="5'>Dallas </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
         Opening double quotes must be closed with double quotes
         <Label>Bordering Bodies of Water:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
          <BorderingBodyOfWater> Atlantic Ocean </borderingBodyOfWater>
Opening tag < BorderingBodyOfWater> does not match closing 
tag </ borderingBodyOfWater> - XML is case sensitive
         <BorderingBodyOfWater> Pacific Ocean </borderingBodyOfWater> 
Opening tag < BorderingBodyOfWater> does not match closing
tag </ borderingBodyOfWater> - XML is case sensitive
         <BorderingBodyOfWater> Gulf of Mexico </borderingBodyOfWater>
Opening tag < BorderingBodyOfWater> does not match closing 
tag </ borderingBodyOfWater> - XML is case sensitive
          <Label>Bordering Countries:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
          <BorderingCountry CountryCode="1"> Canada </borderingCountry>
Opening tag < BorderingCountry> does not match closing
tag </ borderingCountry> - XML is case sensitive
         <BorderingCountry CountryCode ="52"> Mexico </borderingCountry>
Opening tag < BorderingCountry> does not match closing 
tag </ borderingCountry> - XML is case sensitive
     </country>
     Closing tag </country> does not match opening tag </country> - XML is case sensitive
      <Country CountryCode="81">
     Closing tag </country> does not match opening tag </country> - XML is case sensitive
         <OfficialName> Japan </officialName>
          Opening tag <OfficialName> does not match closing tag </officialName> - XML is 
          case sensitive
         <Label>Common Names:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <CommonName> Japan </commonName>
Opening tag <CommonName> does not match closing tag </commonName> - XML is
          case sensitive
         <Label>Capital:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <Capital>Tokyo</capital cityNum="1">
Opening tag < Capital> does not match closing tag </ capital > - XML is case sensitive
         attributes are not allowed in closing tags
          <2ndCity cityNum="2">Osaka </2ndCity>
Tag names must always start with an alphabet character
         <Label>Major Cities:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <MajorCity cityNum="3">Nagoya </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
         <MajorCity cityNum="4">Osaka </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
          <MajorCity cityNum="5'>Kobe </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
         Opening double quotes must be closed with double quotes
         <Label>Bordering Bodies of Water:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <BorderingBodyOfWater>Sea of Japan </borderingBodyOfWater>
Opening tag < BorderingBodyOfWater> does not match closing 
tag </ borderingBodyOfWater> - XML is case sensitive
         <BorderingBodyOfWater>Pacific Ocean </borderingBodyOfWater>
Opening tag < BorderingBodyOfWater> does not match closing 
tag </ borderingBodyOfWater> - XML is case sensitive
      </country>
     Closing tag </country> does not match opening tag </country> - XML is case sensitive
     <Country CountryCode="254">
     Closing tag </country> does not match opening tag </country> - XML is case sensitive
         <OfficialName> Republic of Kenya </officialName>
          Opening tag <OfficialName> does not match closing tag </officialName> - XML is 
          case sensitive
         <Label>Common Names:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <CommonName> Kenya </commonName>
Opening tag <CommonName> does not match closing tag </commonName> - XML is
          case sensitive
         <Label>Capital:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <Capital cityNum='1'>Nairobi </capital>
Opening tag < Capital> does not match closing tag </ capital > - XML is case sensitive
         <2ndCity cityNum='2'>Mombasa</2ndCity>
Tag names must always start with an alphabet character
         <Label>Major Cities:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <MajorCity cityNum='3'>Mombasa </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
         <MajorCity cityNum='4'>Lamu </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
         <MajorCity cityNum='5'>Malindi </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
         <MajorCity cityNum='6' cityNum='7'>Kisumu-Kericho </majorCity>
Opening tag < MajorCity> does not match closing tag </ majorCity> - XML is
case sensitive
Duplicate attributed cityNum not allowed in XML
         <Label>Bordering Bodies of Water:</label>
Opening tag < Label> does not match closing tag </ label > - XML is case sensitive
         <BorderingBodyOfWater <!--Also Lake Victoria --> > Indian Ocean
          </borderingBodyOfWater>
Opening tag < BorderingBodyOfWater> does not match closing 
tag </ borderingBodyOfWater> - XML is case sensitive
          <BorderingBodyOfWater tag not closed properly
          Comments not allowed inside <tags>
          Special characters such as < and > need to be escaped when used in XML as text
      </country>
  Closing tag </country> does not match opening tag </country> - XML is case sensitive



Corrected XML document

<?xml version= “1.0” ?>
<!DOCTYPE countryCollection SYSTEM "countryList.dtd">
<CountryList>
    <Nations TotalNations ="3">
        <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>
            <BorderingBodyOfWater>Lake Victoria</BorderingBodyOfWater>
        </Country>
    </Nations>
</CountryList>

No comments:

Post a Comment