0113-0116.html

来自「Presenting XML.rar,详细介绍有关XML的知识」· HTML 代码 · 共 456 行

HTML
456
字号
<!DOCTYPE HTML PUBLIC "html.dtd"><HTML><HEAD><TITLE>Presenting XML:Physical 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=07 //--><!--  PAGES=0109-0122 //--><!--  UNASSIGNED1 //--><!--  UNASSIGNED2 //--><P><CENTER><A HREF="0109-0112.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0117-0120.html">Next</A></CENTER></P><A NAME="PAGENUM-113"><P>Page 113</P></A><P>In order for an XML document to be well-formed, any parameter entityit contains must be declared before it is referred to.</P><H3><A NAME="ch07_ 6">Uses for Entities</A></H3><P>What are entities good for? The following list shows the variety of usesof entities:</P><UL><LI>     Represent non-standard characters within your XML documents.<LI>     Function as shorthand for frequently used phrases.<LI>     Hold chunks of markup that might appear in more than oneXML document.<LI>     Hold sections or chapters from a large XML document.<LI>     Organize your DTD into logical units.<LI>     Represent non-XML resources.</UL><H4><A NAME="ch07_ 7">Non-Standard Characters</A></H4><P>The following example shows an XML text entity being used to representan e-acute symbol (&eacute;):</P><!--  CODE SNIP //--><PRE>Fernand L&amp;eacute;ger</PRE><!--  END CODE SNIP //--><P>Using eight characters to represent one might seem inefficient. However,accented characters are particularly vulnerable when documents are movedamong different computer platforms, because only the first 128 characters of theASCII character set are used consistently on PCs, Macs, and UNIX systems. Usinga text entity to represent accented characters has the following advantages:</P><UL><LI>    Only characters that appear in 7-bit ASCII are used in theentity reference.<LI>     The result, while not particularly easy to read, is at least clear tothe human reader, because eacute is a reasonable mnemonic forthe character it represents.</UL><P>A useful SGML practice that could be adopted in XML applications is tohave entity sets. Entity sets give standard entity names to groups of relatedcharacters, as in the following examples:</P><UL><LI>ISOlat1: Latin alphabetic characters used in WesternEuropean languages, apart from uppercase and lowercase letters.</UL><A NAME="PAGENUM-114"><P>Page 114</P></A><UL><LI>ISOgrk1: The letters of the Greek alphabet.<LI>     ISOnum: Numeric and special graphic characters.</UL><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>There are two other ways to deal with characters that fall outsidethe ASCII character set. Character references (described later in this chapter)can be used to represent any ISO 10646 character directly by its numericor hexadecimal representation. And if the number of such characters warrantsit, the whole text entity can be encoded using an ISO 10646 encoding inwhich they can be encoded natively.</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch07_ 8">Frequently Used Phrases</A></H4><P>If your documents contain phrases that appear repeatedly, you can benefitfrom using text entities to represent them. For example, when preparing thisbook I found that I was making frequent cross-references to other chapters.Sams.net Publishing's house style requires these to appear with the chapternumber, followed by its title:</P><!--  CODE SNIP //--><PRE>&lt;p&gt;In Chapter 5, &lt;q&gt;The XML Approach&lt;/q&gt;, ...</PRE><!--  END CODE SNIP //--><P>I encoded the chapter headings as entity references, like this:</P><!--  CODE SNIP //--><PRE>&lt;p&gt;In Chapter 5, &amp;chap5;, ...</PRE><!--  END CODE SNIP //--><P>And this encoding produced the following advantages:</P><UL><LI>     Speed: After I declared the chapter heading entities, I was able toselect their names from a drop-down list in my editing program, and Ihad to type the full headings only once (when declaring my entities).<LI>     Consistency: There is no possibility of mistyping an individualcross-reference.<LI>     Flexibility: If I decide to rename a chapter heading at a later date,I have to update only my entity declaration for that chapter toensure that all the cross-references to it will be correct.</UL><H4><A NAME="ch07_ 9">Chunks of Markup</A></H4><P>Entities can also be applied to larger chunks of marked-up text. Forexample, if your company has a standard set of conditions for its contracts, thesecould be encoded in a separate file and declared as anexternal entity. When these conditions are updated, all documents that refer to them will automaticallybe updated too.</P><A NAME="PAGENUM-115"><P>Page 115</P></A><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>Be sure that the markup within these chunks is balanced.Remember that an entity must contain a whole number of elements, plusoptional character data at the start and end. Also, be aware that it is possible to insertan entity declaration into your documents at a point where the markup itcontains is not allowed.</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch07_ 10">Sections of Documents</A></H4><P>Large multi-authored XML documents can usefully be managed bybreaking them into sections and working on each section separately. For example,this book was written as approximately 20 XML documents&#151;one per chapterand one per appendix. The whole book was then put together quickly by havinga series of entity references pull in the individual chapters:</P><!--  CODE //--><PRE>&lt;doc&gt;&lt;body&gt;&amp;chapter1;&amp;chapter2;&amp;chapter3;...&amp;appendixd;&lt;/body&gt;&lt;/doc&gt;</PRE><!--  END CODE //--><P>One point to watch in this situation is that the embedded chapters mustcontain only markup. They cannot have their own&lt;!DOCTYPE declaration:</P><!--  CODE SNIP //--><PRE>&lt;chapter&gt;&lt;head&gt;1. Beginnings&lt;/head&gt;&lt;p&gt; .... &lt;/p&gt;&lt;/chapter&gt;</PRE><!--  END CODE SNIP //--><P>This makes it rather tricky to treat them as XML documents in their ownright. One way around this problem is to have a separate file whose only purposeis to act as the document entity for a single chapter:</P><!--  CODE //--><PRE>&lt;?XML version=&quot;1.0&quot;?&gt;&lt;!DOCTYPE chapter SYSTEM &quot;mydoc.dtd&quot; [&lt;!ENTITY chapter1 SYSTEM &quot;chap1.xml&quot;&gt;]&gt;&amp;chapter1;</PRE><!--  END CODE //--><H4><A NAME="ch07_ 11">Organizing Your DTD</A></H4><P>Parameter entities are particularly useful when developing DTDs. Theyhave the following benefits similar to those of ordinary entity references:</P><UL><LI>     Internal parameter entities canbe used to ensure consistency and to improve the readability of the DTD for users.<LI>     External parameterentities can be used to modularize the DTD.</UL><A NAME="PAGENUM-116"><P>Page 116</P></A><P>Both types of parameter entities can be used withconditional sections to develop DTDs that can be tailored by users for individual documents. Mostoften, this is achieved by including parameter entity declarations inthe document's internal DTD subset to act asswitches, as in the following code:</P><!--  CODE //--><PRE>&lt;?XML version &quot;1.0&quot;?&gt;&lt;!DOCTYPE doc SYSTEM &quot;strict.dtd&quot; [&lt;!ENTITY % options &quot;IGNORE&quot;&gt;]&gt;&lt;doc&gt; ...</PRE><!--  END CODE //--><P>The preceding entry states that the parameter entityoptions is to have the value &quot;IGNORE&quot; in this document. Typically, this switches off a set of optionswithin the DTD. DTD design is discussed in more detail in Chapter 8.</P><H4><A NAME="ch07_ 12">Non-XML Resources</A></H4><P>Binary external entities are provided to represent any non-XML resourcethat is to form part of an XML document. The open-ended design of binaryentities, linking them to notations, allows a framework that can easily copewith any new type of digital resource that is invented.</P><H3><A NAME="ch07_ 13">Storage Strategies for XML Entities</A></H3><P>Note the careful phrase &quot;virtual storage units&quot; that I used to defineentities. An entity's content can be, and often is, a complete file, but it can also bea part of a file, a stream held in the computer's memory, an object stored ina database, or even the result of a database query. XML gives you the freedomto store and manage your entities in whatever way is most appropriate.</P><P>If you decide to take all your supporting files and put them into anobject-oriented database, it isn't always necessary to change all your XMLdocuments. (Even when you do have to make changes because you have reorganizedyour files, XML's design ensures that you don't have to scratch around withinthe content of your documents. All entities used by an XML document mustbe declared up front in the DTD, so that's where you update all yourreferences to storage units when files are moved around.)</P><P>XML assumes that your XML application will includean entity manager, which takes your entity names and finds the correct piece of content for you. Asa</P><P><CENTER><A HREF="0109-0112.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0117-0120.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?