Sunday, 5 February 2012

Lab 10b

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?

The Mozilla Firefox browser would open a link to the resource http://www.thetrams.co.uk/croydon as the text will be considered as a hyper-link and the user will be directed to the website address.

  1. 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?

Although DTD use a different language from XML they are simpler and easier to use but they are limited in the validation they can do, like in the case that one cannot specify data types of elements in DTDs. XML schemas are written in XML code and offer more complex validation options which would not be possible with DTDs. Also XML Schemas have the ability to declare Data Types (such as integer, string or Date), are compatible with other XML Technologies and support namespaces.


Longer question:

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.

Here is the XML Schema for the XML above:

<?xml version=”1.0” encoding=”UTF-8”?>
      <xs:element name = “book”>
           <xs:complexType>
              <xs:sequence>
                 <xs:element name="title" type="xs:string"/>
                 <xs:element name="author" type="xs:string"/>
                 <xs:element name="character" maxOccurs="unbounded">
                      <xs:complexType>
                          <xs:sequence>
                             <xs:element name="name" type="xs:string"/>
                             <xs:element name="friend-of" type="xs:string" minOccurs="0"/>
                             <xs:element name="since" type="xs:date"/>
                             <xs:element name="qualification" type="xs:string"/>
                           </xs:sequence>
                       </xs:complexType>
                   </xs:element>
                </xs:sequence>
                <xs:attribute name="isbn" type="xs:string" use="required"/>
             </xs:complexType>
         </xs:element>
     </xs:schema>

The Root Note is “Book” and since it has multiple elements it is a complex type. The Elements “title” and “author” are simple types and will contain a string. The element “character” is a complex type as it contains 4 elements (“name”, “friend-of”, “since” and “qualification”). The Elements “name”, “friend-of” and “qualification” are all simple types and contain a string. “Friend-of” can occur 0 or more times in the XMl document. “Since” is also a simple type but contains a date. “character” can also appear more than once in the XML as it has the property maxOccurs set at “unbounded”. The Attribute “ISBN” is required and is of type string. In “book” all the elements are in a sequence.

No comments:

Post a Comment