📄 0162-0164.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="0158-0161.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0165-0168.html">Next</A></CENTER></P><A NAME="PAGENUM-162"><P>Page 162</P></A><P>This definition automatically gives allbroad-term elements the desired attribute values by default. Now all you need to do each time you include abroad-term element is specify the HREF attribute value, like this:</P><!-- CODE SNIP //--><PRE><broad-term HREF="mats.xml">materials</broad-term></PRE><!-- END CODE SNIP //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>In fact, it would be an error to specify another value for theROLE attribute within the broad-term element, because the default value is#FIXED.</BLOCKQUOTE></TD></TR></TABLE><P>When you include the additional information about the behavior of eachlinking element type as a set of default values in the DTD, you gain the benefitsof that information without any extra work at the marking-up stage.</P><P>In XML, you don't need to limit yourself to a single linking element, asyou often do in HTML. You can declare any number of different elementtypes, representing all the different styles of simple links that your applicationrequires. For the thesaurus example, you might have the following element types:</P><UL><LI> broad-term<LI> narrow-term<LI> see-also<LI> use-for</UL><H4><A NAME="ch09_ 17">Simple Links and Resources</A></H4><P>A simple link is an example of an inline link. As you have seen, this meansthat it acts as one of its own resources. What exactly is this resource? Theanswer becomes clearer when you realize that it is an element; the linking elementis the resource. If that element has any content, the resource includes that content.</P><P>XML allows you to state whether or not you want your linking elements tobe considered as a resource of the link. All linking elements have theattribute INLINE. This attribute can take the valuesTRUE, which means that the linking element is a resource of the link, andFALSE, which means that it is not considered to be a resource. By default,INLINE takes the value TRUE.</P><A NAME="PAGENUM-163"><P>Page 163</P></A><P>If the linking element is a resource of the link, you need to be able toprovide additional information about this inline resource(TITLE and ROLE). For a simple link, there is nowhere to put this information because these attributes arealready used for the title and role of the target resource. As a result, XMLdefines two additional special attributes,CONTENT-TITLE and CONTENT-ROLE, which describe the linking element's own role within the link.</P><P>As an example, you might extend the attribute list for thebroad-term element within the thesaurus application. By including aCONTENT-ROLE as well as a ROLE, you can indicate that the current term is a narrow term(NT) of the broad term to which you are linking:</P><!-- CODE //--><PRE><!ATTLIST broad-term XML-LINK CDATA #FIXED "SIMPLE" ROLE CDATA #FIXED "BT" CONTENT-ROLE CDATA #FIXED "NT" HREF CDATA #REQUIRED ...</PRE><!-- END CODE //--><P>In HTML, you are used to linking elements containing a short phrasethat acts as a cue for the link:</P><!-- CODE SNIP //--><PRE><A HREF="http://www.w3.org/">The</A> W3C</A></PRE><!-- END CODE SNIP //--><P>So in XML's terms, this phrase is part of the resource at the near end ofthe link.</P><P>It is quite possible for an XML simple link to contain a resource that is notsimply a phrase for the application to underline. At one extreme, nothing stopsa simple link from being expressed by an empty element. At the other extreme,a linking element could contain a large amount of subelements and data content.</P><P>Why does this matter? For one thing, it will be less convenient to indicatethat the link exists if there is nothing to underline (for the empty element), orif you have to underline several pages.</P><P>More importantly, the SHOW attribute allows the behavior"EMBED". You need to be aware of the implications of using this strategy, particularly if yoursimple links have significant contents. If you traverse an"EMBED" link, the target of the link will be displayed at the location where the traversal started.However, the XML-Link specification doesn't make clear exactly where that will bein relation to the content of the element containing your simple link. Ingeneral, it's probably a good practice to keep the contents of linking elements small.</P><A NAME="PAGENUM-164"><P>Page 164</P></A><H4><A NAME="ch09_ 18">Simple Links and Link Rot</A></H4><P>A simple link is a one-way street to its destination. Although an XMLprocessor, like an HTML browser, might be able to go back from the target of alink to the link element (the source of the link), this is not mandated by theXML standard. And, as with HTML, nothing in the target document tells it thatit is being pointed at. Therefore, XML simple links are subject to the sameills that beset HTML hyperlinks—in particular, the "link to nowhere,"pointing to a page or document that no longer exists.</P><H3><A NAME="ch09_ 19">Extended Links</A></H3><P>The XML extensions for simple links are useful, but XML simple linksshare the fundamental limitations of all inline links. The real breakthroughcomes with extended links. Have you ever wanted to be able to make your linkstwo-way, and fudged them by putting in two one-way links? Or have youwanted to link to more than one target, but resorted to putting in several links sideby side? XML extended links enable you to do these things cleanly.</P><P>How does this work? Surprisingly, the one thing holding back simplelinks from doing greater things is the most obvious thing you do with them,which is putting them into your text at the place from which you want the linkmade. As I have said, this makes them inline links. What you need for greaterflexibility is an out-of-line link.</P><H4><A NAME="ch09_ 20">Out-of-Line Links</A></H4><P>I've already defined out-of-line links in the "Some Linking Concepts"section earlier in this chapter. Now let's try to understand the concept. (InChapter 13, "Developing an XML Memo Application," the section "Advancedlinking—Out-of-Line Links" provides a practical example of this concept.)</P><P>The basic idea is simple enough. Suppose you have two related paragraphsin your XML document that you want to link together. You could put in acouple of simple inline links, one in each direction, like this:</P><!-- CODE //--><PRE><P ID="para.1"><LINK HREF="#para.3">In general terms ... </LINK></P><P ID="para.2"> ... </P><P ID="para.3"><LINK HREF="#para.1"> Specifically, ...</LINK></P></PRE><!-- END CODE //--><P><CENTER><A HREF="0158-0161.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0165-0168.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -