XLink & XPointer

advertisement
XLink & XPointer
ShengWu
Contents Covered
• XLink
–
–
–
–
–
XLink Versus HTML links
Linking Elements
Simple Links
Link Behavior
Extended Links
Contents Covered (Continued)
• XPointer
–
–
–
–
–
–
Why use Xpointer
Xpointers in links
Bare Names
Child Squences
Points
Ranges
XLinks Versus HTML Links
• What HTML links can do
HTML made web possible to embed
hypertext links in documents. These links
could insert images or let the user to jump
from inside one document to another
document or another part of the same
document.
(Continued)
• Limitations of HTML links
a. URLs are limited to pointing at a single
document. More granularity than that, such as
linking to the third sentence of the 17th paragraph
in a document, requires you to manually insert
named anchors in the targeted file. It can’t be done
without write access to the document to which you
are linking.
(continued)
b. Furthermore, HTML links don’t maintain
any sense of history or relations between
documents. Links are purely one way. The
linking document knows to whom it’s
linking, but not vice versa.
(continued)
• What XLink can do
 Xlink is a proposal for more powerful links
between documents.
 Xlink achieves everything possible with
HTML’s URL-based hyperlinks and anchors.
 Beyond this, it supports multidirectional links
where the links run in more than one direction.
 Any element can become a link, not just the a
element.
(continued)

Links do not even have to be stored in the
same file as the documents they link.
 Furthermore, Xpointers allow links to point
to arbitrary positions in an XML document.
These features make XLinks more suitable.
(continued)
• Browser Support
Netscape and Internet Explorer 5.5 and
earlier have no support for any kind of
Xlink.
Although a few research projects use
Xlinks, there are no general-purpose
applications that support arbitrary Xlinks.
Linking Elements
• What is a linking element?
In HTML, a link is defined with the <A> tag.
However, just as XML is more flexible with tags
that describe elements, it is more flexible with tags
that refer to external resources. In XML, any
element can be a link.
Elements that include links are called linking
elements. Linking elements are identified by an
xlink:type attribute.
Linking Element (Continued)
• xlink:type attribute values
–
–
–
–
–
–
simple
extended
locator
arc
resource
title
Linking Element (Continued)
• Xlink namespace
– The xlink prefix must be bound to the
http://www.w3.org/1999/xlink namespace URI.
– The xlink prefix is customary and should be
used unless you have got a really good reason
to change it.
Linking Element (Continued)
• Examples:
a.
<composer xmlns:xlink=“ http://www.w3.org/1999/xlink”
xlink:type=“simple”
xlink:href=“ http://www.users.net/~beand/”>
Beth Anderson
</composer>
Linking Elements (Continued)
b. <footnote xmlns:xlink=“ http://www.w3.org/1999/xlink”
xlink:type=“simple”
xlink:href=“footnote7.xml” >
7
</footnote>
c. <image xmlns:xlink=“ http://www.w3.org/1999/xlink”
xlink:type=“simple” xlink:href=“logo.gif”
xlink:actuate=“onLoad” xlink:show=“embed” />
Note: the elements have semantic names that describe the
content they contain rather than how the elements behave.
Simple Link
• Definition: A simple Xlink is encoded in an XML
document as an element of arbitrary type that has an
xlink:type attribute with the value simple and an xlink:href
attribute. The attribute’s value is the link target’s URI.
• How simple link works?
A simple link defines a one-way connection between two
resources. The source, the connection’s starting resource,
is itself the link element. The target or ending resource of
the connection is identified by a URI. The URI may be
something other than a URL.
• Simple links are the only links that are similar to HTML
links.
Simple Link (continued)
• Example
<novel xmlns:xlink=“ http://www.w3.org/1999/xlink”
xlink:type=“simple” xlink:href=“urn:isbn:0688069444”>
<title> The Wonderful Wizard of Oz </title>
<author> L. Frank Baum </author>
<year> 1900 </year>
</novel>
Link Behavior
• Some discussions
How is the connection described by XLink
presented to the end user or what dose it make
software reading the document do? They don’t
have just one answer.
 For instance, when the browser encounters a novel
element that uses an http URI, clicking the link
should probably load the text of the novel from the
URL into the current window, thereby replacing
the document that contained the link.
Link Behavior (Continued)
Then again, maybe it should open a new window
and show the user the new document in that
window.
 The proper behavior for a browser encountering
the novel element that uses an isbn URN is even
less clear. Perhaps it should reserve the book with
the specified ISBN at the local library. Or perhaps
it should order the book from an online bookstore.
Link Behavior (Continued)
Page authors can offer suggestions to browsers about how
links should be handled by using the xlink:show and
xlink:actuate attributes.
• Xlink:show
– The xlink:show tells the browser or other application
what to do when the link is activated.
– It has five possible values:
 New: opens a new window and shows the content at the
link’s URI (the ending resources) in that window.
Link Behavior (Continued)
 Replace: Shows the ending resource in the current
window, replacing the current document
 Embed: Embeds the ending resources in the
current document at the location of the link
element.
 Other: Do something other than what new,
replace, embed do.
 None: Specifies no behavior.
Link Behavior (Continued)
• Xlink:actuate
– The xlink:actuate attribute tells the browser when to
show the content.
– The optional xlink:actuate has four possible value
 OnLoad: The link should be followed as soon as the
application sees it.
 OnRequest: The link should be followed when the user
asks to follow it.
 Other: Other markup in the document, not specified by
xlink, determines when to follow the link.
 None: No details are available.
Link Behavior (Continued)
• Example
<novel xlink:type=“simple”
xlink:href=“ ftp://archive.org/pub/etext93/wizoz10.txt ”
xlink:actuate=“onRequest” xlink:show=“replace”>
<title> The Wonderful Wizard of Oz </title>
<author> L. Frank Baum </author>
</novel>
This code says to wait for an explicit user request to follow
the link and then replace the existing document with the
document found at ftp://archive.org/pub/wizoz10.txt.
Link Semantics
Xlink elements can have xlink:title and xlink:role
attributes to specify the meaning the connection
between the resources
• Xlink:title
this attribute contains a small amount of plain text
describing the remote resources.
• Xlink:role
this attribute contains a URI pointing to a longer
description of the remote resource.
Link Semantics (Continued)
• Example
<novel xlink:type=“simple”
xlink:href=“ ftp://archive.org/pub/etext93/wizoz10.txt ”
xlink:title=“The complete text of the novel from project
gutenberg” xlink:role=“ http://promo.net/pg/”>
<title> The Wonderful Wizard of Oz </title>
<author> L. Frank Baum </author>
</novel>
Extended Links
• Definition:
 An extended link describes a collection of
resources and paths between those resources.
 Each path connects exactly tow resources. Any
individual resource may be connected to another
resource, two other resources, no resources, all
other resources, or any subset of other resources in
the collection. It may even connect back to itself.
 An extended link is a directed, labeled graph in
which the paths are arcs, the documents are
vertices, and the labels are URIs.
Extended Links (Continued)
• Simple links are easy to understand by analogy to
HTML links. However, no obvious analogy exists
for extended links. What the links look like, how
applications treat them, and what user interfaces
present them to people is all undecided.
Extended Links (Continued)
• Extended elements:
in XML, an extended link is represented by
an extended link element, an element of arbitrary
type that has an xlink:type attribute with the value
extended.
Extended Links (Continued)
Most extended links contain local resources, remote
resource, and arcs between those resources.
 A remote resource is represented by a locator
element, which is any type of element that has an
xlink:type attribute with the value locator.
 A local resource is represented by a resource
element, any type of element that has an xlink:type
attribute with resource.
 An arc element, any type of element that has an
xlink:type attribute with the value arc, represents a
connection between two resources.
Extended Links (Continued)
• Locator element
– Each locator element has an xlink:type attribute
with the value locator and an xlink:href
attribute containing a URI for the resource it
locates.
– Usually each locator element also has an
xlink:label attribute that serves as the element’s
ID.
Extended Links (Continued)
• Example of locator element
<novel xlink:type=“extended”>
<title> The Wonderful Wizard of Oz </title>
<author> L. Frank Baum </author>
<edition xlink:type=“locator”
xlink:href=“urn:isbn:06880694444”
xlink:label=“ISBN06880694444”/>
<edition xlink:type=“locator” xlink:href= “urn:isbn:0192839306”
xlink:label=“ISBN0192839306”/>
</novel>
Extended Links (Continued)
• Arc element
– Paths between resources are called arcs. Arcs are
represented by arc element.
– Each arc element should have an xlink:from and an
xlink:to attribute. Xlink:from identifies the link’s source
and xlink:to identifies the link’s target.
– Both xlink:from and xlink:to do not contain URIs, they
contain a name matching the value of the xlink:label
attribute of one of the locator elements in the extended
links.
Extended links (Continued)
• Example (Mutiple arcs from one arc element)
<book xlink:type=“extended” xmlns:xlink=“http://……” >
<author> L. Frank Baum </author>
<title> The Wonderful Wizard of Oz </title>
<!– locator elements -->
<edition xlink:type=“locator” xlink:href=“urn:isbn:99999”
xlink:title=“Oxford University Press”
xlink:role=“ http:// www.oup-usa.org/”
xlink:lable=“ISBN99999” />
Extended Links (Continued)
<store xlink:type=“locator”
xlink:href=“ http://www.amazon.com/….”
xlink:label=“buy”>Amazon </store>
<store xlink:type=“locator”
xlink:href=“ http://www.bookpool.com/…”
xlink:label=“buy”>Bookpool</store>
<store xlink:type=“locator”
xlink:href=“ http://www.ecampus.com/…”
xlink:label=“buy”>Ecampus</store>
Extended Links (Continued)
<!-- arcs - ->
<purchase xlink:type=“arc”
xlink:from=“ISBN99999” xlink:to=“buy” />
</book>
Extended Links (Continued)
• Local resources
Extended links can also contain local
resources, in which the extended link element
contains the data. A resource element represents
each such resource. This is an element of arbitrary
type that has an xlink:type with the value resource.
The function of a resource element is similar
to a locator element. But the locator elements
represent remote resources.
Extended Links (Continued)
• Title Elements
– Xlink:title attribute are not always enough for
identifying the link. Thus, a title can instead (or
in addition) be provided as a title type child
element.
– Title elements has the value title for their
xlink:type attribute.
XPointer
• Xpointers address the individual parts of an
XML document.
• Xpointer syntax builds on the Xpath syntax
used by XSLT.
Why uses Xpointers
• Simple scheme HTML used
some URLs contain fragment identifiers that identify the particular
named anchor inside the document identified by the URL’s path. #
separates this anchor from the path. For instance, URL
http://java.sun.com/index.html#download asks browser look for a
named anchor in the document at http://java.sun.com/index.html with
the name download, such as this one
<a name=“download”></a>
It would then scroll the browser window to the position in the
document where the anchor with the right name was found.
• Drawback of this simple scheme: To link to a particular point in the
document, you must be able to modify the document to insert a named
anchor at the point you’d like to link to.
Why uses Xpointer (Continued)
• Xpointer eliminates the restriction by allowing you to
specify where you want to link to using full Xpath
expressions as fragment identifier.
• Furthermore, Xpointer expands on Xpath by providing
operations to select particular points in or ranges of an
XML document.
• An Xpointer is simply an Xpath expression, often a
location path, enclosed in the parentheses of xpointer().
xpointer(/)
xpointer(//first_name),
Xpointers in Links
• Xpointers in URL
Example:
http://www.ibiblio.org/xml/people.xml#xpointer(//name[positio
n()=1])
This URL points to the first name element in the document at
http://www.ibiblio.org/xml/people.xml
Xpointers in links (continued)
• Xpointers in Xlinks
Xpointers are more frequently used in Xlinks. The
following example points to the first book child of
the bookcoll child of the testament root element in
the document at the relative URL ot.xml:
<link xlink:type=“simple”
xlink:href=“ot.xml#xpointer(/testament/bookcoll/book[pos
ition()=1])”>
Genesis
</link>
Bare Names
• A bare name Xpointer is similar to an HTML
named anchor; it identifies the element it points at
by its name. However, an ID attribute of the
element being pointed at, rather than a special a
element with a name attribute, supplies this name.
• To link to an element with a bare name, append
the usual fragment separator # to the URL,
followed by the ID of the element you are linking
to.
Child Sequences
Many xpointers descend exclusively along the
child axis, selecting elements by their position
relative to their siblings
xpointer(/child::*[position()=1]/child::*[position()
=2]/child::*[position()=3])
selects the third child element of the second child
element of the document's root element.
Child Sequences (Continued)
Since this is so common, xpointer allows you to
abbreviate this syntax by providing only the
numbers of the child elements, separated by
forward slashes. This abbreviation is called a child
sequence.
The previous Xpointer could be rewritten as a
child sequence in the more compact form /1/2/3.
A child sequence should not be enclosed in
xpointer() like a normal Xpath expression.
For example, it should be: http://…………#1/2/3
Points and Ranges
• Xpaths, bare names, and child sequences let you
point only to entire nodes or sets of nodes.
• Sometimes you may want to point to something
that isn’t a node, such as the third word of the
second paragraph. Xpointer adds points and
ranges to the Xpath syntax to make this possible.
Points
• If the node contains child nodes, then points
exist before and after each of its children.
• If the node does not contain child nodes,
then a point is present before and after each
character in the node's string value.
Points (Continued)
• Example
Eight points are located directly inside the novel element.
<novel copyright=“public domain”>*
Point1 *<title>The Wonderful Wizard of Oz</title>*
Point3 *<author>L. Frank Baum</author>*
Point5 *<year>1990</year>*
Point7*</novel>
Point0
Point2
Point4
Point6
Points (Continued)
<year>1990</year>
Five points are present inside the text node child of
the year element:
• Point 0 between <year> and 1
• Point 1 between 1 and 9
• Point 2 between 9 and 0
• Point 3 between 0 and 0
• Point 4 between 0 and </year>
Points (Continued)
<novel copyright=“public domain”>
<title>The Wonderful Wizard of Oz</title>
<author>L. Frank Baum</author>
<year>1990</year>
</novel>
xpointer(//title[position( ) =1]/text ( )/point( ) [position ( )=3])
Initially finds the document’s first title element, then it
takes its text node child. Within this text node, it selects the
point between the third and fourth character. Apply it to
this example, it would point to the space after The.
Ranges
• A range is the span of parsed character data
between two points.
• Ranges are created with four functions that
XPointer adds to XPath:
–
–
–
–
range ( )
range-inside ( )
range-to ( )
string-range ( )
Ranges (continued)
• The range ( ) function takes an Xpath expression
that returns a location set as an argument. For each
node in this location set, the range ( ) function
returns a range that covers that node exactly.
• Example:
Xpointer (range (/novel/*))
when applied to the example we just used, it returns
three ranges, one covering each of the novel root
element’s three child elements.
Download