XLink Examples

At the time of this writing, Internet Explorer browser has no support for XLink. The Netscape 6.x and Mozilla 1.x browsers support XLink simple links only.

Listings 14.1 and 14.2 show two brief XML documents that each contain a single XLink simple link.

Listing 14.1. Document1.xml: A Document with a Single XLink Simple Link
<?xml version='1.0'?> 
<?xml-stylesheet href="BigText.css" type="text/css" ?> 
<Document1 xmlns:xlink="http://www.w3.org/1999/xlink"> 
<myPrefix:myElement xlink:href="Document2.xml" 
 xlink:type="simple" 
 xmlns:myPrefix="http://www.XMML.com/"> 
Click here to go to Document 2. 
</myPrefix:myElement> 
</Document1> 

Listing 14.2. Document2.xml: A Document with Another Simple Link
					<?xml version='1.0'?> 
<?xml-stylesheet href="BigText.css" type="text/css" ?> 
<Document1 xmlns:xlink="http://www.w3.org/1999/xlink"> 
<myPrefix:myElement xlink:href="Document1.xml" 
 xlink:type="simple" 
 xmlns:myPrefix="http://www.XMML.com/"> 
Click here to go back to Document 1. 
</myPrefix:myElement> 
</Document1> 

Notice that the XLink namespace is declared in each listing on the document element. For ease of display in the screenshots, the documents have been linked to a CSS style sheet shown in Listing 14.3.

Listing 14.3. BigText.css: A CSS Style Sheet Controlling the Appearance of Text
myElement { 
font-family:Arial, sans-serif; 
font-size:30pt; 
color:blue; 
text-decoration:underline; 
} 

Without the CSS stylesheet, the XML text would be displayed as black, without underlining, and in the default font.

Figure 14.1 shows Listing 14.1 displayed in the Mozilla 1.0 browser. Note that the cursor changes to a pointing finger cursor over the linking text.

Figure 14.1. Linking text in a simple XML document in the Mozilla browser.


If you wanted Listing 14.2 to display in a new browser window, you could simply add an xlink:show attribute with the value of new, as shown in Listing 14.4.

Listing 14.4. Document3.xml: A Link to Open a New Browser Window
<?xml version='1.0'?> 
<?xml-stylesheet href="BigText.css" type="text/css" ?> 
<Document1 xmlns:xlink="http://www.w3.org/1999/xlink"> 
<myPrefix:myElement xlink:href="Document2.xml" 
 xlink:type="simple" 
 xlink:show="new" 
 xmlns:myPrefix="http://www.XMML.com/"> 
Click here to go to Document 2. 
</myPrefix:myElement> 
</Document1> 

XLink in SVG

One of the XML application languages that already implements XLink simple links is the W3C’s Scalable Vector Graphics (SVG) specification. SVG 1.0 does not support XLink extended links. An XLink example in SVG is shown in Chapter 15.

Having looked at how you can link whole Web pages, let’s move on to see how XPointer handles XML fragment identifiers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset