Pages

Banner 468

Saturday, 28 January 2012

CMT3315 Lab 11 - XML Schemas

0 comments
 

Today's post answers questions related to XML Schemas.

You can download the complete lab questions from here.

Quick Questions

1. The following passage is to be found in the middle of a particular XML document:

  The heavily-used<service xlink:type = "simple" xlink:href ="http://www.thetrams.co.uk/croydon"> Croydon Tramlink </service> provides a cross link to nearby <location>Wimbledon</location>, <location>Addington</location> and <location>Beckenham</location>.
 

What can you say about how the text Croydon Tramlink will be treated by a browser such as Mozilla Firefox?

A web browser would treat the text "Croydon Tramlink" as a hyperlink. Since the "show" XLink attribute was not specified, clicking the link would load the ending resource in the same browser window, entirely replacing the starting resource. This is because the default behaviour of the "show" XLink attribute is in fact "Replace".


2. It’s possible to provide validation for a class of XML document using a Document Type Definition (.dtd) file, or using an XML schema. The DTD approach is easier. Why might you want to use the XML schema approach?

Just like a DTD, an XML schema provides a way of defining the basic structure of an XML document. XML Schemas however offer developers much more control on what the document can and cannot contain, and does so in an object oriented approach. In contrast to DTD's basic CDATA and PCDATA data types, XML Schemas offer data types such as integer, string, dates and decimal numbers. Furthermore, these basic types can be used by a developer to define more complex types.

XML Schemas become essential for validating data contained in XML documents, especially where that data is destined to be stored in a database.


Longer Questions
The answers to the longer questions are given below. Please refer to the Lab 10a handout for the questions themselves.

1a. Here is an XML document:

  <?xml version="1.0" encoding="UTF-8"?> 
  <book isbn="0836217462"> 
   <title> Being a Dog Is a Full-Time Job </title> 
   <author>Charles M. Schulz</author> 
   <character>
    <name>Snoopy</name>
    <friend-of>Peppermint Patty</friend-of> 
    <since>1950-10-04</since>
    <qualification> extroverted beagle </qualification>
   </character>
   <character>
    <name>Peppermint Patty</name>
    <since>1966-08-22</since>
    <qualification>bold, brash and tomboyish</qualification>
   </character>
  </book>
 

An XML schema is to be constructed, which will validate this document and other similar documents. Make notes on the elements etc that this document contains, and record any significant factors about them.

The first step in designing an XML Schema for an XML document, is to analyse the contents of the XML document itself to identify suitable data types. In addition the structure of the XML document dictates the complex data types that will need to be constructed.

For instance, in the example above, most elements contain strings. One noticable exeption is the "<since>" element which holds a date and the "<book>" element's "ISBN" attribute which holds numerical data. Furthermore, the "<book>" and "<character>" elements are complex types made up of other elements of simple types. We can also notice that the "<friend-of>" element is optional and refers to a "<character>" element.


Leave a Reply