Question 1
Write an XML document that contains of the following information: your name, your e-mail address, your student number, your home town, your date of birth. Choose appropriate tags. Use attributes for the date of birth.
Answer
<?xml version="1.0"?>
<personalProfile>
<id dob="18/01/1986> 012345</id>
<name> Twinky </name>
<email> abc@xyz.com</email>
<studentNumber>00123</studentNumber>
<homeTown> </homeTown>
</personalProfile>
Question 2
Have a look at the XML document and identify all 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</borderingBodyOfWater>
<BorderingCountry CountryCode =”52”> Mexico</borderingBodyOfWater>
</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>
Answer:
Syntax Errors:
No closing tag of the root element. </countryList>
All tags should follow case sensitive, there are a lot of tags like so:
Also some tags are not properly nested and not properly closed. For example this tag is not properly nested <Label>Capital:</capital>. and so is this <Capital cityNum="1"> Washington, D.C </label>. While the following is not properly closed <Label> Capital: </capital> apart from having capslock differences it also isn't the correct label.
Another tag which is a syntax error is <2ndCity cityNum ="2"> Mombosa </2ndCity> this tag is not correct as XML tags can contain numbers but cannot start with a number.
There can't be two same attributes in one tag. <MajorCity cityNum=’6’ cityNum=’7’>Kisumu-Kericho</majorCity> Therefor this is not allowed.
Answer:
Syntax Errors:
No closing tag of the root element. </countryList>
All tags should follow case sensitive, there are a lot of tags like so:
- <OfficialName> U.S </officialName>. This should be fixed to be as following <OfficialName> U.S </OfficialName>
- <Label>Common Names: </label>.This should be fixed to be as following <Label> Common Names</Label>
- <CommonName> U.S </commonName>. This should be fixed to be as following <CommonName> U.S </CommonName>
Also some tags are not properly nested and not properly closed. For example this tag is not properly nested <Label>Capital:</capital>. and so is this <Capital cityNum="1"> Washington, D.C </label>. While the following is not properly closed <Label> Capital: </capital> apart from having capslock differences it also isn't the correct label.
Another tag which is a syntax error is <2ndCity cityNum ="2"> Mombosa </2ndCity> this tag is not correct as XML tags can contain numbers but cannot start with a number.
There can't be two same attributes in one tag. <MajorCity cityNum=’6’ cityNum=’7’>Kisumu-Kericho</majorCity> Therefor this is not allowed.
No comments:
Post a Comment