1. What does XML stand for? And CSS?
XML stands for Extensible Markup Language. CSS stands for Cascading Style Sheets.
2. Is this XML line well-formed? Say why.
<b><i>This text is bold and italid</b></i>
No this XML is not well formed, the </b></i> closing tags need to be inverted to reflect the order they were opened.
3. Is this XML document well-formed? Say why.
<? xml version="1.0" ?>
<greeting>
Hello, World!
</greeting>
<greeting>
Hello Mars too!
</greeting>
No this XML is not well formed, a well formed XML document should only have one root element.
Longer Questions
1. Write an XML document that contains the following information: the name of this course, the name if this building, the name of this room and the start and end times of this session. Choose appropriate tags. Use attributed for the start and end times.
Answer
<?xml version="1.0" ?>
<sessions>
<session start="2011-11-22T18:00:00" end="2011-11-22T21:00:00">
<name>CMT3315</name>
<building>A</building>
<room>4<room>
</session>
</ sessions >
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 bookStock SYSTEM "bookstock.dtd">
<bookstore>
No corresponding </bookstore> close tag
<book category="Cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<1stEdition>2005</1stEdition >
<2ndEdition>2007</2ndEdition >
Tags may not start with numbers
<price>19.99</price currency="pounds sterling">
Closing tags may not contain attributes
</book>
<book category="Children’>
Opening double quotes must be matched by closing double quotes
<title lang="en">Harry Potter and the enormous pile of money</title>
<!—best selling children’s book of the year --2009 -->
<author>J K. Rowling</author>
<1stEdition>2005</1stEdition>
Tags may not start with numbers
<price>29.99</Price>
Opening <price> tag does not match closing </Price tag> - XML is case sensitive
</book>
<book category="Web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<1stEdition>2003</1stEdition>
<2ndEdition >2008</2ndEdition >
Tags may not start with numbers
<price>29.95</discount>
<discount>15%</price>
<price> tag must be closed with </price> tag, <discount> tag must be closed
with </discount>
</book>
<book category="Computing">
<title lang=en>
Insanely great – the life and times of Macintosh, the computer that changed everything
</title>
Attribute values must be enclosed in either single or double quotes
<author <!—other authors not listed -->>Steven Levy</author>
<1stEdition>1994</1stEdition>
Tags may not start with numbers
<price>9.95</discount>
<discount>15%</price>
<price> tag should be closed with </price>, <discount> should be closed
with </discount>
</book>
Corrected XML document
<?xml version= "1.0" ?>
<!DOCTYPE bookStock SYSTEM "bookstock.dtd">
<bookstore>
<book category="Cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<firstEdition>2005</firstEdition>
<secondEdition>2007</secondEdition>
<price currency="GBP">19.99</price >
</book>
<book category="Children">
<title lang="en">Harry Potter and the enormous pile of money</title>
<author>J K. Rowling</author>
<1stEdition>2005</1stEdition>
<price>29.99</price>
</book>
<book category="Web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<firstEdition>2003</firstEdition>
<secondEdition>2008</secondEdition>
<price>29.95</price>
<discount>15%</discount>
</book>
<book category="Computing">
<title lang="en">
Insanely great – the life and times of Macintosh, the computer that changed everything
</title>
<author>Steven Levy</author>
<firstEdition>1994</firstEdition>
<price>9.95</price>
<discount>15%</discount>
</book>
</bookstore>
3. You are asked to produce a Document Type Declaration for a class of XML documents called "memo". You come up with this .dtd file.
Your client says "That's all very well", but every memo has to have a date, and some of them have to have a security classification too (You might want to write "Secret" at the top). And a memo has a serial number - I think that's what you'd call an attribute, isn't it?". How would you amend this .dtd so that it did what the client wanted?
Answer
<!DOCTYPE memo
[
<!ELEMENT memo (date,to,from,heading,body,classification)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ELEMENT classification (#PCDATA)>
<!ATTLIST memo serialNumber ID #REQUIRED>
]>