Book HomeXML SchemaSearch this book

14.3. Foreign Attributes

Although xs:annotation is certainly the most flexible way to embed any information within a schema, W3C XML Schema defines a second opening in its vocabulary that may be used either as an alternative or in conjunction with annotations. All the W3C XML Schema elements (except xs:documentation and xs:appinfo) accept any attribute that has a namespace other than the W3C XML Schema namespace (unprefixed attributes are forbidden). Such attributes may be used to document a schema:

<xs:element name="author" type="author" doc:doc="This element
  describes the author of a book."
  xmlns:doc="http://dyomedea.com/ns/doc"/>

This approach is also used by SAF adornments, whose simple form can be embedded in attributes:

<xs:element name="author" type="author" sql:table="TBL_AUTHOR"
  xmlns:sql="http://www.extensibility.com/saf/spec/safsample/sql-map.saf"
  />

The huge opening given to attributes is especially interesting with attribute-only vocabularies such as XLink, and simple XLinks can be directly embedded into W3C XML Schema. The following example links the definition of our author element directly to a XSLT template:

<xs:element name="author" type="author"
  xlink:arcrole="http://www.w3.org/1999/xhtml"
  xlink:role="http://www.w3.org/1999/XSL/Transform"
  xlink:title="Author template" xlink:href="library.xslt#author"
  xmlns:xlink="http://www.w3.org/1999/xlink"/>

Unfortunately, because of the exception for xs:appinfo and xs:documentation, which do not accept foreign attributes, metadata cannot be added through attributes in these elements, so the following example is invalid:

<xs:element name="author" type="author">
  <xs:annotation> 
    <xs:appinfo
      xlink:arcrole="http://www.w3.org/1999/XSL/Transform"
      xlink:role="http://www.w3.org/1999/XSL/Transform"
      xlink:title="Author template" xlink:href="library.xslt#author"
      xmlns:xlink="http://www.w3.org/1999/xlink">
      <div class="resource">
        <h4>
          XSLT Transformation
        </h4>
        <p>
          This
          <a href="library.xslt#author">
            template
          </a>
          displays the description of an author.
        </p>
      </div>
    </xs:appinfo> 
    <xs:appinfo title="CSS Stylesheet"
      role="http://www.isi.edu/in-notes/iana/assignments/media-types/text/css"
      href="author.css">
      <div class="resource">
        <h4>
          CSS Stylesheet
        </h4>
        <p>
          A
          <a href="author.css">
            CSS stylesheet
          </a> 
          defining the styles which may be used to display an
          author.
        </p>
      </div>
    </xs:appinfo>
  </xs:annotation>
</xs:element>

Of course, the usual limitations of attributes apply here: attributes are less extensible than elements and they cannot include structured content.



Library Navigation Links

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