Document Fragments and XPointer

In HTML documents, the process of addressing a specific part of the document involves using anchors. This can be a useful mechanism, but it does have significant limitations.

Caution

Immediately before this writing, the XPointer specification was split into four W3C Working Drafts. The description that follows is based on those drafts and, therefore, is potentially subject to change.



Let’s suppose that you want to link to the HTML document shown in Listing 14.5. It includes many br tags to space out the anchors.

Listing 14.5. Anchors.html: An HTML Document with Anchors
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" 
"http://www.w3.org/TR/REC-html40/loose.dtd"> 
<HTML> 
<HEAD> 
<TITLE>Teach Yourself XML in 10 Minutes - Chapter 14</TITLE> 
</HEAD> 
<BODY> 
<h1> 
Linking in XML - XLink 
</h1> 
<a name="Anchor1">  
<p>First fascinating text.</p> 
</a> 
<br /><br /><br /><br /><br /> 
<a name="Anchor2"> 
<p>Second fascinating text.</p> 
</a> 
<br /><br /><br /><br /><br /> 
<a name="Anchor3"> 
<p>Third fascinating text.</p> 
</a> 
<br /><br /><br /><br /><br /> 
<br /><br /><br /><br /><br /> 
<br /><br /><br /><br /><br /> 
<p>The REALLY fascinating text.</p> 
<br /><br /><br /><br /><br /> 
<br /><br /><br /><br /><br /> 
</BODY> 
</HTML> 

If you want to link from another HTML document to any of the specified anchors in Listing 14.5, writing a link is straightforward:

<a href="Anchors.html#anchorName" ...> LinkText</a> 

If you don’t have write privileges on the target document, you have limited options. You can ask the Web page author to add an anchor at the point that you want to link to (often unrealistic in a rapidly growing Web), link to an anchor close to the real point of interest (if there is such an anchor), or accept that it isn’t possible to link to a desired fragment in that page.

XPointer is designed to provide improved functionality for linking to document fragments in XML documents. A correctly written XPointer should be capable of identifying any arbitrary part of an XML document. How that part of the document is processed after it is identified depends on the application with which the XPointer processor is associated.

For example, suppose you wanted to link to a long XML document, perhaps a lengthy report, and display it in a browser or similar software at exactly the point of interest. You could write an XPointer to access any part of the document that is of interest without having write access to the target document.

Note

At the time of this writing, no XPointer tools conform fully to the newly issued XPointer draft documents.



To understand how to do that, you should look first at the relationship between XPath (discussed in Chapter 9, “The XML Path Language—XPath”), and XPointer.

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

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