QUICK QUESTIONS
The following passage is to be found in the middle of a particular XML document:
The text 'Craydon Tramlink' will be treated as a link, which will be redirected to 'http://www.thetrams.co.uk/croydon'. It will be treated like this because it contains the
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?xlink:hrefattribute.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?
As already explained in previous a previous post, a Document Type Definition (DTD) is used to describe how an XML document should be constructed. A DTD is used to validate an XML document. Although the DTD is easier, it also has limitations and therefore an alternative to DTD is an XML schema. Some benefits of XML schema over DTD are the following[1]:
- XML schemas include data types and namespaces;
- XML schemas are written using XML;
- XML schemas are more powerful.
LONGER QUESTIONS
Here is an XML document:
The datatypes of the above elements are:
<?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.
- title - string
- author - string
- charater - string
- name - string
- friend-of - string
- since - date
- qualification - string
The XML schema produced above consists of1: <?xml version="1.0"?> 2: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 3: <xs:element name="book"> 4: <xs:complexType> 5: <xs:sequence> 6: <xs:element name="title" type="xs:string"/> 7: <xs:element name="author" type="xs:string" maxOccurs="unbounded"/> 8: <xs:element name="character" type="xs:string" maxOccurs="unbounded"> 9: <xs:complexType> 10: <xs:sequence> 11: <xs:element name="name" type="xs:string"/> 12: <xs:element name="friend-of" type="xs:string" minOccurs="0"/> 13: <xs:element name="since" type="xs:string"/> 14: <xs:element name="qualification" type="xs:string"/> 15: </xs:sequence> 16: </xs:complexType> 17: </xs:element> 18: </xs:sequence> 19: </xs:attribute name="isbn" type="xs:string" use="required"/> 20: </xs:complexType> 21: </xs:element> 22: </xs:schema>maxOccursandminOccursattributes. In the "character" element and the "author" element, themaxOccursattribute have been set to "unbounded" because there might be many occurences of the "character" element. The element "friend-of" have theminOccursattribute set to zero because the element is optional.
Question Sheet:
Question Sheet: Lab 10bSources:
[1] http://www.w3schools.com/schema/schema_intro.asp[2] http://www.w3schools.com/schema/schema_example.asp