Wednesday, 23 November 2011

Week 4 - XML and CSS

Introduction
This week XML entities were covered during the lecture. Entities can be used not only in XML but also in other languages like HTML. In XML an entity is formed using an ampersand followed by the name of the symbol and ending it with a semicolon.  Example: &example;

Some examples of entities are &cope; &alt; and &

There are 3 different types of entities; internal, external and parameter entities. Internal works as a type of shortcuts like macros, external entities work by merging content from other files while parameter entities can be both external and internal.

Coursework
Quick Questions 
Question 1 
What does XML stand for? And CSS?
XML evolved from markup language which stands for Extensible Markup Language which was developed by the world wide consortium. XML is know as Extensible as it allows the creation of tags. 
CSS stands for Cascading Style Sheets which allows you to add styles to websites makes sites more presentable to the users. CSS is a markup language. In HTML styling can be added in-line within HMTL but to make things more understandable styling can be separated into different files and then linked in within the HTML. With CSS instead of chaining that format from each HTML page one has to edit only the CSS page once in order to make the change. 


Question 2 
Is this XML line well-formed? Say why? <b><i> This text is bold and italic </b> </i>
Answer
The above line is not properly coded this is because it does not go with the W3C standards, having an HTML document with proper nesting. An open tag must be closed before the next closing tag. Therefore this line is not well formed since the <b> tag, has the closing tag before the <i>. In order for this line of code to be well formed it has to be: 
<b><i> This text is bold and italic </i></b>

Question 3 
IS this XML document well-formed? Say why?
<?xml version "1.0"?>
          <greeting>Hello World! </greeting/>
          <greeting> Hello Mars too! </greeting>
Answer
This XML document is not well formed, as XML documents can only contain one root element. There cannot be an XML with duplicate root elements hence this is not well-formed. For this document to be well formed it must be as following: 

<salutations>
             <greeting> Hello World!</greeting>
             <greeting> Hello Mars too</greeting>
</salutations>

Longer Questions 
1. Write an XML document that contains the following information: the name of this course. The name of this building. The name of this room. The start and end times of this session. Choose appropriate tags. Use attributes for the start and end  times. 

<?xml version = "1.0"?>
<course>
<coName> Internet Application and Development</coName>
   <module>
     <moduleName> CMT3315 </moduleName>
     <buildingName> STC </buildingName>
     <roomNumber> Room 4 </roomNumber>
     <moduleDate start="20/09/11" end="20/04/2012"/>
     <moduleTime start = "18:00" end = "21:00"/>
  </module>
</course>
Question 2 
Have a look at the XML document below. Identify all the syntax errors. 
Answer
Below are the syntax errors: 
  • The first line of syntax which is the declaration is not pointing to the correct root tag. The root should be called "bookStock" as it is specified in the DOCTYPE declaration and then there should be a closing tag. 
  • The next error which was found is the element names starting with numerics are invalid.  There are two elements called <1stEdition> and <2ndEdition> both tags are incorrect. 
  • Another error was placed within an element, the attribute "currency" was placed in the closing tag, attributes should be placed in the opening tag.
  • On line 11 the element <book category = "Children'> is not correct as attributes are to be enclosed within double quotes
  • There are a lot of mismatching start and ending tags at several different lines. These are found on line 16, 23, 24, 30 and also line 31
  • Another error is that XML is case sensitive, on line 16 there is an element the opening is lower case while the closing tag is upper case
  • The comment on line 13 is not types properly. Comments are to use "--" instead of "_"
  • On line 31 there is a "price" opening tag and a "discount" closing tag any opening tag must be closed before any other tag is opened.
  • On line 28 comments cannot start inside an element and as already stated above comments start by "<!--"
  • Attribute on line 27 must be in double quotes
  • The root element <bookstore> was not closed. 
Question 3 
You are asked to produce a DTD for a class of XML documents called "memo". You come up with this .dtd file: 
<!DOCTYPE memo
[
<!ELEMENT memo (to, from, heading, body)>
<!ELEMENT to (#PCDATA)>

<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENTbody (#PCDATA)>
]>

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 wrtie "Secret" at the top). And a memo has a serial number-I think thats what you'd call an attribute isn't it?" How would you amend this .dtd file so that it did what the client wanted?
Answer 

<!DOCTYPE memo
[
<!ELEMENT memo (to, from, heading, body, classification)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT classification (#PCDATA)>
<!ATTLIST memo classification PCDATA "Secret">
<!ATTLIST memo serialNum ID #REQUIRED>
]>

References:


No comments:

Post a Comment