📄 0172-0174.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="0169-0171.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0175-0178.html">Next</A></CENTER></P><A NAME="PAGENUM-172"><P>Page 172</P></A><P>It is also what makes the EMBED value for theSHOW attribute meaningful.</P><P>In most circumstances, this simple form of the locator syntax is all thatyou will ever need. As I have said, it is equivalent to the familiar fragmentidentifiers in HTML, except that it is based on uniqueID values. These are certainly the most robust methods of addressing within an XML document,because they do not change simply from routine editing.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Tip:</TD></TR><TR><TD><BLOCKQUOTE>Because elements with attribute values of type ID can be referencedby this easy form of XML fragment identifier, it is a good idea to sprinkleyour XML documents with sensible ID values. In addition to making it easierfor you to cross-reference within and between your own XML documents,this makes life easier for other Web users who want to make links into parts ofyour XML documents. If someone else wants to refer to a specific part of anXML document that you have placed on the Web, that person can use thepreferred form of ID-based fragment identifier, but only if the element to be linkedto has been given an ID—by you.</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch09_ 27">The Rest of the XPointer Syntax</A></H4><P>Just in case you do need to use it, let's review the XPointer syntax in full.</P><P>The ultimate goal of an XPointer is to direct you to the correct elementwithin the target XML document. However, doing this is a bit like directingsomeone to a single house in your town; it is difficult to give perfect directionsin one try. You might start with a named landmark, give a direction, countstreets, and then describe houses. Here is an example:</P><!-- CODE SNIP //--><PRE>go to the Central Stationhead west on Station Roadtake the third tree-lined road on the leftit's the fourth house on the right-hand side</PRE><!-- END CODE SNIP //--><P>Each of these instructions is dependent on the traveler following theprevious instructions correctly.</P><P>XPointers work in exactly the same way. They are a sequence oflocation terms, which are either absolute locations or locations relative to the previousone. XPointers describe elements within the document in terms of variousproperties such as their type or attribute values, or simply by counting them.</P><A NAME="PAGENUM-173"><P>Page 173</P></A><P>A fragment identifier can contain a single XPointer or two XPointersseparated by the .. directive. If it has two XPointers, the fragment is assumed to beeverything from the start of the first XPointer's target to the end of thesecond one.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>You can't assume that a fragment that is specified by a pairof XPointers will be a meaningful chunk of the document. It is very unlikelyto be a single element, or even a whole number of elements. This limits whatan XML application can expect to do with such fragments.</BLOCKQUOTE></TD></TR></TABLE><P>Thus, the XPointer equivalent to the previous directions might look like this:</P><!-- CODE SNIP //--><PRE>go to the element with ID = "intro.notes"find the second <DIV3> element within this elementfind the fourth <P> within this <DIV3> element</PRE><!-- END CODE SNIP //--><P>This set of directions would be expressed as the following XPointer:</P><!-- CODE SNIP //--><PRE>ID(intro.notes)CHILD(2,DIV3)(4,P)</PRE><!-- END CODE SNIP //--><P>To put this more formally, each location term is defined in the context ofa location source, which is the place it starts from.</P><P>The XPointer syntax is based on an addressing system developed as part ofthe Text Encoding Initiative (TEI) guidelines. The TEI Extended Pointerscheme has been slightly simplified for use in XML. More importantly, the syntaxhas been adjusted so that XML's XPointers can sit comfortably inside URLs.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>Specifically, commas have replaced spaces within XPointers, so that itis not necessary to put in escape sequences for spaces within the URL. Also,the .. construction allows a pair of XPointers (representing a span withinthe target document) to be placed in a single URL. In the TEI scheme, the endsof a span are declared in two separateattributes—FROM and TO.</BLOCKQUOTE></TD></TR></TABLE><H5><A NAME="ch09_ 28">Absolute Location Terms</A></H5><P>Each XPointer starts with one of the following absolute location terms:</P><UL><LI> ROOT() confirms that the location source for the first location termis the root element.</UL><A NAME="PAGENUM-174"><P>Page 174</P></A><UL><LI> HERE() states that the location source for the first location term isthe linking element containing the locator. This can be usedmeaningfully only if the target is in the same document as the link.<LI>ID(Name) states that the location source for the first location termis the element with the specified ID (as in the previous example)<LI>DITTO() can be used only at the start of the second XPointer of apair. It states that the location source for the first location term isthe location that the first XPointer found.<LI>HTML(NAMEVALUE) states that the location source for the firstlocation term is the first element of type A that has aNAME attribute whose value matches NAMEVALUE.</UL><P>By default, the location source for the first location term is theroot element of the XML document that is the containing resource. This means that,strictly speaking, you never need to specifyROOT(). However, including ROOT() does make the intention of your XPointer clearer to a human reader.</P><H5><A NAME="ch09_ 29">Relative Location Terms</A></H5><P>When you have a starting point (a location source) for your XPointer, youcan use relative location terms to move around the target XML document.Each relative location term consists of a keyword, followed by one or moresteps. The allowed keywords are as follows:</P><UL><LI> CHILD selects child elements of the location source.<LI>DESCENDANT selects elements appearing within the content ofthe location source.<LI>ANCESTOR selects elements in whose content the location sourceis found.<LI>PSIBLING selects preceding sibling elements of the location source.<LI>FOLLOWING selects elements that appear after the location source.<LI>FSIBLING selects following sibling elements of the location source.</UL><P>By declaring a keyword, you limit the possible targets of a location termto elements that have the required property in relation to the locationsource. There might be zero or more. For example, if you move to an element withno preceding elements at the same level, thePREVIOUS keyword always fails. The elements that do match up are calledcandidate locations.</P><P><CENTER><A HREF="0169-0171.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0175-0178.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -