Home | | Service Oriented Architecture | XLink: Simple and Extended Links

Chapter: XML and Web Services : Essentials of XML : The X-Files: XPath, XPointer, and XLink

XLink: Simple and Extended Links

Simple Links, Extended Links - The anchor element, , within HTML indicates a link to another resource on an HTML page.

XLink

 

The anchor element, <a>, within HTML indicates a link to another resource on an HTML page. This could be a location within the same document or a document located elsewhere. In HTML terms, the anchor element creates a hyperlink to another location. The hyperlink can either appear as straight text, a clickable image, or a combination of both. Although HTML anchor elements contain a lot of functionality, they are still limit-ing—they require the use of the anchor element (<a>) itself, and they basically sit there waiting for someone to click them before navigating to the specified location.

The XML Linking Language, XLink, addresses and overcomes these limitations by allowing a link to another document to be specified on any element within an XML document. What’s more, those links to other documents can be much more complex than the simple links supported by the HTML specification. You can find the complete specification at http://www.w3.org/TR/xlink.

 

The XML Linking Language creates a link to another resource through the use of attributes specified on elements, not through the actual elements themselves. The XML Linking Language specification supports the attributes listed in Table 5.12.

 

TABLE 5.12     XLink Attributes




 

The xlink:type attribute must contain one of the following values:

 

            simple

 

            extended

 

            locator

 

            arc

 

            resource

 

            title

 

            none

 

A value of simple creates a simple link between resources. Indicating a value of extended creates an extended link, which is discussed in the “Extended Links” section later in this chapter. A value of locator creates a link that points to another resource. A value of arc creates an arc with multiple resources and various traversal paths. A resource value creates a link to indicate a specific resource. A value of title creates a title link. By specifying a value of none for the xlink:type attribute, the parent element has no XLink meaning, and no other XLink-related content or attributes have any rela-tionship to the element. For all intents and purposes, a value of none removes the ability to link to another resource from an element.

 

As indicated in Table 5.12, the xlink:href attribute supplies the location of the resource to link to. This attribute is a URI reference that can be used to find the desired resource. In a case where you wish to link to a specific area of the target resource, you may optionally include an XPointer expression to specify a point or range within that docu-ment with which to link.

 

The xlink:role attribute specifies the function of the link. However, you cannot use this attribute with just any type of XLink. This attribute may only be used for the following XLink types:

 

            extended

 

            simple

 

            locator

 

            resource

 

Similarly, the xlink:arcrole attribute may only be used with two types of XLinks:

 

            arc

 

            simple

 

The xlink:title attribute is completely optional and is provided for us to make some sense of and document, in a way, what a particular link is. If the xlink:title attribute is specified, it should contain a string describing the resource.


 

The xlink:show attribute is an optionally specified attribute for a link for the simple and arc XLink types and will accept the following values:

 

            new

 

            replace

 

            embed

 

 

            other

 

            none

 

If a value of new is specified, the resource will be loaded into a new window. A value of replace indicates that the resource should be loaded into the current window. Indicating a value of embed will load the resource into the specified location and wrap the originat-ing resource around it, as appropriate. This effect is similar to specifying an src attribute on a <img> tag in HTML. A value of other allows each application using XLinks to look for other indications within the XML document to determine what needs to be done.

 

Specifying a value of none has essentially the same effect as specifying a value of other, with the exception that the application is not expected to look for other indications as to what to do to display the link.

 

The xlink:actuate attribute is used to indicate when the linked resource should be loaded. This attribute will accept the following values:

 

            onLoad

 

            onRequest

 

            other

 

            none

 

A value of onLoad indicates that when the current resource is loading, the linked resource should be loaded as well. Specifying a value of onRequest means the linked document should only be loaded when some post-loading event triggers a message for traversal. A value of other indicates, again, that the application should look for other indications as to what the desired behavior is. Indicating a value of none specifies that the application is free to handle the loading of the linked resource in whatever manner seems appropriate.

 

The xlink:label attribute is used to name resource and locator XLink types. This value will end up being used as values within the xlink:from and xlink:to attributes to indicate the starting and ending resources for an arc XLink type.

 

The XML Linking Language offers two major types of links: simple and extended. Within XLink, a simple link is a convenient, shorthand notation by which to associate two resources. These resources—one local and one remote—are connected by an arc, always making a simple link an outbound link. An extended link associates any number of resources together. Furthermore, those resources may be both local and remote.

 

Simple Links

 

A simple link combines the functionality provided by the different pieces available through an extended link together into a shorthand notation. A simple link consists of an xlink:type attribute with a value of simple and, optionally, an xlink:href attribute with a specified value. A simple link may have any content, and even no content; it is up to the application to provide some means to generate a traversal request for the link. If no target resource is specified with the xlink:href attribute, the link is simply considered “dead” and will not be traversable.

 

Simple links play multiple roles in linking documents. For instance, the simple link, itself, acts as a resource XLink type for the local document. It is the combination of this functionality that shortens the XLink definition for a simple link.

 

However, as stated earlier, simple links are just that—simple. They link exactly two resources together: one local and one remote. Therefore, if something more complex must be handled, an extended link is necessary.

 

Extended Links

 

Within the XML Linking Language, extended links give you the ability to specify rela-tionships between an unlimited number of resources, both local and remote. In addition, these links can involve multiple paths between the linked resources. Local resources are part of the actual extended link, whereas remote resources identify external resources to the link. An out-of-line link is created when there are no local resources at all for a link. It is up to individual applications to decide how to handle extended links; there’s no magic formula for this one.

Understanding extended links can be rather frustrating. Therefore, let’s look at a sample XML document that incorporates XLinks, as shown in Listing 5.4, to see how this all works.

 

LISTING 5.4 Sample4.xml Contains a Modified Version of the Names List in

 

Sample3.xml

 

<People xmlns:xlink=”http://www.w3.org/1999/xlink” xlink:type=”extended” xlink:title=”Phone book”>

 

<Person>

 

<Name>Dillon Larsen</Name> <Address>

 

<Street>123 Jones Rd.</Street> <City>Houston</City> <State>TX</State> <Zip>77380</Zip>

 

</Address>

 

</Person>

 

<Person>

 

<Name>Madi Larsen</Name> <Address>

 

<Street>456 Hickory Ln.</Street> <City>Houston</City> <State>TX</State> <Zip>77069</Zip>

 

</Address>

 

</Person>

 

<Person>

 

<Name>John Doe</Name> <Address>

 

<Street>214 Papes Way</Street> <City>Houston</City> <State>TX</State> <Zip>77301</Zip>

 

</Address>

 

</Person>

 

<Person xlink:type=”resource” xlink:label=”John”> <Name>John Smith</Name>

 

<Spouse xlink:type=”resource” xlink:label=”JohnSpouse”>Jane Smith</Spouse> <Address>

 

<Street>522 Springwood Dr.</Street> <City>Houston</City> <State>TX</State>

 

<Zip>77069</Zip>

 

</Address>

 

</Person>

 

<Person xlink:type=”resource” xlink:label=”Jane”> <Name>Jane Smith</Name>

 

<Spouse xlink:type=”resource” xlink:label=”JaneSpouse”>John Smith</Spouse> <Address>

 

<Street>522 Springwood Dr.</Street> <City>Houston</City> <State>TX</State>

 

<Zip>77069</Zip>

 

</Address>

 

</Person>

 

<Marriage  xlink:type=”arc”  xlink:from=”JohnSpouse”

 

xlink:to=”Jane” xlink:actuate=”onRequest” xlink:show=”new”/> <Marriage xlink:type=”arc” xlink:from=”JaneSpouse”

xlink:to=”John”  xlink:actuate=”onRequest”  xlink:show=”new”/>

 

</People>

From Listing 5.4, you can see that we’ve slightly modified the XML document from Listing 5.3. The difference here is that we’re specifying XLinks within this document. Notice the addition of two new elements in Listing 5.4: <Spouse> and <Marriage>.

 

The basic idea here is that clicking the <Spouse> element will open up a new window with the spousal information on it. So how would this occur? The actual mechanics are up to the individual applications, but ideally, the <Marriage> element serves as an arc, or navigation path, from the local resource, which could be Jane Smith or John Smith, depending on which element you’re looking at, to another resource. The <Marriage> ele-ment with the appropriate xlink:from attribute would be selected, and the application would find where the destination resource is by looking in the xlink:to attribute. Then, locating the element with that value in its xlink:label attribute, the application would navigate there and open up that information in a new window.


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
XML and Web Services : Essentials of XML : The X-Files: XPath, XPointer, and XLink : XLink: Simple and Extended Links |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.