Tuesday, 15 March 2011

Week 4 - Introduction to XML

Introduction
For the fourth week, we were introduced to XML. XML stands for eXtensible Markup Language. This is a markup language because one can invent entities which mean something. Some research was made on XML using http://www.w3schools.com/xml. XML was designed to carry data and not to display. XML and HTML are different then each other, XML is used to store data while HTML is used to display data. In XML you predefine your own tags, there aren't tags that are XML standards. XML syntax are case sensitive.

XML documents starts with declaring the XML versionThe first tag is the root element which describes what the document is.Example: <mail> that means that the document is a mail the next tags are the child elements of the root. 

DTD which stands for document type definition describes the XML file, it defines the structure with a list of legal elements.

Task 
This weeks task was to create a file about a school project having student name, student Id, project title, project category, abstract and date submitted. We had to try use both elements and attributes to describe the data. Then we had to validate the XML using a W3Schools Validator. After that create a DTD to describe the XML file and validate the DTD too.

XML Document


Above is the code for the XML document. The root element is the project element meaning that this document is about a project. Student is the child element of  the project element and contains the student tag. Both attributes and element needed to be used so in student name and Id where used as the attributes of student. Each student will give the project a title, the category, abstract and what date it was submitted since each student will have a project.

DTD Schema
On the right hand side is the code for the DTD for the XML document in the above section. The <!ELEMENT> tag declares an element with the following syntax. <!ELEMENT element-name category>. Therefore first comes the element tag then you write the name of that element then in the brackets the sub elements are written if there isn't any sub elements you write what data type is expected. Some elements show (#PCDATA) that means that elements with only parsed character data are declared. <!ATTLIST> is the tag which is used to declare the attributes together with the name of that attribute. #REQUIRED states that that element is to be included. 

Both XML and DTD where tested in w3schools validators. 
Schema
Further more to XML and DTD there is also the Schema this is used to describe the structure of the XML Schema in detail like stating which are the child elements and there order which is an empty element and which element includes text and more. Since the XML contained both elements and attributes the Schema has elements for the <!ELEMENT> and others for th <!ATTLIST>. The element date submitted on line 9 is of type date since it will output a date format. 

No comments:

Post a Comment