📄 0175-0178.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="0172-0174.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="../ch10/0179-0182.html">Next</A></CENTER></P><A NAME="PAGENUM-175"><P>Page 175</P></A><P>The keyword is followed by one or more steps. Each step defines aninstance, an optional element type, and an even more optional attribute type and value.</P><P>The instance counts the candidate locations. It can be a positive number(found by counting forward from the first candidate location), a negativenumber (counting backward from the last candidate location), or the special value"ALL", which means all candidate locations are selected. Here are some examples:</P><!-- CODE SNIP //--><PRE>(4) - select the fourth candidate location(-2) - select the second-to-last candidate location</PRE><!-- END CODE SNIP //--><P>The instance is followed by a comma and anelement type, which can take the following values:</P><UL><LI> The*CDATA value selects pseudo-elements containing only text.<LI> The * value selects any element type.<LI> The . value selects elements only.<LI> TheName value selects elements with the type Name from thecandidate locations.</UL><P>Here are some examples:</P><!-- CODE //--><PRE>(4,DIV1) - select the fourth <DIV1> element from the candidate locations(-1,EXAMPLE) - select the last <EXAMPLE> element from the candidate locations(3,*CDATA) - select the third untagged span of text from the candidate locations</PRE><!-- END CODE //--><P>The element type, if specified, can be qualified by an attribute name and value.</P><P>The attribute name can take the following values:</P><UL><LI> The * value matches any attribute name.<LI> The Name value specifies the attribute type Name.</UL><P>The attribute value can take the following values:</P><UL><LI> The*IMPLIED value matches attributes for which no value wasspecified and no default exists.<LI> The * value matches any value.<LI> TheName value matches the value Name, normalized intouppercase and with spaces normalized.<LI> The"value" value matches the value that is quoted.</UL><A NAME="PAGENUM-176"><P>Page 176</P></A><P>Here is an example:</P><!-- CODE SNIP //--><PRE>CHILD(1,FS,RESP,*IMPLIED)</PRE><!-- END CODE SNIP //--><P>This example selects the first <FS> element with theRESP attribute left unspecified, which is a child of the location source.</P><H5><A NAME="ch09_ 30">String-Match Location Terms</A></H5><P>All of the absolute and relative location terms that I have described haveas their target one or more complete elements. In order to allow text withinan element to be the target of an XPointer, theSTRING() location term is provided. If used,STRING() must be the last location term in the XPointer.</P><P>The STRING() location term takes the following three arguments:</P><UL><LI> A number that indicates which occurrence of the specified stringis required.<LI> The string to be matched.<LI> A number that indicates how many characters to count forwardfrom the start of the matched string.</UL><P>All three arguments must be provided every timeSTRING() is used. For example, this XPointer points to the ninth character after the start of the secondoccurrence of the string "Location Term" in the whole document:</P><!-- CODE SNIP //--><PRE>ROOT()STRING(2,"Location\Term",9)</PRE><!-- END CODE SNIP //--><P>This character is the letter T at the start ofTerm.</P><P>This XPointer selects the character immediately following the fifthexclamation mark within the element with an ID value equal toa27:</P><!-- CODE SNIP //--><PRE>ID(a27)STRING(5,'!',1)</PRE><!-- END CODE SNIP //--><P>This definition means that the target of aSTRING() location term is always a single character. To mark a range of characters, such as the actual phrase <BR>"Location Term", you need to use a span. This XPointer points to therange of characters from the beginning (offset 0) to the end (offset 12) of thesecond occurrence of "Location Term" in the document:</P><!-- CODE SNIP //--><PRE>ROOT()STRING(2,"Location\Term",0)..ROOT()STRING(2,"Location\Term",12)</PRE><!-- END CODE SNIP //--><P>All of the character data within the location source is used when looking fora string match. Markup is ignored completely. The matching has to be exact;it</P><A NAME="PAGENUM-177"><P>Page 177</P></A><P>is case sensitive, and all spaces have to be exactly as specified inSTRING(). Therefore, the "Location Term" example given previously would matchthe string within</P><!-- CODE SNIP //--><PRE><p>It is a <emph>Location</emph> Term ...</PRE><!-- END CODE SNIP //--><P>However, the newline (which does not match the space in theSTRING() location term) means that the following markup will not give a match:</P><!-- CODE SNIP //--><PRE><p>It is a <emph>Location</emph>[Term ...</PRE><!-- END CODE SNIP //--><H3><A NAME="ch09_ 31">Extended Link Groups</A></H3><P>Because XML supports extended (out-of-line) links—which do not haveto occur within either, or any, of the documents they point to—you needsome means of telling an XML application where to find them. XML achievesthis with extended link groups, which simply list the documents that combineto form an interlinked group.</P><P>The GROUP element contains one or more DOCUMENT elements, each pointingto a resource (or a sub-resource, using the XPointer syntax) that is consideredto form part of the document group.</P><P>For example, if an XML document contains</P><!-- CODE //--><PRE><GROUP><DOCUMENT HREF="http://www.mysite.org/links1.xml"/></A><DOCUMENT HREF="http://www.mysite.org/links2.xml"/></A></GROUP></PRE><!-- END CODE //--><P>where GROUP and DOCUMENT have XML-LINK values of GROUP andDOCUMENT, then an XML processor would process the documentslinks1.xml and links2.xml looking for links that involve this document.</P><P>It is possible that the resource identified byDOCUMENT will itself contain GROUP elements that point to yet more linked documents. These could point toeven more documents, including the one you started with. To avoid situationslike this, which could lead to endless program loops in XML applications, theDOCUMENT element has a STEPS attribute. This allows authors to indicate howmany steps of Extended Link Group processing it makes sense for an XML linkprocessor to carry out. In this example, the link processor is advised toprocess Extended Link Groups in the starting document, and those that it findsin links1.xml and links2.xml. It is advised that it should then stop.</P><A NAME="PAGENUM-178"><P>Page 178</P></A><!-- CODE //--><PRE><GROUP STEPS="2"><DOCUMENT HREF="http://www.mysite.org/links1.xml"/></A><DOCUMENT HREF="http://www.mysite.org/links2.xml"/></A></GROUP></PRE><!-- END CODE //--><H4><A NAME="ch09_ 32">Summary</A></H4><P>This chapter reviewed XML's linking facilities. You learned how XML'slinking builds upon the Web's current hypertext facilities by using URLsand interoperating with HTML hyperlinks.</P><P>However, XML links allow users to control the behavior of links muchmore closely, and they provide support for two-way and multidirectionallinking through the concept of out-of-line links.</P><P>I reviewed the methods by which XML allows you to address any singleelement or span of elements as a link target within an XML document.</P><P>Finally, you learned how you can help an XML processor to findout-of-line links that involve the current document but are not physically stored <BR>within it.</P><P><CENTER><A HREF="0172-0174.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="../ch10/0179-0182.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -