A schema for recipesThe following is a complete schema for the recipe example, written in the DSD schema language:... XML: XLink, XPointer, and XPathXLink, XPointer, and XPath are three
Trang 1The recipe exampleSchema languages
A schema for recipesXLink, XPointer, and XPathPointing at recipes
XML-QLQuerying the recipesXSLT
A style sheet for recipesExercises
XML Mini-Tutorial
http://www.brics.dk/~mis/ITU/XML/ [18/09/2000 14:24:26]
Trang 3What is XML?
XML is a framework for defining markup languages:
there is no fixed collection of markup tags;
XML is not a replacement for HTML:
HTML should ideally be just another XML language;
Trang 4Rhubarb Cobbler made with bananas as the main sweetener
It was delicious Basicly it was
Combine all and use as cobbler, pie, or crisp
Related recipes: <a href="#GardenQuiche">Garden Quiche</a>
There are many problems with this approach:
the semantics is encoded into text formatting tags;
It would be much better to invent a special recipe markup language:
<recipe id="117" category="dessert">
<title>Rhubarb Cobbler</title>
<author><email>Maggie.Herrick@bbs.mhv.net</email></author> <date>Wed, 14 Jun 95</date>
Trang 5This example illustrates:
the markup tags are chosen purely for logical structure;
Trang 7A concrete view of XML
An XML document is a (Unicode) text with markup tags and other meta-information
Markup tags denote elements:
.<foo attr="val" > </foo>
| | | |
| | | a matching element end tag
| | the contents of the element
| an attribute with name attr and value val, values enclosed by ' or "
an element start tag with name foo
There is a short-hand notation for empty elements: <foo attr="val" />
Note: XML is case sensitive!!
An XML document must be well-formed:
start and end tags must match;
Special characters can be escaped using Unicode character references:
& yields &;
The strange syntax is a legacy from SGML
The following service checks well-formedness of an XML document (given a full URL):
XML: a concrete view
http://www.brics.dk/~mis/ITU/XML/concrete.html [18/09/2000 14:24:32]
process clear
Trang 9XML technologies
Just a notation for trees is not enough:
the real force of XML is generic languages and tools!
- grammars to define classes of documents;
linking between documents
- a generalization of HTML anchors and links;
addressing parts of documents
- it is not enough that only the author can place anchors;
Trang 10We have some problems here:
the meaning of head and big depends on the context;
Do not be confused by the use of URI for namespaces:
they are not supposed to point to anything;
Trang 11we rely on existing organizations that control domain names.
●
All XML technologies (are supposed to) respect namespaces
XML: namespaces
http://www.brics.dk/~mis/ITU/XML/namespaces.html (2 of 2) [18/09/2000 14:24:35]
Trang 12The recipe example
Consider the following raw data describing some (Danish) recipes:
Trang 13Schema languages
The syntax of a new XML language must be formalized:
this is similar to the formal syntax of a programming language;
A modern schema language:
is itself an XML language (and can be used to describe itself);
Trang 14A schema for recipes
The following is a complete schema for the recipe example, written in the DSD schema language:
<AttributeDecl Name="kvantitet" Optional="no"/>
<AttributeDecl Name="tid" Optional="yes"/>
Trang 15<AttributeDecl Name="navn" Optional="no"/>
<AttributeDecl Name="antal" Optional="yes">
Trang 16<Else>
<Not><Attribute Name="enhed"/></Not> <Content IDRef="indhold"/>
Trang 17XML: XLink, XPointer, and XPath
XLink, XPointer, and XPath are three related mechanisms:
they generalize the link mechanisms from HTML;
HTML links are just too simple:
an anchor must be placed at every link destination (problem with read-only documents)
- we want to express relative locations;
●
the link definition must be at the same location as the link source
- we want out-of-line links ("link databases");
●
only individual nodes can be linked to
- we want links to whole tree fragments;
●
a link always has one source and one destination
- we want links with multiple sources and destinations.
●
The XLink pointer model looks like this:
These technologies are not really supported by any browsers today
XML: XLink, XPointer, and XPath
http://www.brics.dk/~mis/ITU/XML/xpath.html [18/09/2000 14:24:38]
Trang 18Pointing at recipes
The following simple XPath expressions point to parts of the XML recipe document:
//ingrediens[@navn="radiser i små tern"]/@antal
200
//ingrediens[@antal="100" and @enhed="g"]/@navn
flødeost med løg og urter
og saml hurtigt dejen Tryk den ud i en smurt springform (ca 22 cm
i diameter) Lad dejen gå halvt op ad formens side Stil den
tildækket i køleskabet i mindst 1 time Forbag bunden midt i ovnen
i 12 minutter ved 200 grader
XPath expressions navigate step by step through the XML tree
XML: pointing at recipes
http://www.brics.dk/~mis/ITU/XML/xpathrecipe.html [18/09/2000 14:24:39]
Trang 19XML-QL is a query language for XML documents:
XML document can be seen as generalizations of database relations;
Relations are special, restricted cases of XML trees:
XML query languages are not released until 2001
XML: XML-QL
http://www.brics.dk/~mis/ITU/XML/xmlql.html [18/09/2000 14:24:40]
Trang 20Querying the recipes
The following XML-QL queries extract information from the XML recipe document:
<titel>Hornfisk med radisesalat</titel>
<titel>Islagkage med chokolade</titel>
<titel>Rabarberdessert med jordbær</titel>
Trang 21<?xml version="1.0"?>
<opskriftermedsukker>
<navn>Citrontærte</navn>
<navn>Islagkage med chokolade</navn>
<navn>Rabarberdessert med jordbær</navn>
<ingrediens navn="jordbær i skiver">
<ret>Rabarberdessert med jordbær</ret>
Trang 22<ret>Rabarberdessert med jordbær</ret>
<ret>Islagkage med chokolade</ret>
<ret>Rabarberdessert med jordbær</ret>
<ret>Græsk farsbrød og agurkesalat</ret>
<ret>Græsk farsbrød og agurkesalat</ret>
<ret>Hornfisk med radisesalat</ret>
Trang 23<ret>Laksemousse</ret>
</ingrediens>
<ingrediens navn="knust fed hvidløg">
<ret>Græsk farsbrød og agurkesalat</ret> </ingrediens>
<ingrediens navn="groft salt">
<ingrediens navn="Feta ost 45+">
<ret>Græsk farsbrød og agurkesalat</ret> </ingrediens>
<ingrediens navn="frisk, rød chilipeber"> <ret>Filokurve med tigerrejer</ret>
</ingrediens>
<ingrediens navn="tørret basilikum">
<ret>Smørrebrød med flødeost og tomat</ret> </ingrediens>
<ingrediens navn="lille hakket zittauerløg"> <ret>Græsk farsbrød og agurkesalat</ret> </ingrediens>
<ingrediens navn="smør">
<ret>Filokurve med tigerrejer</ret>
<ret>Græsk farsbrød og agurkesalat</ret> </ingrediens>
<ingrediens navn="hakket hvidløgsfed">
<ret>Filokurve med tigerrejer</ret>
</ingrediens>
<ingrediens navn="creme fraiche">
<ret>Filokurve med tigerrejer</ret>
Trang 24<ret>Islagkage med chokolade</ret>
</ingrediens>
<ingrediens navn="smeltet overtrækschokolade">
<ret>Islagkage med chokolade</ret>
</ingrediens>
<ingrediens navn="agurk">
<ret>Filokurve med tigerrejer</ret>
</ingrediens>
<ingrediens navn="udbenet hornfisk">
<ret>Hornfisk med radisesalat</ret>
<ingrediens navn="frisk, klippet purløg">
<ret>Hornfisk med radisesalat</ret>
</ingrediens>
<ingrediens navn="jordbærskiver">
<ret>Rabarberdessert med jordbær</ret>
</ingrediens>
<ingrediens navn="limefrugt i halve skiver">
<ret>Filokurve med tigerrejer</ret>
</ingrediens>
<ingrediens navn="creme fraiche 18%">
<ret>Hornfisk med radisesalat</ret>
</ingrediens>
<ingrediens navn="friske, hakkede citronmelisseblade">
<ret>Filokurve med tigerrejer</ret>
<ingrediens navn="agurk i små tern">
<ret>Hornfisk med radisesalat</ret>
</ingrediens>
<ingrediens navn="cherrytomater i skiver">
<ret>Smørrebrød med flødeost og tomat</ret>
</ingrediens>
<ingrediens navn="magert, hakket svinekød">
<ret>Græsk farsbrød og agurkesalat</ret>
</ingrediens>
<ingrediens navn="flødeost med løg og urter">
<ret>Smørrebrød med flødeost og tomat</ret>
XML: querying the recipes
http://www.brics.dk/~mis/ITU/XML/xmlqlrecipe.html (5 of 7) [18/09/2000 14:24:42]
Trang 25<ingrediens navn="hakket lammekød">
<ret>Græsk farsbrød og agurkesalat</ret>
<ingrediens navn="parboiled ris">
<ret>Græsk farsbrød og agurkesalat</ret>
</ingrediens>
<ingrediens navn="blødt smør i mindre stykker"> <ret>Citrontærte</ret>
</ingrediens>
<ingrediens navn="iskold piskefløde">
<ret>Rabarberdessert med jordbær</ret>
Trang 26<ingrediens navn="radiser i små tern"> <ret>Hornfisk med radisesalat</ret>
Trang 27An XSLT style sheets transforms an XML document into another:
if the target language is XHTML, then this is similar to a CSS style sheet;
There is little support for XSLT style sheets yet:
Netscape 4 does nothing;
http://www.brics.dk/~mis/ITU/XML/xslt.html [18/09/2000 14:24:43]
http://www.brics.dk/~mis/ITU/XML/karoline.xml process clear
Trang 28A style sheet for recipes
The following XSLT style sheet illustrates many features (the two namespaces are in different colors):
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns="http://www.w3.org/1999/xhtml">
Trang 29<xsl:if test="@alkohol">
<td align="right"><xsl:value-of select="@alkohol"/>%</td> </xsl:if>
Trang 30Add the necessary HTML to the following style sheet:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns="http://www.w3.org/1999/xhtml">
</html>
4
XML: exercises
http://www.brics.dk/~mis/ITU/XML/exercises.html [18/09/2000 14:24:45]