XML

XLink

XLink provides links similar to hyperlinks. XLink enables you to define link elements in your DTD. XLink elements can have the following attributes: type, href, role, title, show, and actuate. There are two types of XLinks, simple and extended. A simple link connects two resources: a source and a destination. An extended link connects any number of resources. In this section, let's take a look at these two types and the attributes defined in XLink in detail.

Simple Links

A declaration for a simple XLink element might look like this:

  <!ELEMENT Mylink ANY>
  <!ATTLIST Mylink
    xlink:type    (simple)             #FIXED "simple"
    xlink:href    CDATA                #REQUIRED
    xlink:role    NMTOKEN              #FIXED "roleName"
    xlink:title   CDATA                #IMPLIED
    xlink:show    (new
                  |replace
                  |embed
                  |undefined)          #FIXED "replace"
    xlink:actuate (onLoad
                  |onRequest
                  |undefined)          #FIXED "onRequest"
  >

The attributes are defined as follows:

  • type Specifies whether the link is simple or extended.

  • href Refers to the URI of the other end of the link. This can be an entire document, or it can be a point or an element in a document. An XPointer can be used to identify a point in the document.

  • role Describes the function of the other end of the link. There are no predefined role values. You can create your own roles that will be interpreted by your applications to define different types of XLink. For more information on roles, see the W3C specification at http://www.w3c.org/TR/2000/WD-xlink-20000221/.

  • title The title attribute is the same as the HTML link title. It can be used to display floating tips or a default value when the link cannot be displayed.

  • show If no style sheet is used, the show attribute will tell the application what to do with the link. The embed value causes the content of the link target to be embedded in the content of the link source. The replace value causes the content of the link source to be replaced by the content of the link target. The new value creates a new instance of the application containing the linked document. An undefined value means there is no defined behavior for this link.

  • actuate Specifies when the link should be activated. The onRequest value indicates that the application will wait for the user to request that the link be followed. The onLoad value causes the link to be followed immediately. The onRequest value behaves like the HTML a element; onLoad behaves like the img element.


Extended Links

Extended links are similar to simple links, except they allow you to link to multiple links instead of just one link. An extended link consists of a set of linking resources and a set of connections between these resources. The linking resources may be local or remote. If all the resources are remote, the link is an out-of-line link. If all the resources are local, the link is an inline link. A local resource is contained in the extended link element and a remote resource is outside of the extended link element.

For more information about extended links, visit the specification Web site, at http://www.w3.org/TR/xlink/.

Summary

XML namespaces allow you to avoid naming collisions when you define elements and attributes using different DTDs or schemas. Namespaces can be defined with prefixes, or you can use default namespaces.

XPointer and XPath enable you to link to specific parts of an XML document. XPath can use patterns to identify sections of an XML document. XPointer allows you to do everything XPath can do, but also extends XPath to allow you to address points in the document and ranges between points. The range may not correspond to any one node. XLink enables you to create links within XML documents. In Chapter 7, we'll discuss an XML schema that enables you to validate data types, use namespaces, and check ranges of values.