📄 0143-0146.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="0139-0142.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="../ch09/0147-0150.html">Next</A></CENTER></P><A NAME="PAGENUM-143"><P>Page 143</P></A><P>When a switch has been set, you can use it as often as necessary withinyour DTD. The HTML DTD uses the HTML.Recommended switch in fourdifferent places to enforce recommended practice.</P><P>Switches can trigger other switches. For example, HTML has anotherparameter entity switch called HTML.Deprecated, which guards declaration ofmarkup that is no longer seen as good practice. If a user switches inHTML.Recommended, it suggests that he doesn't want any deprecated features, so, as you haveseen, this conditional section automatically switches them out:</P><!-- CODE SNIP //--><PRE><![%HTML.Recommended;[<!ENTITY % HTML.Deprecated "IGNORE">]]></PRE><!-- END CODE SNIP //--><P>Each switchable section is normally followed by declarations that will applyif that section is switched out. This example, again taken from the HTMLDTD, says that the parameter entity preformatted will apply to only thePRE element unless the HTML.Deprecated switch has been set, in which case it will alsoinclude the deprecated elements XMP and LISTING:</P><!-- CODE //--><PRE><![%HTML.Deprecated;[<!ENTITY % preformatted "PRE | XMP | LISTING">]]><!ENTITY % preformatted "PRE"></PRE><!-- END CODE //--><P>How does this work? This technique relies heavily on the fact that thefirst declaration is the one that counts if an entity is declared more than once.All subsequent declarations are ignored. So, ifHTML.Deprecated is switched in, the conditional section is part of the markup, and it is processed as follows:</P><!-- CODE SNIP //--><PRE><!ENTITY % preformatted "PRE | XMP | LISTING"><!ENTITY % preformatted "PRE"></PRE><!-- END CODE SNIP //--><P>The parameter entity preformatted is declared twice, so the firstdeclaration counts, and the second one is ignored.</P><P>If HTML.Deprecated is switched out, the whole conditional sectiondisappears, and it is as though only the following appeared in the DTD:</P><!-- CODE SNIP //--><PRE><!ENTITY % preformatted "PRE"></PRE><!-- END CODE SNIP //--><P>This gives the required default setting.</P><P>You can use these switches in many ways. However, you should bear inmind that user switches in the internal DTD subset are meaningful only if youtell your users what switches they have available to them and which aspects ofthe DTD's behavior will be affected by each switch.</P><A NAME="PAGENUM-144"><P>Page 144</P></A><H3><A NAME="ch08_ 27">The Required Markup Declaration</A></H3><P>In the case where an XML document is to be treated as well-formedrather than valid, it is not always necessary to read and process the whole DTD.Time and bandwidth can be saved by skipping this job. However, there is aproblem here. Some information that might be found in the DTD is essential forthe correct processing even of well-formed XML documents. Thisinformation consists of declarations of the following:</P><UL><LI> Attributes with default values, if these default values are requiredby the document (because the attribute in question isn't always specified)<LI> Entities (apart from the five predefined entitiesamp, lt, gt, apos, and quot) that are referenced in the document<LI> Element types with element content, where the document haswhite space that needs to be treated differently because it falls insideinstances of those element types</UL><P>The problem is that the XML processor cannot know if any of thesesituations have arisen without reading the DTD. So how can it decide whether toread the DTD without first reading the DTD? Obviously, a little help is calledfor, and this is where the required markup declaration comes in.</P><P>The required markup declaration, or RMD, is the last component of theXML declaration. It is provided by the document's author as a guide to theXML processor, as in the following example:</P><!-- CODE SNIP //--><PRE><?XML version="1.0" RMD="INTERNAL"?></PRE><!-- END CODE SNIP //--><P>The RMD can take one of three values:</P><UL><LI> NONE means that the document can be parsed correctly withoutreading any part of the DTD.<LI>INTERNAL means that the XML processor must read and processthe internal DTD subset, if provided, in order to interpret thedocument correctly.<LI> ALL means that both the internal and the external DTD subsetsmust be read in order to interpret the document correctly.</UL><P>If an RMD isn't provided, the value ALL is assumed by default.</P><A NAME="PAGENUM-145"><P>Page 145</P></A><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>The XML language specification sternly calls it "an error" to getthis wrong and to imply in the RMD that the XML processor can skip part orall of the DTD when in fact it shouldn't. However, this isn't the sort of errorthat the XML processor can pick up (apart from entities that it will knowhaven't been declared). So misuse of the RMD can lead to your XMLdocuments being incorrectly parsed, without any warning.</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch08_ 28">Summary</A></H4><P>In this chapter, I discussed the aspects of XML that control the form ofvalid XML documents. I started by finding out what the rules consist of, andwhere they are to be found.</P><P>For much of the chapter, I discussed the four main types of declarationsthat are found in a document type definition:</P><UL><LI> Element declarations<LI> Attribute list declarations<LI> Entity declarations<LI> Notation declarations</UL><P>I then discussed how to use built-in XML features—specificallyconditional sections and parameter entities—to produce clear, modular DTDs.</P><P>Finally, I described the role of the required markup declaration in helpingXML processors to read well-formed XML documents efficiently and accurately.</P><A NAME="PAGENUM-146"><P>Page 146</P></A><P><CENTER><A HREF="0139-0142.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="../ch09/0147-0150.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -