1 linking in xml a way of creating hyperlinks in xml documents, internal-link and external-link

44
1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

Post on 20-Dec-2015

219 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

1

Linking in XML

A way of creating hyperlinks in XML documents, Internal-Link and External-Link

Page 2: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

2

• Introduction

• XLink vs. HTML Links

• XML Linking Language (XLink)

– XLink Element

– XLink Attributes

– Simple Links

– Extended Links

• XML Pointer Language (XPointer)

Page 3: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

3

Introduction

• Linking in XML is divided into two parts: XLink and XPointer

• External-Link: XLink defines a standard way of creating hyperlinks in XML documents

– It defines how one document links to another document

• Internal-Link: XPointer allows the hyperlinks to point to more specific parts (fragments) in the XML document

– It defines how individual parts of a document are addressed

Page 4: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

4

XLink vs. HTML Links

• HTML:

– The Web conquered gopher for one reason: HTML made it 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 to jump to another part of the same document

– Limitations:

• Single URL only: URLs are limited to pointing at a single document

• A pre-set named anchor is required before the link to any part of a document can be set

• Links are purely one-way communication: from reader to targeted documents

Page 5: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

5

XLink vs. HTML Links

• XML Linking

– Combining XLink and XPointer to embed internal- and external- links as in HTML.

– Use XSLT for rendering the XML documents into HTML for viewing

– XLink is a proposal for more powerful links between documents designed especially for use with XML documents

– Supports multidirectional links where the links run in more than one direction.

Page 6: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

6

XLink vs. HTML Links

• XML Linking

– Any element can become a link, not just the <a> element.

– Links do not even have to be stored in the same file as the documents they connect.

– These features make XLinks more suitable not only for new uses, but for things that can be done only with considerable effort in HTML,

• Such as cross-references, footnotes, end notes, interlinked data, and more.

Page 7: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

7

XLink vs. HTML Links

• Application Support

– Currently, there are no general-purpose applications that support arbitrary XLinks

– That's because XLinks have a much broader base of applicability than HTML links.

– Specific linking processors can be found: i.e., xlip from Fujitsu, used to demonstrate the traverse of linking, for the detail information regarding the tools, visit:

http://www.w3.org/XML/2000/09/LinkingImplementations.html

– XLinks are not just used for hypertext connections and embedding images in documents

– They can be used by any custom application that needs to establish connections between documents and parts of documents, for any reason.

Page 8: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

8

XLink Element• XLink Syntax

– It is impossible for browsers to predict what hyperlink elements will be called in XML documents

– The solution for creating links in XML documents was to put a marker on elements that should act as hyperlinks

– In XML, any element can be a link or part of a link.

<?xml version="1.0"?><homepages xmlns:xlink="http://www.w3.org/1999/xlink"> <homepage

xlink:type="simple"xlink:href="http://www.w3schools.com">Visit W3Schools</homepage>

<homepage xlink:type="simple“xlink:href="http://www.w3.org">Visit W3C

</homepage></homepages>

To get access to the XLink attributes and features we must declare the XLink namespace at the top of the document

Page 9: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

9

XLink Element (cont.)

• XLink elements are identified by an xlink:type attribute with one of the seven values (next slide)

• An example:

<COMPOSER xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://www.users.interport.net/~beand/"> Beth Anderson

</COMPOSER>

• The xlink prefix must be bound to the http://www.w3.org/1999/xlink namespace URI

• Linking information of these elements are included in the attributes, not the element names

• Attributes define the linking behavior

Page 10: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

10

XLink and DTDs

• DTDs used with documents that use XLink

– Validation

– Reduce the number of XLink attributes in XML document

<car xmlns:xlink = "http://www.w3.org/1999/xlink" xlink:type = "simple" xlink:role = "MT4606" xlink:title = "The Latest Model">

– Provide default values in DTD, and rewrite as:

<car xlink:role = "MT4606" xlink:title = "The Latest Model">

Page 11: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

11

XLink Element (cont.)

• To make the linking as the default values of an element, then add it to the DTD file of an XML document

• The previous example, defined the element in a DTD file:

<!ELEMENT COMPOSER (#PCDATA)>

<!ATTLIST COMPOSER

xmlns:xlink CDATA #FIXED http://www.w3.org/1999/xlink

xlink:type CDATA #FIXED "simple"

xlink:href CDATA #REQUIRED>

• Rewrite the example element:<COMPOSER

xlink:href="http://www.users.interport.net/~beand/">

Beth Anderson

</COMPOSER>

Page 12: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

12

XLink --Semantic Attributes

• Descriptions of the Remote Resource

• A linking element may have optional xlink:role and xlink:title attributes that describe the remote resource

– The document or other resource to which the link points.

– The title contains plain text that describes the resource.

– The role contains a URI pointing to a document that more fully describes the resource.

– For example, the title might describe what a page does and the role might point to a help page for the page

<SEARCH xlink:href="http://www.google.com/advanced_search" xlink:title="Search with Google" xlink:role="http://www.google.com/help.html"> Search the Web with Google</SEARCH>

Page 13: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

13

XLink – Behaviour Attributes

• Link Behavior Attributes (show and actuate)

– The show attribute suggests how the content should be displayed when the link is activated

• xlink: show = “new” indicates that the resource should be displayed in a new windows,

– The actuate attribute suggests whether the link should be traversed automatically or whether a specific user request is required

• Xlink:actuate=“onRequest” indicates that the resource should not be retrieved until the users requests it (e.g. by clicking on the link)

• These are application dependent, however, applications are free to ignore the suggestions.

– All these are based on the XLink-aware application

Page 14: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

14

xlink:show

• The show attribute is used to communicate the desired presentation of the ending resource on traversal from the starting resource

• Constraint: show Value

– The xlink:show attribute has five legal values:

• replace

• new

• embed

• other

• none

Page 15: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

15

xlink:actuate

• The actuate attribute is used to communicate the desired timing of traversal from the starting resource to the ending resource

• Constraint: actuate Value

– If a value is supplied for an actuate attribute, it must be one of the values

• onLoad

• onRequest

• Other

• none

Page 16: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

16

XLink -- Links

• XLink offers two kinds of links:– Simple links

• Shorthand syntax for a common kind of link,

• an outbound link with exactly two participating resources (into which category HTML-style A and IMG links fall).

• Because simple links offer less functionality than extended links, they have no special internal structure.

– Extended links• Extended links offer full XLink functionality, such as inbound and

third-party arcs, as well as links that have arbitrary numbers of participating resources.

• As a result, their structure can be fairly complex, including

– Elements for pointing to remote resources,

– Elements for containing local resources,

– Elements for specifying arc traversal rules,

– Elements for specifying human-readable resource and arc titles.

Page 17: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

17

Simple Links

• A simple link is a link that associates exactly two resources, one local and

one remote, with an arc going from the former to the latter.

– Thus, a simple link is always an outbound link

• Links one resource to another (similarly to HTML link)

• Linking elements

– Specify linking information

<COMPOSER xlink:type = "simple"

xlink:href = "http://www.users.interport.net/~beand/">

– Linking element (COMPOSER) is local resource

– http://www.users.interport.net/~beand/ is remote resource

Page 18: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

18

Fig. 14.1 Illustrating a simple link from document 1 to document 2.

document 1 document 2

Page 19: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

19

Extended Links

• Definition: An extended link is a link that associates an arbitrary number of resources

– The participating resources may be any combination of remote and local

– Link multiple combinations of local and remote resources

• Remember the “back” button in homepage to traverse back to previous document? It is also a browser function.

• Multidirectional links

– Traverse between resources (Fig. 14.6)

– Can link any number of resources (Fig. 14.7)

– Unidirectional links (Fig. 14.5) may not offer return to local resource

Page 20: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

20

Fig. 14.5 Two unidirectional links.

document 1 document 2

Page 21: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

21

Fig. 14.6 Multidirectional link.

document 1 document 2

Page 22: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

22

Fig. 14.7 Multidirectional linking between four resources.

document 1 document 2 document 3 document 4

Page 23: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

23

Extended Links (cont.)• Syntax

– Extended links generally point to more than one target and from more than one source.

– Both sources and targets are called by the more generic word “resource”.

– “Resources” are divided into remote resources and local resources.

– A local resource

• It is actually contained inside the extended link elements

• It is the content of an element of arbitrary type that has an xlink:type attribute with the value resource.

<WEBSITE xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="extended">

<NAME xlink:type="resource">Cafe au Lait</NAME>

……..

</WEBSITE>

Page 24: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

24

Extended Links (cont.)•Syntax

–A remote resource :

•It exists outside the extended link element, very possibly in another document.

•The extended link element contains locator child elements that point to the remote resource.

•These are elements with any name that have an xlink:type attribute with the value “locator”.

•Each locator element has an xlink:href attribute whose value is a URI locating the remote resource

<WEBSITE xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="extended"> <HOMESITE xlink:type="locator" xlink:href="http://ibiblio.org/javafaq/"/> …………….

</WEBSITE>

Page 25: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

25

Extended Links (cont.)• For example, suppose you're writing a page of links to Java sites.

• One of the sites you want to link to is Cafe au Lait at http://ibiblio.org/javafaq/.

• However, there are also three mirrors of that site in three other countries.

• Some people coming to your site will want to access the home site while others will want to go to one of the mirror sites.

• Do it in HTML? You have to write four different links

<WEBSITE xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="extended">

<NAME xlink:type="resource">Cafe au Lait</NAME>

<HOMESITE xlink:type="locator" xlink:href="http://ibiblio.org/javafaq/"/>

<MIRROR xlink:type="locator" xlink:href="http://sunsite.kth.se/javafaq"/>

<MIRROR xlink:type="locator" xlink:href="http://sunsite.informatik.rwth-aachen.de/javafaq/"/>

<MIRROR xlink:type="locator" xlink:href="http://sunsite.cnlab-switch.ch/javafaq/"/>

</WEBSITE>

Page 26: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

26

Extended Links (cont.)

• Shows the WEBSITE extended link element and five resources.

• The WEBSITE element contains one local resource and refers to the other four remote resources by URLs.

• However, this just describes these resources. No connections are implied between them

Page 27: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

27

An Extended Link with Arcs

•Arc

– Simple link: The xlink:show and xlink:actuate attributes define how and when a link is traversed.

– Extended links are a little more complicated because they provide many different possible traversal paths

– For example, the Multidirectional linking between resources,

– Each of the possible paths between resources can have different rules for when the link is traversed and what happens when it's traversed.

Page 28: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

28

An Extended Link with Arcs (cont.)

•Arc– These potential traversals are called arcs,

• They're represented in XML by elements that have an xlink:type attribute with the value “arc”

• Traversal rules are specified by attaching xlink:actuate and xlink:show attributes to arc elements.

• These attributes have the same values and meanings as they do for simple links.

• Applications can use arc elements to determine which traversals are and are not allowed and when a link is traversed.

Page 29: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

29

An Extended Link with Arcs (cont.)

• An arc element also has

– The xlink:from attribute says which resource or resources the arc comes from.

– The xlink:to attribute says which resource or resources the arc goes to.

– They do this by matching the value of the xlink:label attributes on the various resources in the extended link.

– For instance, if the xlink:from attribute has the value “A”, and the xlink:to attribute has the value “B”, then the arc goes from the resource whose xlink:label has the value “A” to the resource whose xlink:label has the value “B”

Page 30: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

30

<WEBSITE xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="extended" xlink:title="Cafe au Lait">

<NAME xlink:type="resource" xlink:label="source"> Cafe au Lait </NAME> <HOMESITE xlink:type="locator“ xlink:href="http://ibiblio.org/javafaq/" xlink:label="us"/> <MIRROR xlink:type="locator" xlink:title="Cafe au Lait Swedish Mirror" xlink:label="se“ xlink:href="http://sunsite.kth.se/javafaq"/> <MIRROR xlink:type="locator" xlink:title="Cafe au Lait German Mirror" xlink:label="sk“ xlink:href="http://sunsite.informatik.rwth-aachen.de/javafaq/"/> <MIRROR xlink:type="locator" xlink:title="Cafe au Lait Swiss Mirror“ xlink:label="ch" xlink:href="http://sunsite.cnlab-switch.ch/javafaq/"/> <CONNECTION xlink:type="arc" xlink:from="source" xlink:to="ch" xlink:show="replace" xlink:actuate="onRequest"/> <CONNECTION xlink:type="arc" xlink:from="source" xlink:to="us" xlink:show="replace" xlink:actuate="onRequest"/> <CONNECTION xlink:type="arc" xlink:from="source" xlink:to="se" xlink:show="replace" xlink:actuate="onRequest"/> <CONNECTION xlink:type="arc" xlink:from="source" xlink:to="sk" xlink:show="replace" xlink:actuate="onRequest"/>

</WEBSITE>

An Extended Link with Arcs (cont.)

Page 31: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

31

An Extended Link with Arcs (cont.)• An extended link with one local and four remote resources and arcs going from the local

resource to each of the remote resources

• In this case, each arc element defines exactly one connection because the target and source labels aren't shared by multiple resources

Page 32: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

32

Xlip – from Fujitsu Corp.1. An application requests the XML processor and the XLink processor that generates

DOM to perform processing, and it accesses the generated information space.

2. The information space is referred to as an XLink data model.

3. An XLink data model consists of an XLink data set and at least one related DOM.

4. An XLink data set contains the results of analyzing XLink descriptions in XML documents.

Page 33: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

33

Fig. 14.9 XLink tree browser rendering of booklinks.xml

©Fujitsu Laboratories Ltd.

Page 34: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

34

Fig. 14.10 Traversing an outbound link.

©Fujitsu Laboratories Ltd.

Page 35: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

35

Fig. 14.11 Traversing an outbound link.

©Fujitsu Laboratories Ltd.

Page 36: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

36

Fig. 14.12 Ending resource shown in a new window.

©Fujitsu Laboratories Ltd.

Page 37: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

37

XML Pointer Language (XPointer)

• Defines an addressing scheme for individual parts of an XML document

• These addresses can be used by any application that needs to identify parts of or locations in an XML document.

– For instance, an XML editor could use an XPointer to identify the current position of the insertion point or the range of the selection

• References fragments of XML document via URI

– Link to specific part of resource, instead of linking to entire resource

– Link to specific locations (i.e., XPath tree nodes)

– Link to ranges of locations

• Uses XPath to reference XML document nodes

• Also used for searching XML documents via string matching

Page 38: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

38

XPointer Example• Traditional way to reference part of document

<H2><A NAME="xtocid20.2">XPointer Examples</A></H2>

– You can then link to this position in the file by adding a # and the name of the anchor to the URL.

– The piece of the URL after the # is called the fragment identifier.

– For example, in this link the fragment identifier is xtocid20.2

<A HREF="http://www.ibiblio.org/xml/bible/20.html#xtocid20.2"> XPointer Examples

</A>

• Problems:

– This solution is kludge. It's not always possible to modify the target document

– Named anchors violate the principle of separating markup from content

Page 39: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

39

XPointer Example (cont.)• XPointers allow much more sophisticated connections between parts of documents.

• An XPointer can refer to any element of a document

– To the first, second, or seventeenth element, and so on

• XPointers provide very precisely targeted addresses of particular parts of documents.

• They do not require the targeted document to contain additional markup just so its individual pieces can be linked to.

• Furthermore, unlike HTML anchors, XPointers don't point to just a single point in a document.

– They can point to entire elements, to possibly discontinuous sets of elements, or to the range of text between two points.

1. Thus, you can use an XPointer to select a particular part of a document,

2. Perhaps so it can be copied or loaded into a program.

Page 40: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

40

XPointer Example (cont.)

• Here are a few examples of XPointers:

• Each of these seven XPointers selects a particular element in a document

1. xpointer(id("ebnf"))

2. xpointer(descendant::language[position()=2])

3. element(/1/14/2)

4. xpointer(id("ebnf"))xpointer(id("EBNF"))

Finds the element with the ID “ebnf”

Finds the second “language” element in the document

Finds the second child element of the fourteenth child element of the root element

Points to the element with the ID “ebnf”.

However, if no such element is present, it then finds the element with the ID “EBNF”

<SPECIFICATION xmlns:xlink="http://www.w3.org/1999/xlink" xlink:type="simple" xlink:href="http://www.w3.org/TR/1998/REC-xml-19980210.xml#xpointer(id('ebnf'))" xlink:actuate="onRequest" xlink:show="replace"> Extensible Markup Language (XML) 1.0

</SPECIFICATION>

Page 41: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

Outline41

Fig. 14.14 Example contact list.

Lines 5-9

1 <?xml version = "1.0"?>

2 <!-- Fig. 14.14 : contacts.xml -->

3 <!-- contact list document -->

4

5 <contacts>

6 <contact id = "author01">Deitel, Harvey</contact>

7 <contact id = "author02">Deitel, Paul</contact>

8 <contact id = "author03">Nieto, Tem</contact>

9 </contacts>

Mark up contact list that contains ids for three authors

Page 42: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

42

XML Pointer Language (cont.)

• Figure 14.14

– Assume contact list has relative URI /contacts.xml

• XLink references entire contact list with URI

xlink:href = "/contacts.xml"

• XPointer references specific part:

– Element contact with id of author02

xlink:href = "/contacts/xml#xpointer(//contact[@id = ‘author02]’)"

Page 43: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

43

That’s it for today (5/20)!

Page 44: 1 Linking in XML A way of creating hyperlinks in XML documents, Internal-Link and External-Link

44

XLink Attribute Reference

Attribute Value Description

xlink:actuate onLoadonRequestothernone

Defines when the linked resource is read and shown

xlink:href URL The URL to link to

xlink:show embednewreplaceothernone

Where to open the link. Replace is default

xlink:type simpleextendedlocatorarcresourcetitlenone

The type of link