📄 0154-0157.html
字号:
<!DOCTYPE HTML PUBLIC "html.dtd"><HTML><HEAD><TITLE>Presenting XML:Linking with XML:EarthWeb Inc.-</TITLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"><SCRIPT><!--function displayWindow(url, width, height) { var Win = window.open(url,"displayWindow",'width=' + width +',height=' + height + ',resizable=1,scrollbars=yes');}//--></SCRIPT></HEAD><BODY BGCOLOR="#FFFFFF" VLINK="#DD0000" TEXT="#000000" LINK="#DD0000" ALINK="#FF0000"><TD WIDTH="540" VALIGN="TOP"><!-- <CENTER><TABLE><TR><TD><FORM METHOD="GET" ACTION="http://search.itknowledge.com/excite/cgi-bin/AT-foldocsearch.cgi"><INPUT NAME="search" SIZE="20" VALUE=""><BR><CENTER><INPUT NAME="searchButton" TYPE="submit" VALUE="Glossary Search"></CENTER><INPUT NAME="source" TYPE="hidden" VALUE="local" CHECKED> <INPUT NAME="bltext" TYPE="hidden" VALUE="Back to Search"><INPUT NAME="sp" TYPE="hidden" VALUE="sp"></FORM></TD><TD><IMG SRC="http://www.itknowledge.com/images/dotclear.gif" WIDTH="15" HEIGHT="1"></TD><TD><FORM METHOD="POST" ACTION="http://search.itknowledge.com/excite/cgi-bin/AT-subscriptionsearch.cgi"><INPUT NAME="search" SIZE="20" VALUE=""><BR><CENTER><INPUT NAME="searchButton" TYPE="submit" VALUE=" Book Search "></CENTER><INPUT NAME="source" TYPE="hidden" VALUE="local" CHECKED> <INPUT NAME="backlink" TYPE="hidden" VALUE="http://search.itknowledge.com:80/excite/AT-subscriptionquery.html"><INPUT NAME="bltext" TYPE="hidden" VALUE="Back to Search"><INPUT NAME="sp" TYPE="hidden" VALUE="sp"></FORM></TD></TR></TABLE></CENTER> --><!-- ISBN=1575213346 //--><!-- TITLE=Presenting XML//--><!-- AUTHOR=Richard Light//--><!-- PUBLISHER=Macmillan Computer Publishing//--><!-- IMPRINT=Sams//--><!-- CHAPTER=09 //--><!-- PAGES=0147-0178 //--><!-- UNASSIGNED1 //--><!-- UNASSIGNED2 //--><P><CENTER><A HREF="0151-0153.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0158-0161.html">Next</A></CENTER></P><A NAME="PAGENUM-154"><P>Page 154</P></A><P>The following points sum up the world of HTML links using XML-Link <BR>terminology:</P><UL><LI> Within HTML pages,<a> elements are used as linking elements.<LI> Any<a> element containing an HREF attribute specification is alinking element, specifying an inline link.<LI> Any<a> element containing a NAME attribute specification ispotentially a resource in one or more links, although it has no means ofknowing in what links it is participating.<LI> HTML links are normally traversed by user action—clicking onthe linking element.<LI> The HTML linking scheme offers no way of expressingmultidirectional or out-of-line links.</UL><H3><A NAME="ch09_ 8">Identifying XML Links</A></H3><P>Before you can do clever things with your links, you first have to findthem. As I already noted, XML needs to give users the freedom to say that anyelement type in their applications is to act as a linking element. So how doyou specify in XML which elements are to be treated as links?</P><P>This is achieved by specifying the reserved attributeXML-LINK for each element that is to act as a linking element. In addition, the value of theXML-LINK attribute indicates what type of link the element expresses. For example,this tells an XML processor that it is dealing with a simple (inline) link:</P><!-- CODE SNIP //--><PRE><A XML-LINK="SIMPLE" HREF="http://www.w3.org/">The</A> W3C</A></PRE><!-- END CODE SNIP //--><P>The full list of link types supported by XML is as follows:</P><UL><LI> SIMPLE: A simple inline link<LI> EXTENDED: An extended or out-of-line link<LI> LOCATOR: A locator, pointing to an actual target resource<LI> GROUP: An extended link group<LI> DOCUMENT: An extended link document</UL><P>Of these, only SIMPLE and EXTENDED are actual linking elements; the othersplay supporting roles, which will be described later in this chapter.</P><A NAME="PAGENUM-155"><P>Page 155</P></A><H4><A NAME="ch09_ 9">Fixed XML-LINK Attributes</A></H4><P>To avoid having to declare the special XML-LINK attribute every time youuse an element, you can declare it one time as follows, in the DTD, as a fixedvalue and then forget about it:</P><!-- CODE SNIP //--><PRE><!ATTLIST MYLINKXML-LINK CDATA #FIXED "SIMPLE"></PRE><!-- END CODE SNIP //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>The preceding attribute list specification says "the<MYLINK> element always has an XML-LINK attribute with the value"SIMPLE" whenever it occurs."</BLOCKQUOTE></TD></TR></TABLE><P>With that declaration out of the way, your XML<MYLINK> links start to look just like HTML hyperlinks:</P><!-- CODE SNIP //--><PRE><MYLINK HREF="http://www.w3.org/">The</A> W3C</MYLINK></PRE><!-- END CODE SNIP //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>A technical issue has arisen over the placing of this defaultdeclaration. If it lives in the main DTD (its external DTDsubset), an XML client has the overhead of downloading the whole DTD in order to find outabout linking rules. If it lives in the internal DTD subset, which is transmittedwith the document, this breaks SGML interoperability unless the element'sother attributes are declared there as well. SGML currently mandates that youcan have only one attribute list declaration per element. It is almost certainthat this issue will be resolved by a forthcoming change to the SGML standard.If not, a new mechanism for flagging links to XML would have to be defined.</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch09_ 10">Declaring Your Own XML-LINK Attributes</A></H4><P>The XML-LINK specification declares that certain attributes are to betreated specially. This could be a major headache if your own XML applicationalready uses one or more of those attributes for another purpose. This isquite possible, because only one of these attributes(XML-LINK) begins with the reserved prefix XML. Some attribute names, such asROLE and TITLE, could easily be used for other purposes. For that reason,XML-LINK provides a mechanism that it calls attributeremapping, which allows you to change the attributesthat are significant for linking within XML.</P><A NAME="PAGENUM-156"><P>Page 156</P></A><P>The XML-ATTRIBUTES attribute is used to accomplish attribute remapping fora given type of linking element. It should take a value consisting of pairs ofnames, with each pair being the name of an attribute that is significant to XML,followed by the name of the attribute that is to actually fulfill this function.Here is an example:</P><!-- CODE //--><PRE><!ATTLIST person-link ROLE CDATA #IMPLIED XML-LINK CDATA #FIXED "SIMPLE" LINK-ROLE CDATA #IMPLIED XML-ATTRIBUTES CDATA #FIXED "ROLE LINK-ROLE"></PRE><!-- END CODE //--><P>This example maps the XML-LINK concept of role to theLINK-ROLE attribute for the person-link element type, which allows aperson-link element to take the following form:</P><!-- CODE SNIP //--><PRE><person-link role="parent" link-role="footnote"></PRE><!-- END CODE SNIP //--><P>In this example, role="parent" indicates the role that the person isplaying, and link-role="footnote" describes the role that the link is to have.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>When remapping attributes, remember that you are not allowedto use any attributes beginning with XML. It would be tempting, but wrong,to remap the ROLE attribute to XML-ROLE.</BLOCKQUOTE></TD></TR></TABLE><H3><A NAME="ch09_ 11">Information Associated with <BR>XML Links</A></H3><P>HTML provides some attributes you can use to add value to your links,in addition to the HREF and NAME attributes already covered. These attributesinclude the following:</P><UL><LI> REL: The relationship of this resource to the destination of link<LI> REV: The relationship of the link destination to this resource<LI> TITLE: A description of the nature of the link<LI> CHARSET: The character encoding of the text at the link destination</UL><P>Like HTML, XML allows you to associate additional information withyour links. However, the XML-Link specification carefully defines how keyaspects of this additional information are used. This gives you an importantadditional level of control over the way your links behave.</P><A NAME="PAGENUM-157"><P>Page 157</P></A><P>This section reviews all of the information associated with XML linking elements.</P><H4><A NAME="ch09_ 12">Resources</A></H4><P>Every locator within an XML simple link or extended link must identifya resource. This is specified by the value of theHREF attribute. The value of HREF is always a URL, like this one:</P><!-- CODE SNIP //--><PRE><A HREF="http://www.w3.org/">The</A> W3C</A></PRE><!-- END CODE SNIP //--><P>This is just the same as in HTML, except that for locators within XMLdocuments, the HREF attribute value must always be specified, whereasA elements in HTML do not have to specify HREF.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>I deal with the case of a target resource that is a fragment of anXML document later in this chapter, in the section called "Addressing."</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch09_ 13">Link Behavior</A></H4><P>XML gives you the chance to control how links behave. The informationdescribed in this section can be applied to both simple and extended XML links.</P><P>Let's start by describing the behavior of HTML links. When you click onan <A> link in HTML, the browser follows the link and returns its targetresource to you. (Note that this isn't always another page; depending on the URL,it might be an ftp download or an invitation to send an e-mail.) This processis called traversing the link. In HTML, you can always see that the link isthere, and it is never traversed until you take action by clicking on it.</P><P>When you author an XML document, you have a much wider range ofoptions. However, you can only state a policy for your links. It is up to theXML application to decide how to best implement that policy.</P><P>First, the SHOW attribute lets you control how the resources that you link toare displayed and processed. It has three possible values:</P><UL><LI> EMBED: The target resource is embedded into the body of theresource where the traversal started.<LI> REPLACE: The target resource replaces the resource where thetraversal started.<LI> NEW: The target resource is displayed in a new context, notaffecting that of the resource where the traversal started.</UL><P><CENTER><A HREF="0151-0153.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0158-0161.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -