Previous Table of Contents Next


Simple Links in XML

In XML, all these links are called simple in-line links. Links connect resources—“anything which happens to be reachable by the use of a locator in some linking element.” (Resources include documents, but they also include graphics and other files.) The locator is a URL, defined the same way as URLs for HTML, and equally capable of using fragment identifiers. For in-line links, the element defining the link counts as one of those resources, and the target is the other. The classic HTML HREF link is an in-line link because it points only one direction: from the element that provides the link to the target location. (The “Back” button doesn’t count, in this example, as providing two-way linking.) The action taken when a link is actuated is called traversing, even if the link doesn’t “take” the actuator (which may be a user or a program) any place new.

A simple link in XML carries all its linking information in the linking element. There is no need in a simple link for the application to search out other elements carrying information about the locators—all the locator information is provided in the HREF attribute.

Building a true XML link isn’t exactly simple, however; it takes more than an HREF attribute for an element to be a link. A sample declaration for an element using simple links (taken from the 7/31/97 XML-Link Working Draft) follows:

  <!ELEMENT SIMPLE ANY>
   <!ATTLIST SIMPLE
      XML-LINK        CDATA                  #FIXED "SIMPLE"
      ROLE            CDATA                  #IMPLIED
      HREF            CDATA                  #REQUIRED
      TITLE           CDATA                  #IMPLIED
      INLINE          (TRUE|FALSE)           "TRUE"
      CONTENT-ROLE    CDATA                  #IMPLIED
      CONTENT-TITLE   CDATA                 #IMPLIED
      SHOW            (EMBED|REPLACE|NEW)   "REPLACE"
      ACTUATE         (AUTO|USER)           "USER"
      BEHAVIOR        CDATA                 #IMPLIED
   >
Link elements don’t have to be called SIMPLE—any element can be a link element. The SIMPLE element declaration is used, both here and in the Working Draft, only for illustration. In fact, any element can be a link—there is no need to create separate elements like the HTML A that exist solely to implement simple links.

The familiar HREF attribute is still there and works the same way as it did in HTML, although, as we’ll see later, it too has been extended. The rest of the attributes are new. The first link, XML-LINK, announces to the processing application that this element is in fact a linking element and that it is a simple link. The XML-LINK attribute is required for all links; defining it with a fixed value in the DTD is usually a better solution than spelling out this attribute in every single instance of the element.

Avoid the temptation to create documents and DTDs that use an HREF attribute without declaring XML-LINK. Even though they might work in HTML browsers, XML-LINK compliant processing applications will ignore the HREF attribute if the XML-LINK attribute is missing.

The ROLE attribute is optional (as are all the attributes marked #IMPLIED or provided with a default value here), allowing the link to specify the “meaning” of the link to the application processing the link. The ROLE attribute is intended for use only by machine processors—information meant for humans to read should be kept in the TITLE attribute. The HREF attribute provides the link with a locator, a URL as already described. The TITLE attribute, also optional, includes information that could, for example, pop up as the user rolls the mouse over a link much as the ALT tags for clickable images appear during rollovers in the latest versions of the Netscape and Microsoft browsers.

The TITLE attribute in XML has nothing to do with the TITLE element in HTML; it’s just an unfortunate overlap in name.


Previous Table of Contents Next