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

📄 0135-0138.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="0131-0134.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0139-0142.html">Next</A></CENTER></P><A NAME="PAGENUM-135"><P>Page 135</P></A><P>Here are examples of attribute declarations with default values:</P><!--  CODE //--><PRE>&lt;!ATTLIST termdefid ID #REQUIREDname CDATA #IMPLIED&gt;&lt;!ATTLIST listtype (bullets|ordered|glossary) &quot;bullets&quot;&gt;&lt;!ATTLIST formmethod CDATA #FIXED &quot;POST&quot;&gt;</PRE><!--  END CODE //--><H3><A NAME="ch08_ 16">Entity Declarations</A></H3><P>In Chapter 7, &quot;Physical Structures in XML Documents,&quot; I discussed thedifferent types of entities that XML supports and the things you can makeand do with them in your documents. In that discussion, I demonstratedsome examples of entity declarations. Here I review those declarations and look ata new type of entity&#151;the parameter entity&#151;which can be used only withinyour XML DTDs.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>Remember that you do not need to provide entity declarationsfor resources to which you are linking via XML's linking facility. This appliesonly to entities that are part of the XML documentitself.</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch08_ 17">Internal and External Entities</A></H4><P>Internal entities have a value that is actually part of the entity declaration:</P><!--  CODE SNIP //--><PRE>ENTITY chap8 &quot;Chapter 8, &lt;q&gt;Keeping it Tidy: the XML Rule Book&lt;/q&gt;&quot;&gt;</PRE><!--  END CODE SNIP //--><P>This entity declaration is self-contained. It maps the namechap8 to the content Chapter 8, &lt;q&gt;Keeping it Tidy: the XML RuleBook&lt;/q&gt;. No separate storage unit is involved.</P><P>You see in Chapter 7 that an XML document can be made up of asmany physical storage units (usually files) as you like. However, these externalobjects must always be declared up-front in the DTD.</P><P>External entities are declared by associating a name with a storage unit thatis physically identified by means of a SYSTEM orPUBLIC identifier:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY chapter1 SYSTEM &quot;chap1.xml&quot;&gt;</PRE><!--  END CODE SNIP //--><A NAME="PAGENUM-136"><P>Page 136</P></A><P>This associates the name chapter1 with the filechap1.xml.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>You can choose any name you like for your entities. However,entity names must conform to XML's rules for a name, which strictly limit thenon-alphanumeric characters you can use within the entity's name. Also,entity names must be unique within each XML document. If you declare thesame entity name more than once, the first declaration is used and all the otherswill be ignored. You might not be warned that this has happened.</BLOCKQUOTE></TD></TR></TABLE><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>Because external entities tend to be uniquely associated withparticular documents, their declarations are usually found in the document itself, aspart of its internal DTD subset.</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch08_ 18">Text and Binary Entities</A></H4><P>In Chapter 7,  I also discussed the distinction between binary and textexternal entities. A text entity contains text data that is considered to form part ofthe XML document. A binary entity is basically anything that isn't to be treatedas though it is XML-encoded.</P><P>The difference between the declarations of a text entity and a binary entityis that each binary entity has a notation associated with it. This is a binary entity:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY my.picture SYSTEM &quot;mypic.bmp&quot; NDATA BMP&gt;</PRE><!--  END CODE SNIP //--><P>The following is a text entity:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY chap4 SYSTEM &quot;chap4.xml&quot;&gt;</PRE><!--  END CODE SNIP //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>In order to be valid, the notation name(BMP in this example) must be declared in the DTD. Notation declarations are discussed later inthis chapter.</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch08_ 19">Parameter Entities</A></H4><P>Parameter entities have the same job description as general entities. Theonly difference in their scope is that parameter entities can appear only in theDTD.</P><A NAME="PAGENUM-137"><P>Page 137</P></A><P>The only difference in their declaration and use is an extra% symbol. A parameter entity declaration has % between the initial&lt;!ENTITY and the entity's name:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY % HTML.Version&quot;-//W3C//DTD HTML 3.2//EN&quot;&gt;</PRE><!--  END CODE SNIP //--><P>A parameter entity reference uses % in place of the&amp; that precedes general entity references:</P><!--  CODE SNIP //--><PRE>&lt;!ATTLIST HTMLVERSION CDATA #FIXED &quot;%HTML.Version;&quot;&gt;</PRE><!--  END CODE SNIP //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>Note that there is white space on either side of the% in the parameter entity declaration, but no space between% and the entity's name when it actually is used.</BLOCKQUOTE></TD></TR></TABLE><P>Later in this chapter, you find out how to use parameter entities to help inthe design of flexible, user-customizable XML DTDs.</P><H3><A NAME="ch08_ 20">Notation Declarations</A></H3><P>Notations are declared in the DTD in a similar fashion to entities. Theydeclare a name as signifying a notation, and they associate it with aSYSTEM or PUBLIC identifier:</P><!--  CODE SNIP //--><PRE>&lt;!NOTATION JPEG SYSTEM &quot;/programs/viewjpg.exe&quot;&gt;</PRE><!--  END CODE SNIP //--><P>The general intention here is that the external identifier in the notationdeclaration will help your XML application to deal with other stuff in thisstrange non-XML format. In this case, for example, it could be the filename of aprogram that can view JPEG images. However, the XML-Lang standard leavesit slightly open as to exactly how this information will be used. It does notforce applications to treat notations as helper applications.</P><H3><A NAME="ch08_ 21">DTD Design Tips</A></H3><P>Although I have reviewed the actual declarations that make up an XMLDTD, I haven't talked about how you might actually go about designing yourown DTD. In an introductory book like this, I can't go into any sort of detail(although, in the SGML world at least one whole book is devoted to justthis single topic), but I can at least outline some useful techniques that aresuggested by XML's built-in facilities.</P><A NAME="PAGENUM-138"><P>Page 138</P></A><P>In Chapter 13, &quot;Developing an XML Memo Application,&quot; I cover howyou might actually design a DTD for a simple XML application. If you wantto review a more complex example, the XML version of the HTML 2.0 DTDon the CD-ROM is the basis of many of the examples discussed in this section.</P><H4><A NAME="ch08_ 22">External Versus Internal DTD Subset</A></H4><P>When designing a DTD, you are actually designing a file (or several, seethe next section) that can act as the external DTDsubset for a class of similar XML documents.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>For the rest of this section, the term classDTD will be used as a shorthand for &quot;an external DTD subset designed for a class of similarXML documents.&quot;</BLOCKQUOTE></TD></TR></TABLE><P>As you design a class DTD, it is worth bearing in mind that the XMLdocument author is at liberty to create an internal DTD subset before the startof the document, and that declarations in the internal DTD subset willoverride corresponding declarations in your class DTD. This feature of XML canbe used to your advantage, but only if authors work to an agreed plan and donot introduce gratuitous changes to the class DTD in their internal subsets.</P><P>In general, it makes sense to include a complete logical structure (includingall the element and attribute declarations) in your class DTD. You mightgive users some options to switch on and off, but they shouldn't be expectedto design new structural elements. (I discuss how to provide user options inthe section &quot;User Switches,&quot; later in this chapter.)</P><P>Entities and notations can be more of a gray area. Normally these varyfrom one document to another, so they shouldn't appear in the class DTD.However, if your class DTD has a well-understood sphere of operation, it mightbe possible to include declarations for entities that are widely used withinthat application. For example, for an intranet XML application, a company'slogo could be declared as a standard entity in the class DTD:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY logo SYSTEM &quot;/resources/logo.gif&quot; NDATA GIF&gt;</PRE><!--  END CODE SNIP //--><P>Again, if you know in advance which notations are likely to be used, itsaves authors work (and improves consistency) if you include their declarationsin the DTD:</P><!--  CODE SNIP //--><PRE>&lt;!NOTATION GIF SYSTEM &quot;/resources/gifviewer.exe&quot;&gt;</PRE><!--  END CODE SNIP //--><P><CENTER><A HREF="0131-0134.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0139-0142.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>

⌨️ 快捷键说明

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