Title: Dickson K'W' Chiu
1CSIT600b XML Programming Xlink, XPointer, XQuery
- Dickson K.W. Chiu
- PhD, SMIEEE
- Thanks to Prof. Francis Lau (HKU)
2Problem of HTML Linking
- Growth of the Web attributed to the ability of
an HTML page to (hyper)link to another page - lta hrefhttp//www.ust.hk/gt
- Limitations
- Involves only two resources
- One-way (the back button is a browsers thing)
- The source must be HTML
- The whole document is loaded even if your link
points to a section - ltimg srchttp//www.dot.comjpg5gt
- The target page must contain explicit section
markups
3XML Linking
- XLink to link resources, XPointer to point to
fragments of XML documents - Tutorial http//zvon.org/xxl/xlink/OutputExamples
/xlinksimple_intro.html - 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
4XLink
- Example
- ltname xmlnshttp//dot.com/name
xmlnsxlinkhttp//www.w3.org/1999/xlinkgtltfirst
gtTommylt/firstgtltlast xlinktypesimple
xlinkhrefhttp//dot.com/tleegtLeelt/lastgtlt/nam
egt - XLinks global attributes
- type, href, label, role, arcrole, title, show,
actuate, from, to - Can be added to elements that are in any
arbitrary namespace
5The 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
6title, 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
- ltlast xlinklabellastName
xlinktypesimple xlinkhrefpeople.xml
xlinktitleLast name xlinkrolehttp//d
ot.com/namesgtLast namelt/lastgt - role is a URI that references a resource that
describes the meaning of the link
7actuate 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 lthtmlimg
src... gt - The application can provide other values, using
QNames, but the application should know how to
handle them - xlinkactuateopEveryFiveMinutes
8from and to
- A link can involve multiple resources, and be
traversed in multiple directions - ltelement xlinkfrommyappfirst
xlinktomyapplast xlinkshowreplace
xlinkactuateonRequestgt Click for
lastlt/elementgt - When clicked, the first link resource will be
replaced by the last link resource
9Simple Links
- Like HTML links 2 resources
- ltelement xlinktypesimple xlinkhref
xlinkshownewgtClick me!lt/elementgt - Simple links are inline links because the
links own content (i.e., Click me) is the
resource
10Extended 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
11Extended Links Example
ltextendedlink xlinktype"extended"gt ltloc
xlinktype"locator" xlinkhref"..."
xlinklabel"parent" xlinktitle"p1" /gt ltloc
xlinktype"locator" xlinkhref"..."
xlinklabel"parent" xlinktitle"p2" /gt ltloc
xlinktype"locator" xlinkhref"..."
xlinklabel"child" xlinktitle"c1" /gt ltloc
xlinktype"locator" xlinkhref"..."
xlinklabel"child" xlinktitle"c2" /gt ltloc
xlinktype"locator" xlinkhref"..."
xlinklabel"child" xlinktitle"c3" /gt ...
lt!-- arc-type elements would go here
--gt lt/extendedlinkgt
- ltgo xlinktypepararc" xlinkfrom"parent"
xlinkto"child" /gt - links from parents to children (6 links total)
- ltgo xlinktypechildarc" xlinkto"child" /gt
- 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.
12XPointer
- 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 URIs
- 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
13XInclude and XBase
- XML 1.0 / 1.1 does not have includes
- XInclude uses XPointer to include portions of
another document - The parse attribute has value xml (parsed) or
text (unparsed) - XBase is for providing base URIs for relative
links in a document
14XQuery
- XQuery is a language for querying XML data
- XQuery is built on XPath expressions
- XQuery for XML is like SQL for databases
- http//www.w3c.org/XML/Query
- 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
http//www.datadirect.com/news/whatsnew/xquerybook
/index.ssp - Brief tutorials
- http//www.brics.dk/amoeller/XML/index.html
- http//www.w3schools.com/xquery/default.asp
15XQuery 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
16XQuery 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
17XQuery Path Expressions
- The simplest kind of query is just an XPath 2.0
expression. - Example
- document("recipes.xml")//recipetitle"Ricotta
Pie"//ingredient_at_amount - 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
18XPath 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
- ...
19XQuery 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")//employeedeptno
d - where count(e) gt 10
- order by avg(e/salary) descending
- return
- ltbig-deptgt d,
- ltheadcountgtcount(e)lt/headcountgt,
ltavgsalgtavg(e/salary)lt/avgsalgt - lt/big-deptgt
For loop Let binding once
Only 1 where
list expression
20XQuery FLWOR Join Example
- Sufficient to compute joins of documents
example - for p IN document("www.irs.gov/taxpayers.xml")//p
erson - for n IN document("neighbors.xml")//neighborssn
p/ssn - return
- ltpersongt
- ltssngt p/ssn lt/ssngt
- n/name
- ltincomegt p/income lt/incomegt
- lt/persongt
21XQuery List Expression
- XQuery expressions manipulate lists of values,
for which many operators are supported - constant lists (7, 9, ltthirteen/gt)
- 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
22XQuery 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,"windsur
fing")) - return b/title
- every-in-satisfies
- for b in document("bib.xml")//book
- where every p in b//paragraph satisfies
- contains(p,"sailing")
- return b/title
-
23XQuery 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("2001-06-07")) - as explicit casts (cast as xsdpositiveInteger(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.
24XQuery - 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
25Status (updated)
- Software? Starting to come up
- http//www.w3.org/XML/Linking
- XLink 1.0 and Xbase 1.0 - June 27, 2001
- XPointer 1.0 - 25 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