Presentation is loading. Please wait.

Presentation is loading. Please wait.

Dickson K.W. Chiu PhD, SMIEEE Thanks to Prof. Francis Lau (HKU)

Similar presentations


Presentation on theme: "Dickson K.W. Chiu PhD, SMIEEE Thanks to Prof. Francis Lau (HKU)"— Presentation transcript:

1 Dickson K.W. Chiu PhD, SMIEEE Thanks to Prof. Francis Lau (HKU)
CSIT600b: XML Programming Xlink, XPointer, XQuery Dickson K.W. Chiu PhD, SMIEEE Thanks to Prof. Francis Lau (HKU)

2 Problem of HTML Linking
Growth of the “Web” attributed to the ability of an HTML page to (hyper)link to another page <a href= … Limitations Involves only two resources One-way (the “back” button is a browser’s thing) The source must be HTML The whole document is loaded even if your link points to a section <img src=“ … The target page must contain explicit section markups Dickson Chiu-2004

3 XML Linking XLink to link resources, XPointer to point to fragments of XML documents Tutorial: W3C Recommendation 1.0, Jun 2001 Example One-way and two-way One link, involving 4 resources Information about this link can be in a completely separated file A.html B.xml C.html D.xml Dickson Chiu-2004

4 XLink Example XLink’s global attributes
<name xmlns=“ xmlns:xlink=“ <first>Tommy</first> <last xlink:type=“simple” xlink:href=“ </name> XLink’s global attributes type, href, label, role, arcrole, title, show, actuate, from, to Can be added to elements that are in any arbitrary namespace Dickson Chiu-2004

5 The “type” Attribute Mandatory, to define a link
Six types (the first 2 are link types, the others are for providing more info about a link) Simple Extended Title – to provide human-readable titles Locator – to indicate remote resources Resource – to define local resources involved Arc – to indicate the rules for traversing Dickson Chiu-2004

6 “title”, “label”, and “role”
title and label are used to label the functions of various resources in the link label is machine-readable, title human-readable <last xlink:label=“lastName” xlink:type=“simple” xlink:href=“people.xml” xlink:title=“Last name” xlink:role=“ name </last> role is a URI that references a resource that describes the meaning of the link Dickson Chiu-2004

7 “actuate” and “show” The actuate attribute specifies when the resource should be retrieved onLoad (default) onRequest The show attribute specifies how to display the resource when it is loaded new – new window replace – current window embed (default) – insert here like <html:img src=... > The application can provide other values, using “QNames”, but the application should know how to handle them xlink:actuate=“op:EveryFiveMinutes” Dickson Chiu-2004

8 “from” and “to” A link can involve multiple resources, and be traversed in multiple directions <element xlink:from=“myapp:first” xlink:to=“myapp:last” xlink:show=“replace” xlink:actuate=“onRequest”> Click for last</element> When clicked, the first link resource will be replaced by the last link resource Dickson Chiu-2004

9 Simple Links Like HTML links: 2 resources
<element xlink:type=“simple” xlink:href=… xlink:show=“new”>Click me!</element> Simple links are “inline” links because the link’s own content (i.e., “Click me”) is the resource Dickson Chiu-2004

10 Extended Links An element to describe links among sets of document(s), classified by labels Extended links can be “out of line” You could create a link from A to B even though you have no access rights for A and B Locator-type to indicate remote resources, and arc-type to specify rules for traversals Attribute arcrole is used to describe the relationship between the resources Dickson Chiu-2004

11 Extended Links Example
<extendedlink xlink:type="extended"> <loc xlink:type="locator" xlink:href="..." xlink:label="parent" xlink:title="p1" /> <loc xlink:type="locator" xlink:href="..." xlink:label="parent" xlink:title="p2" /> <loc xlink:type="locator" xlink:href="..." xlink:label="child" xlink:title="c1" /> <loc xlink:type="locator" xlink:href="..." xlink:label="child" xlink:title="c2" /> <loc xlink:type="locator" xlink:href="..." xlink:label="child" xlink:title="c3" /> ... <!-- arc-type elements would go here --> </extendedlink> <go xlink:type=“pararc" xlink:from="parent" xlink:to="child" /> links from parents to children (6 links total) <go xlink:type=“childarc" xlink:to="child" /> links from parents to children and children to children (15 links total) Upon clicking on a item, say “p1”, the rendering software (need not be a browser) displays a list of linked items for the user to choose. Dickson Chiu-2004

12 XPointer Provides a method for pointing to pieces of an XML document
W3C Recommendation 1.0, Mar 2003 Built on XPath, with the following extensions Locate information by string matching Can be appended to URI’s Address not only entire nodes, but pieces of nodes in an XML document Finer than nodes A location is any node type allowed in Xpath A point is any spot in the XML document A range is defined by two points Dickson Chiu-2004

13 XInclude and XBase XML 1.0 / 1.1 does not have “include’s”
XInclude uses XPointer to include portions of another document The parse attribute has value xml (parsed) or text (unparsed) XBase is for providing base URI’s for relative links in a document Dickson Chiu-2004

14 XQuery XQuery is a language for querying XML data
XQuery is built on XPath expressions XQuery for XML is like SQL for databases Updated release of the XQuery 1.0, XPath 2.0: W3C Oct 2004 XQuery is not an XML language - a version in XML syntax is called XQueryX. Tutorial booklet download from DataDirect: Brief tutorials: Dickson Chiu-2004

15 XQuery W3C Requirements
at least one XML syntax (at least one human-readable syntax) must be declarative must be protocol independent must respect XML data model must be namespace aware must coordinate with XML Schema must work even if schemas are unavailable must support simple and complex datatypes must support universal and existential quantifiers must support operations on hierarchy and sequence of document structures must combine information from multiple documents must support aggregation must be able to transform and to create XML structures must be able to traverse ID references Dickson Chiu-2004

16 XQuery Basic Concepts Expressions are evaluated relative to a context:
namespaces variables functions date and time context item (current node or atomic value) context position (in the sequence being processed) context size (of the sequence being processed) A query in XQuery is an expression that: reads a sequence of XML fragments or atomic values returns a sequence of XML fragments or atomic values The principal forms of XQuery expressions are: path expressions (same as XPath) element constructors FLWOR ("flower") expressions list expressions conditional expressions quantified expressions datatype expressions Dickson Chiu-2004

17 XQuery Path Expressions
The simplest kind of query is just an XPath 2.0 expression. Example: document("recipes.xml")// recipe[title="Ricotta Pie"]// Some XQuery specific extension of XPath: location steps may follow a new IDREF axis an arbitrary XQuery expression may be used as a location step Dickson Chiu-2004

18 XPath 2.0 Major Changes from 1.0
now using XML Schema primitive types instead of just node-set, boolean, number, string new type operators: cast, treat, assert, instance of now using sequences instead of node-sets also allow non-node types new operators: for, if, some, every, intersect, except many new functions regular expression match/replace/tokenize date formats ... Dickson Chiu-2004

19 XQuery FLWOR expressions
The main engine of XQuery is FLWOR expression For-Let-Where-Order-Return pronounced "flower" generalizes SELECT-FROM-HAVING-WHERE from SQL Example for $d in document("depts.xml")//deptno let $e := document("emps.xml")//employee[deptno = $d] where count($e) >= 10 order by avg($e/salary) descending return <big-dept> { $d, <headcount>{count($e)}</headcount>, <avgsal>{avg($e/salary)}</avgsal> }</big-dept> For – loop Let – binding once Only 1 where { … } – list expression Dickson Chiu-2004

20 XQuery FLWOR Join Example
Sufficient to compute joins of documents – example: for $p IN document(" for $n IN document("neighbors.xml")//neighbor[ssn = $p/ssn] return <person> <ssn> { $p/ssn } </ssn> { $n/name } <income> { $p/income } </income> </person> Dickson Chiu-2004

21 XQuery List Expression
XQuery expressions manipulate lists of values, for which many operators are supported: constant lists: (7, 9, <thirteen/>) integer ranges: i to j XPath expressions, like all named children of the context node: name concatenation: , set operators: | (or union), intersect, except functions: remove, index-of, count, avg, max, min, sum, distinct-values ... When lists are viewed as sets: XML nodes are compared on node identity duplicates are removed the order is preserved Dickson Chiu-2004

22 XQuery Qualified Expression
some-in-satisfies for $b in document("bib.xml")//book where some $p in $b//paragraph satisfies (contains($p,"sailing") AND contains($p,"windsurfing")) return $b/title every-in-satisfies where every $p in $b//paragraph satisfies contains($p,"sailing") Dickson Chiu-2004

23 XQuery Datatype Expression
XQuery supports all datatypes from XML Schema, both primitive and complex types. Constant values can be written: as literals (like string, integer, float) as constructor functions (true(), date(" ")) as explicit casts (cast as xsd:positiveInteger(47)) Arbitrary XML Schema documents can be imported into a query. An instance of operator allows runtime validation of any value relative to a datatype or a schema. A typeswitch operator allows branching based on types. Dickson Chiu-2004

24 XQuery - Other Features
Hundreds of built-in operators and functions - contains anything you might think of Computed element and attribute names - allow more flexible queries User-defined functions - allow general-purpose computations Views and updates are still under development Dickson Chiu-2004

25 Status (updated) Software? Starting to come up
XLink 1.0 and Xbase June 27, 2001 XPointer March 2003 XInclude 1.0 – W3C Working Draft 10 Nov 2003 Updated release of the XQuery 1.0, XPath 2.0, Oct 2004 Working draft  Last call working draft  Candidate recommendation  Proposed recommendation  Recommendation Dickson Chiu-2004


Download ppt "Dickson K.W. Chiu PhD, SMIEEE Thanks to Prof. Francis Lau (HKU)"

Similar presentations


Ads by Google