Pointing to identifiers

The most obvious way to point to an element is to reference its unique identifier. This technique is well known to developers of HTML Web sites. Although alternative pointing techniques are described later, this approach remains the most efficient and robust, and should always be used in preference when the target is an element, when this element has a unique identifier, and when the identifier is known to the person creating the link.

Identifier function

XPointer can point to an element with a unique identifier using the XPath Id function:

http://.../xml/doc9.xml#xpointer(id("sect2.1"))

It does not matter what the names of the elements and attributes are, though both must be defined in a DTD:

<section identifier="sect2.1">...</section>

Bare names

The standard includes a minimization technique that attempts to retain backward compatibility with the HTML mechanism for linking to objects within Web pages. When the expression is simply the value of an element identifier attribute, this is termed a 'bare name'. The example below is fully equivalent to the more verbose example above:

http://.../xml/doc9.xml#sect2.1
					

However, this can be a little misleading to those familiar with HTML fragment linking. This mechanism only works for XML documents, not HTML documents. The document must be both well-formed (most HTML documents are not), and must reference a DTD. The target object can be any XML element that has an attribute defined in a DTD to be an identifier attribute.

XHTML anchor targets

In the XHTML standard the Name attribute in the Anchor element is not classified as an identifier attribute in the DTD (see Chapter 23). However, this element has an Id attribute that serves this purpose:

<a id="sec2.1" name="SomethingElse">...</a>

To target an XHTML Anchor element that uses the traditional Name attribute for its unique identifier, the following XPath expression would be used:

xpointer(//a[@name='sect2.1'])

   <a name="sect2.1">...</a>

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

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