Today we will be covering XML Schemas, this comes from the word databaes. This describes the structure of an XML document, it gives out details of relationships and refers to XML schema definition known as XSD.
An XML Schema defines elements, attributes, child attributes and the order of the child attributes. During the lecture we also watched two short clips about XML Schemas. An XSD always starts with "<xs:schema>" for example <xs:elementName = "basicDocument" type = "xs:string">
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?
This would be treated as a normal XML hyperlink. As the "show" XLink attribute was not specified, clicking this link would load the site replacing the initial site. As seen in the previous blogs, replace is the default setting for this attribute.
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?
Answer
All the things that can be defined within a DTD can be also defined by schema, but not vice versa. XML Schemas provide more control over the documents, within an XML Schema it would be easier to describe what is allowed within the content. An XML Schema can work with namespaces while a DTD can't, therefore it provides more flexibility. Another thing which provides flexibility is that XML Schema provide several different data types like string, integer and also dates and decimal numbers on the other hand DTD only uses two data types PCDATA and CDATA.
With XML one doesn't need to learn a new technology and can use the same XML editor when editing XML files.
Longer Questions
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.
Answer
Before doing the XML Schema one has to analyze what is needed. At a glance once can start by noticing the main things, like <book> is the root note. One needs to identify the data types that will be used.
<author>, <qualification> and <name> are of type string. While <since> is to be classified under <date> as it specifies days range. Book contains an attribute which is the ISBN of the book this should use a numeric data type. One can also notice that <friend-of> is not used in both character nodes, which makes it that <friend-of> is optional to use it. References
No comments:
Post a Comment