Book HomeXML in a Nutshell

10.6. DTDs for XLinks

For a document that contains XLinks to be valid, all the XLink attributes that the document uses have to be declared in a DTD just like any other attributes. In most cases some of the attributes can be declared #FIXED, and then they do not need to be explicitly included in the document itself. For example, this DTD fragment describes the novel element seen earlier:

<!ELEMENT novel  (title, author, year)>
<!ATTLIST novel  xmlns:xlink CDATA   #FIXED 'http://www.w3.org/1999/xlink'
                 xlink:type (simple) #FIXED 'simple'
                 xlink:href  CDATA   #REQUIRED>
<!ELEMENT title  (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT year   (#PCDATA)>

Given this DTD to fill in the fixed attributes xmlns:xlink and xlink:type, a novel element only needs an xlink:href attribute to be a complete simple XLink:

<novel xlink:href = "urn:isbn:0688069444">
  <title>The Wonderful Wizard of Oz</title>
  <author>L. Frank Baum</author>
  <year>1900</year>
</novel>

Documents that contain many XLink elements often use parameter entity references to define the common attributes. For example, suppose novel, anthology, and nonfiction are all simple XLink elements. Their XLink attributes could be declared in a DTD like this:

<!ENTITY % simplelink
  "xlink:type (simple) #FIXED 'simple'
   xlink:href  CDATA   #REQUIRED
   xmlns:xlink CDATA   #FIXED 'http://www.w3.org/1999/xlink'
   xlink:role  CDATA   #IMPLIED
   xlink:title CDATA   #IMPLIED
   xlink:actuate (onRequest | onLoad | other | none) 'onRequest'
   xlink:show (new | replace | embed | other | none) 'new'"
>
<!ATTLIST anthology   %simplelink;>
<!ATTLIST novel       %simplelink;>
<!ATTLIST nonfiction  %simplelink;>

Similar techniques can be applied to declarations of attributes for extended XLinks.



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.