⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0139-0142.html

📁 Presenting XML.rar,详细介绍有关XML的知识
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "html.dtd"><HTML><HEAD><TITLE>Presenting XML:Keeping It Tidy: The XML Rule Book: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=08 //--><!--  PAGES=0123-0146 //--><!--  UNASSIGNED1 //--><!--  UNASSIGNED2 //--><P><CENTER><A HREF="0135-0138.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0143-0146.html">Next</A></CENTER></P><A NAME="PAGENUM-139"><P>Page 139</P></A><P>Putting entity and notation declarations in the DTD does not constrainauthors. They are at liberty to add any number of entities and notations totheir internal DTD subset.</P><P>On the other hand, including a large number of predefined declarations inthe class DTD does not impose too big an overhead. Clearly, the XMLprocessor has to read the declarations, but it does not have to do anything aboutthem (such as fetching the files they mention) until a document actuallyreferences them.</P><H4><A NAME="ch08_ 23">Conditional Sections</A></H4><P>Conditional sections are allowed only within the external DTD subset.They are a piece of markup that can be placed around one or moredeclarations, comments, and white space. They cause the markup they contain to beincluded in the DTD or ignored, depending on the value of their initialkeyword, which must be either INCLUDE or IGNORE:</P><!--  CODE SNIP //--><PRE>&lt;![INCLUDE[... included markup ...]]&gt;&lt;![IGNORE[... excluded markup ...]]&gt;</PRE><!--  END CODE SNIP //--><P>Conditional sections can nest inside each other:</P><!--  CODE SNIP //--><PRE>&lt;![INCLUDE[... included markup ...&lt;![IGNORE[... markup is still excluded ...]]&gt;]]&gt;</PRE><!--  END CODE SNIP //--><P>Be warned, however, that when inside an IGNORE conditional section,everything&#151;including INCLUDE conditional sections&#151;is ignored:</P><!--  CODE //--><PRE>&lt;![IGNORE[... excluded markup ...]]&gt;&lt;![INCLUDE[... this markup is ignored, despite being marked `include' ...]]&gt;]]&gt;</PRE><!--  END CODE //--><P>Conditional sections become interesting only when you use them inconjunction with parameter entities. I'll discuss how to do that in the nextsection.</P><A NAME="PAGENUM-140"><P>Page 140</P></A><H4><A NAME="ch08_ 24">Parameter Entities</A></H4><P>Parameter entities can be used in the external DTD subset as a shorthandfor a group of elements that come up repeatedly in the DTD. By givingparameter entities a suitable name, you can make the logical structure of yourclass DTD much clearer to a reader.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>Parameter entities can also be used in the internal DTD subset,but in a much more restricted way than I describe in this section.</BLOCKQUOTE></TD></TR></TABLE><P>For example, in the HTML DTD, the parameter entitylist is used to refer to all the elements that contain lists of various types:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY % list &quot; UL | OL | DIR | MENU &quot;&gt;</PRE><!--  END CODE SNIP //--><P>This parameter is then used as a shorthand for &quot;&#133;and all the list-typeelements&quot; in the declaration of the parameter entityblock, which in turn means &quot;all block-type elements&quot;:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY % block &quot;P | %list; | DL | %preformatted;| %block.forms;&quot;&gt;</PRE><!--  END CODE SNIP //--><P>In turn, block is used within the body.content parameter entity:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY % body.content &quot;(%heading;|%block;|HR|ADDRESS|IMG)*&quot;&gt;</PRE><!--  END CODE SNIP //--><P>Eventually, the body element type's content model becomes asingle body.content parameter entity:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT BODY %body.content;&gt;</PRE><!--  END CODE SNIP //--><P>Without these parameter entities, the declaration ofBODY would be something like this (depending on which options, covered in the next section, are in force):</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT BODY(H1|H2|H3|H4|H5|H6|P | UL | OL | DIR | MENU | DL| PRE | BLOCKQUOTE |HR|ADDRESS|IMG)*&gt;</PRE><!--  END CODE SNIP //--><P>This is longer, but more importantly it has lost the sense that theseelement types fulfill certain well-defined types of roles within the class DTD.</P><P>Another common use for parameter entities is to act as a shorthandwithin attribute declarations. For example, the HTML DTD contains theSDAPREF parameter entity, which introduces generated text prefixes for use whendisplaying HTML pages for the print-impaired:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY % SDAPREF &quot;SDAPREF CDATA #FIXED&quot;&gt;</PRE><!--  END CODE SNIP //--><A NAME="PAGENUM-141"><P>Page 141</P></A><P>This handy shorthand is used throughout the DTD, as in the followingexample:</P><!--  CODE SNIP //--><PRE>&lt;!ATTLIST XMP%SDAPREF; &quot;Example:&amp;#RE;&quot;&gt;</PRE><!--  END CODE SNIP //--><P>A parameter entity also can be used for a whole group of attributedeclarations. The following is a definition ofa.global:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY % a.global &quot;id ID #IMPLIEDn CDATA #IMPLIEDlang IDREF #IMPLIEDrend CDATA #IMPLIED&quot;&gt;</PRE><!--  END CODE SNIP //--><P>With this, you have a set of global attributes that can be associated withany element:</P><!--  CODE SNIP //--><PRE>&lt;!ATTLIST PERSON %a.global;&gt;</PRE><!--  END CODE SNIP //--><P>Part of the value of this approach is that if you decide to add anotherglobal attribute, you have to update only the definition ofa.global to achieve this.</P><H4><A NAME="ch08_ 25">The Modular Approach</A></H4><P>You have already seen that XML's general entities can be used to helpauthors by breaking up large documents into manageable chunks. In a similarspirit, parameter entities can be used to break up a large class DTD.</P><P>In general, each module should have a clearly defined purpose. It mightcontain element and attribute declarations for a part of the documentstructure. For example, this code declares and then includes a module containingdeclarations for the components of tables:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY % basic.tables SYSTEM &quot;table1.dtd&quot;&gt;%basic.tables;</PRE><!--  END CODE SNIP //--><P>You could also use a module to include declarations for a set ofcommonly used entities:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY % common.files SYSTEM &quot;common.dtd&quot;&gt;%common.files;</PRE><!--  END CODE SNIP //--><P>One advantage of the modular approach to DTD design is that you caneasily switch in a whole replacement module. For example, if you decide to adopta new approach to modeling tables, all you have to do is remove the referenceto basic.tables and replace it with a reference to another tablemodule.</P><A NAME="PAGENUM-142"><P>Page 142</P></A><H4><A NAME="ch08_ 26">User Switches</A></H4><P>Now you are ready for the subject of customizing class DTDs.</P><P>You can use conditional sections and parameter entities in combination tomake your class DTD user-customizable. The general technique is to place aparameter entity reference at the point where the keywordINCLUDE or IGNORE occurs in a conditional section:</P><!--  CODE SNIP //--><PRE>&lt;![%user_option;[... conditionally included declarations ...]]&gt;</PRE><!--  END CODE SNIP //--><P>If the parameter entity user_option has the valueINCLUDE, the declarations in the marked section will be part of the DTD. If it isIGNORE, they will simply be ignored.</P><P>A common method of using this technique is to place switchableconditional sections in the external DTD subset, and to advise users that they canswitch various features of the class DTD on or off as they please, by declaringthe parameter entity in their internal DTD subset. The following documenttype declaration declares the parameter entityHTML.Recommended to have the value INCLUDE, which switches in the set of markup declarations that count asgood practice in the HTML DTD:</P><!--  CODE SNIP //--><PRE>&lt;!DOCTYPE HTML SYSTEM &quot;HTML2_X.DTD&quot; [&lt;!ENTITY % HTML.Recommended &quot;INCLUDE&quot;&gt;]&gt;</PRE><!--  END CODE SNIP //--><P>This includes all those CDATA sections in the DTD that are introduced bya reference to HTML.Recommended. For example, this CDATA section fromthe HTML DTD will be included:</P><!--  CODE SNIP //--><PRE>&lt;![%HTML.Recommended;[        &lt;!ENTITY % HTML.Deprecated &quot;IGNORE&quot;&gt;]]&gt;</PRE><!--  END CODE SNIP //--><P>Using switches requires a certain amount of care. If the user declares thisparameter entity to have any value other thanINCLUDE or IGNORE, the user will render the whole DTD, and the document, invalid. It is certainly essentialto declare a meaningful value for the parameter entity in the class DTDbefore using that parameter entity to introduce a conditional section in your DTD:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY HTML.Recommended &quot;IGNORE&quot;&gt;</PRE><!--  END CODE SNIP //--><P>The parameter entity will then have a sensible value that can be used ifthe user does not specify a value for it in his or her internal DTD subset.</P><P><CENTER><A HREF="0135-0138.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0143-0146.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>

⌨️ 快捷键说明

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