📄 0100-0103.html
字号:
<!DOCTYPE HTML PUBLIC "html.dtd"><HTML><HEAD><TITLE>Presenting XML:Logical Structures in XML Documents: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=06 //--><!-- PAGES=0085-0108 //--><!-- UNASSIGNED1 //--><!-- UNASSIGNED2 //--><P><CENTER><A HREF="0097-0099.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0104-0106.html">Next</A></CENTER></P><A NAME="PAGENUM-100"><P>Page 100</P></A><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>XML makes itself more restrictive than SGML by definingmixed-content declarations in this way. Content models that combine#PCDATA and other elements in any way other than the preceding form are illegal inXML. Therefore, many content models in existing SGML DTDs need to berewritten to be valid in an XML context.</BLOCKQUOTE></TD></TR></TABLE><H3><A NAME="ch06_ 27">Cross-References and Links</A></H3><P>The basic XML language provides a considerable amount of power toexpress cross-references within an XML document and links to resources outsideit. This is in addition to the power linking facilities that come withXML-Link (which is described in Chapter 9, "Linking with XML"). This sectionsummarizes what you can already do by just using the standard attribute typesthat XML supports.</P><H4><A NAME="ch06_ 28">Internal Cross-References</A></H4><P>The ID and IDREF attribute types are tailor-made for the task of makingreference from one part of an XML document to another. This technique canbe useful for a whole variety of reasons:</P><UL><LI> Citing a bibliographic reference that is held elsewhere—forexample, in a bibliography<LI> Pointing to a footnote<LI> Putting in "see also" references</UL><P>It is likely that XML-aware software will provide built-in support forID to IDREF hyperlinks. This will include the capability to indicate the presence of across-reference and, where appropriate, to traverse to the target of the cross-<BR>reference.</P><P>ID attributes give elements an identifier that is guaranteed to be uniquewithin the XML document. (If an ID isn't unique, the document isn't valid.)This uniqueness makes ID attribute specifications a ready-made target for cross-<BR>references. (As you will see in Chapter 9, they are also a handy target forXML XPointers.)</P><A NAME="PAGENUM-101"><P>Page 101</P></A><P>By convention, attributes with type ID are given the nameID, although nothing in the XML specification enforces this approach. It just makes lifeeasier for everyone. Here is an example:</P><!-- CODE SNIP //--><PRE><ATTLIST PERSONID ID #IMPLIED ></PRE><!-- END CODE SNIP //--><P>Again, there is no reason why XML-aware editing software shouldn't beable to assign unique values to each ID type attribute, saving you the effort ofinventing your own names or codes and ensuring that they are unique.</P><P>IDREF and IDREFS attribute types have one purpose in life: to point toID attribute types. If an IDREF or IDREFS attribute value contains an entry thatdoesn't match an ID, the XML document is invalid.</P><P>Setting up a cross-reference is very simple. First you ensure that the targetelement has a unique ID, like this:</P><!-- CODE //--><PRE><bibl ID="bib.5"><auth>Goldfarb, Charles</auth><date>1990</date><title>The SGML Handbook</title></bibl></PRE><!-- END CODE //--><P>Then you quote that ID in your cross-reference, like this:</P><!-- CODE SNIP //--><PRE><p>As we can see from <ref TARGET="bib.5">The SGMLHandbook</ref>, ...</PRE><!-- END CODE SNIP //--><P>Job done! When browsing your completed XML document, you cannow expect the phrase The SGML Handbook to be underlined and "hot," just likeA elements in HTML. Click on it, and you jump to the fullcitation.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>These internal links can be put to a wide variety of uses; hyperlinks area very simple application. The fact that the target of the link is anelement, rather than just a point (as in an HTML internal link), means that XMLapplications can do a whole range of useful things by traversing these internal links.In effect, they add the possibility of processing XML documents in anonlinear manner.</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch06_ 29">External Linking</A></H4><P>XML documents can make reference to non-XML resources that areoutside the document. Here are some obvious examples:</P><UL><LI> Image files<LI> Video clips</UL><A NAME="PAGENUM-102"><P>Page 102</P></A><UL><LI> Audio clips<LI> Word processor files<LI> Java applets</UL><P>The built-in mechanism for linking these external resources is more formaland less direct than the HTML equivalent. In HTML, you just use a standardURL and expect the browser and server to work out between them what typeof resource is being addressed. The following line implies a link to an imageof type GIF:</P><!-- CODE SNIP //--><PRE><img src="/Images/bump.gif"></PRE><!-- END CODE SNIP //--><P>XML makes the type of the target explicit through its use ofnotations.</P><P>Before you can link to an external entity from an XML document, youmust declare it in the document's DTD. An external entity declaration lookslike this:</P><!-- CODE SNIP //--><PRE><!ENTITY fig.bump SYSTEM "/Images/bump.gif" NDATA GIF></PRE><!-- END CODE SNIP //--><P>This declaration specifies the GIF notation through the value given tothe NDataDecl, which is the Nmtoken followingNDATA. This notation, in turn, must be declared:</P><!-- CODE SNIP //--><PRE><!NOTATION GIF SYSTEM "http://www.mainsite.com/support/gviewer.exe"></A></PRE><!-- END CODE SNIP //--><P>Now you are free to use the name fig.bump to link the image file to yourXML document. If the XML version of your HTML DTD defines theSRC attribute of img as having type ENTITY orENTITIES, as in</P><!-- CODE SNIP //--><PRE><!ATTLIST IMG SRC ENTITY #REQUIRED</PRE><!-- END CODE SNIP //--><P>you can link to the image file in a manner similar to the earlier HTML case,as follows:</P><!-- CODE SNIP //--><PRE><img src="fig.bump"></PRE><!-- END CODE SNIP //--><P>But in this case, the entity name is the value of theSRC attribute, rather than its actual filename orURL.</P><H3><A NAME="ch06_ 30">Groves</A></H3><P>Groves do not appear on the scene until Chapter 10, "The XML StyleMechanism." However, they are a logicalstructure that is fundamental to how XML</P><A NAME="PAGENUM-103"><P>Page 103</P></A><P>works (or at least to how XML documents will be exploited effectively), andas such I will cover them here.</P><P>A grove is a new way to look at an XML document that makes its contentmuch more tractable to object-oriented programming techniques. Groves providea method of delivering only those aspects of a document (or parts thereof)that are required for a particular purpose.</P><P>This section is provided mainly for the technically minded reader who iseager to understand the potential use of groves when developing XMLapplications. It can quite safely be skipped if it ceases to make sense to you at any point.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>In the following discussion, I have made every effort to explainthe logic of groves as I understand it. I have not made a major effort to usethe exact terminology used by the DSSSL standard from which the explanationis derived. If you understand my explanations and want to take things further,be sure to check out the DSSSL standard for an authoritative use of terminology.</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch06_ 31">Classes and Properties</A></H4><P>Your goal is to present an XML document as a well-organized stream ofobjects that can be treated, at some basic level, in a consistent manner. Eachobject will be a member of a class, which might be derived from some base class.Each class will have its own set of properties. Some of these properties will beinherited from its base class, and others will be unique to that particular class.Each actual object will exhibit a value for some or all of the properties of its class.</P><P>If that sounds like a reasonable basis for an object-oriented approach,consider what you have with XML. In order to process the wide range of differentstructures that make up an XML document, I will generalize things a little bit.</P><P>First of all, the different logical structures you have encountered whileexploring XML (such as elements, comments, and processing instructions) canbe considered your classes. Next, if you say that each class has a propertycalled class name, all of your XML logical structures will have thisproperty:</P><!-- CODE //--><PRE>Class: class name="element"Class: class name="comment declaration"Class: class name="processing instruction"</PRE><!-- END CODE //--><P><CENTER><A HREF="0097-0099.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0104-0106.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -