Upload
adrian-baker
View
216
Download
2
Embed Size (px)
Citation preview
Copyright © 2003 Pearson Education, Inc. Slide 6-1
Created by Cheryl M. Hughes, Harvard University Extension School — Cambridge, MA
The Web Wizard’s Guide to XML by Cheryl M. Hughes
Copyright © 2003 Pearson Education, Inc. Slide 6-2
CHAPTER 5Links in XML
Copyright © 2003 Pearson Education, Inc. Slide 6-3
Overview of Hyperlinks
A “hyperlink” in a web page is an object that a user can click on that will redirect the browser to another web page, file or position within the page
Hyperlinks in HTML make the web interactive Links in XML are similar in syntax to links in the
HTML language XML Linking Language (XLink) is the XML
specification for linking The resource being linked to is called the “target
resource”
Copyright © 2003 Pearson Education, Inc. Slide 6-4
Linking in HTML
The <a> anchor element Require the user to take an action – usually by
clicking on the link, which can consist of images or text
The target of the link can be an absolute or relative URL
The <img> element Does not require user intervention – resource
loads automatically when page loads. Usually used for graphics in HTML
Copyright © 2003 Pearson Education, Inc. Slide 6-5
HTML Link Example: HTML file
1 <html>
2 <head>
3 <title>Link Examples in HTML</title>
4 </head>
5 <body>
6 <p> Here are some examples of links in HTML:</p>
7 <p>
8 <a href=”http://chughes.com/newpage.html”>This is an absolute
link to a new page</a>
9 </p>
10 <p>
11 <a href=”newpage.html”>This is a relative link to a new page</a>
12 </p>
13 <p>
14 <a href=”newpage.html”><img src=”button.gif” alt=”This image is a
clickable button”></a>
15 </p>
16 <p>
17 <a href=”mailto:[email protected]”>This is link that launches an
email message</a>
18 </p>
19 </body>
20 </html>
Copyright © 2003 Pearson Education, Inc. Slide 6-6
HTML Link Example: Browser
Copyright © 2003 Pearson Education, Inc. Slide 6-7
HTML Link Limitations
Can only point to one target resource Links are unidirectional – once the link is
followed, there is no path back to the original document
Only certain HTML elements can be used for providing linking functionality
Copyright © 2003 Pearson Education, Inc. Slide 6-8
XLink Overview
The XLink specification was released by the W3C in July 2001
Benefits over HTML links: Supports multi-directional links, which allows the target
resource to link back to the originating document Can contain multiple destinations Any XML element can be a linking element XML link behavior can be programmed
XLink specification defines two types of links Simple links Extended links
Copyright © 2003 Pearson Education, Inc. Slide 6-9
Simple XLink Links
Syntax is similar to HTML links Simple links are:
Unidirectional Can only link to one target resource Can be defined on any XML element Defined as a namespace:
http://www.w3c.org/1999/xlink
Required attributes: href and type
Copyright © 2003 Pearson Education, Inc. Slide 6-10
Simple Links: Attributes
type : Determines the type of link – for simple, the value is always “simple”
href : Defines the URL of the target resource show : Defines the behavior of the link after it is
activated actuate : Defines when the link will be activated role : Describes the resource being linked to title : Used to describe the link arcrole : Describes the relationship between the
source and target documents
Copyright © 2003 Pearson Education, Inc. Slide 6-11
Simple XLink Example
1 <?xml version="1.0"?>
2 <map
3 xmlns:xlink=”http://www.w3.org/1999/xlink”
4 xlink:type=”simple”
5 xlink:href=”mapimage.gif”
6 xlink:actuate=”onRequest”
7 xlink:show=”replace”
8 xlink:role=”image”
9 xlink:title=”A map image”>
10 Link to Map image
11 </map>
Copyright © 2003 Pearson Education, Inc. Slide 6-12
Simple XLink Example with DTD
1 <?xml version="1.0" standalone=”yes”?>
2 <!DOCTYPE map [
3 <!ELEMENT map (#PCDATA)>
4 <!ATTLIST map
5 xmlns:xlink CDATA #FIXED ”http://www.w3.org/1999/xlink”
6 xlink:type CDATA #FIXED “simple”
7 xlink:href CDATA #REQUIRED>
8 ]>
9 <map xlink:href=”mapimage.gif”>Link to Map image</map>
Attributes that are defined as “#FIXED” in the DTD do not have to be included in the XLink element
Copyright © 2003 Pearson Education, Inc. Slide 6-13
XLink Extended Links
Extended links provide much greater functionality than simple links
Extended links: Can link to multiple target resources Are multi-direction
Extended links can be any of the following types: extended, resource, locator, arc or title
Copyright © 2003 Pearson Education, Inc. Slide 6-14
Extended XLink Example
1 <courses xmlns:xlink=”http://www.w3.org/1999/xlink”
2 xlink:type=”extended”>
3 <locator xlink:type=”locator”
4 xlink:href=”courses/xml101.xml”
5 xlink:title=”XML 101”/>
6 <locator xlink:type=”locator”
7 xlink:href=”courses/advxml.xml”
8 xlink:title=”Advanced XML”/>
9 <locator xlink:type=”locator”
10 xlink:href=”courses/bw.xml”
11 xlink:title=”Basket Weaving”/>
12 Link to Course
13 </courses>
Copyright © 2003 Pearson Education, Inc. Slide 6-15
Extended XLink Example with DTD
1 <?xml version="1.0" standalone=”yes”?>2 <!DOCTYPE map [3 <!ELEMENT courses (locator*, resource*, arc*, title?)>4 <!ATTLIST courses5 xmlns:xlink CDATA #FIXED
”http://www.w3.org/1999/xlink”6 xlink:type CDATA #FIXED “extended”>7 <!ELEMENT locator EMPTY>8 <!ATTLIST locator9 xlink:href CDATA #REQUIRED10 xlink:title CDATA #IMPLIED>11 ]>12 <courses xmlns:xlink=”http://www.w3.org/1999/xlink”13 xlink:type=”extended”>14 <locator xlink:type=”locator”15 xlink:href=”courses/xml101.xml”16 xlink:title=”XML 101”/>17 <locator xlink:type=”locator”18 xlink:href=”courses/advxml.xml”19 xlink:title=”Advanced XML”/>20 <locator xlink:type=”locator”21 xlink:href=”courses/bw.xml”22 xlink:title=”Basket Weaving”/>23 </courses>