📄 0123-0126.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="../ch07/0121-0122.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0127-0130.html">Next</A></CENTER></P><A NAME="PAGENUM-123"><P>Page 123</P></A><H3><A NAME="ch08_ 1">CHAPTER 8</A></H3><H2>Keeping It Tidy: The <BR>XML Rule Book</H2><B>by Richard Light</B><P>In previous chapters, I characterized XML documents asself-describing. Every valid XML document brings its ownrule book along with it. In fact, that is the definition of avalid XML document: It obeys its own rules. In this chapter, Iopen up the rule book and see what it can tell us about anXML document.</P><H3><A NAME="ch08_ 2">The XML Prolog</A></H3><P>The prolog is everything that occurs in an XMLdocument before the start-tag that begins the document proper.This can include the following items:</P><UL><LI> An optional XML declaration<LI> A document type declaration</UL><A NAME="PAGENUM-124"><P>Page 124</P></A><UL><LI> Comments<LI> Processing instructions<LI> White space</UL><P>Here is an example of an XML prolog for this chapter, containing all ofthe preceding features:</P><!-- CODE //--><PRE><?XML version="1.0" RMD="internal" ?><!-- Chapter 8: the XML rulebook --><!-- Last edited by rbl, 7 July 1997 --><!-- Processing instructions: --><?XML-STYLE *** to add *** ?><?PCX compression="standard" type="256 color" ?><!-- Document type declaration: --><!DOCTYPE DIV1 SYSTEM "TEISAMS.DTD" [<!-- Figures for this chapter: --><!ENTITY ch8.fig1 SYSTEM "08PXM01.PCX"><!ENTITY ch8.fig2 SYSTEM "08PXM02.PCX">]><!-- The chapter starts here: --></PRE><!-- END CODE //--><P>The following five sections break down each component of theprolog.</P><H4><A NAME="ch08_ 3">The XML Declaration</A></H4><P>I covered the XML declaration in Chapter 6, "Logical Structures inXML Documents." I cover the last aspect of the XML declaration—therequired markup declaration—at the end of this chapter. Here is the XML declaration:</P><!-- CODE SNIP //--><PRE><?XML version="1.0" RMD="internal" ?></PRE><!-- END CODE SNIP //--><H4><A NAME="ch08_ 4">The Document Type Declaration</A></H4><P>I discuss the document type declaration throughout most of this chapter.Here is the document type declaration:</P><!-- CODE //--><PRE><!DOCTYPE DIV1 SYSTEM "TEISAMS.DTD" [<!-- Figures for this chapter: --><!ENTITY ch8.fig1 SYSTEM "08PXM01.PCX"><!ENTITY ch8.fig2 SYSTEM "08PXM02.PCX">]></PRE><!-- END CODE //--><H4><A NAME="ch08_ 5">Comments</A></H4><P>Comments are meant to be included purely for user consumption (althoughI have seen systems in which comments were used as a place to squirrelaway information that will be used by the application). Use comments liberally,so</P><A NAME="PAGENUM-125"><P>Page 125</P></A><P>that the purpose of the XML markup can be clearly understood by anyhuman reader who is looking at an XML document. Here are the comments:</P><!-- CODE //--><PRE><!-- Chapter 8: the XML rulebook --><!-- Last edited by rbl, 7 July 1997 --><!-- Processing instructions: --><!-- Figures for this chapter: --></PRE><!-- END CODE //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>Comments are normally thrown away when an XML documentis processed, so they won't ever appear on the screen when the documentis displayed by a client's Web browser.</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch08_ 6">Processing Instructions</A></H4><P>I cover processing instructions (PIs) in Chapter 5, "The XML Approach."PIs can be placed anywhere in the content of an XML document, but theprolog is where you can expect most of them to appear. Here are the processinginstructions:</P><!-- CODE SNIP //--><PRE><?XML-STYLE *** to add *** ?><?PCX compression="standard" type="256 color" ?></PRE><!-- END CODE SNIP //--><P>PIs in the prolog will set up a global processing environment for thewhole XML document. They can set up the environment for the XMLdocument itself. For example, they can be used to specify which XS style sheet isassociated with the document, as in the following:</P><!-- CODE SNIP //--><PRE><?XML-STYLE *** to add *** ?></PRE><!-- END CODE SNIP //--><P>Alternatively, they can give additional information to the helperapplications that will be called on to process the various non-XML objects that arelinked to the document. The following specifies options for the treatment ofPCX images (standard compression; 256 color 8-bit images):</P><!-- CODE SNIP //--><PRE><?PCX compression="standard" type="256 color" ?></PRE><!-- END CODE SNIP //--><H4><A NAME="ch08_ 7">White Space</A></H4><P>Each declaration is laid out on a separate line. Blank lines appear betweengroups of declarations that belong together. You can space out the prolog anyway you want. Try to ensure that its structure is clear to a reader.</P><A NAME="PAGENUM-126"><P>Page 126</P></A><H3><A NAME="ch08_ 8">The Document Type Declaration</A></H3><P>An XML document's document type declaration specifies what type ofdocument it is, and says where to find its rule book. This rule book can be intwo parts that together form the document typedefinition (DTD) for the document. The external DTDsubset is outside the document. It typically is astandard DTD that someone else wrote. The internal DTDsubset forms part of the document. It typically contains declarations that specify your usage of thestandard DTD and declarations for the entities that are referred to within the text.</P><P>You can have a reference to an external DTD subset on its own, like this:</P><!-- CODE SNIP //--><PRE><!DOCTYPE XXX EXTERNAL-DTD-SUBSET-REFERENCE ></PRE><!-- END CODE SNIP //--><P>An internal DTD subset can also be on its own, like this:</P><!-- CODE SNIP //--><PRE><!DOCTYPE XXX [INTERNAL-DTD-SUBSET]></PRE><!-- END CODE SNIP //--><P>The two can also be together, like this:</P><!-- CODE SNIP //--><PRE><!DOCTYPE XXX EXTERNAL-DTD-SUBSET-REFERENCE [INTERNAL-DTD-SUBSET]></PRE><!-- END CODE SNIP //--><P>Here, XXX must be the same as the element type of the document element.For example, this would be an error:</P><!-- CODE SNIP //--><PRE><!DOCTYPE TEI.2 SYSTEM "TEISAMS.DTD"><DIV1> ...</PRE><!-- END CODE SNIP //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>One interesting feature of DTDs is that they do not specifywhich element type has to be the document element. When I wrote this book, Imade each chapter into a separate document and started with thediv1 element type:<BR><!-- CODE SNIP //--><PRE><!DOCTYPE DIV1 ...</PRE><!-- END CODE SNIP //-->When the whole book is put together as a single document, it has the(intended) TEI.2 element as its document element type:<BR><!-- CODE SNIP //--><PRE><!DOCTYPE TEI.2 ...</PRE><!-- END CODE SNIP //--><BR>The chapters all are div1 elements inside it.</BLOCKQUOTE></TD></TR></TABLE><P><CENTER><A HREF="../ch07/0121-0122.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0127-0130.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -