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

📄 0127-0130.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="0123-0126.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0131-0134.html">Next</A></CENTER></P><A NAME="PAGENUM-127"><P>Page 127</P></A><P>When the external DTD subset is a standard DTD, it will often have aPUBLIC identifier as well as a SYSTEM identifier:</P><!--  CODE SNIP //--><PRE>&lt;!DOCTYPE DIV1 PUBLIC &quot;-//TEI//DTD TEI Lite 1.0 For SAMS//EN&quot;&quot;TEISAMS.DTD&quot;&gt;</PRE><!--  END CODE SNIP //--><P>For simple applications, there is nothing to stop you from putting thewhole DTD in the internal DTD subset. This memo is a complete, valid, totallyself-contained XML document:</P><!--  CODE //--><PRE>&lt;!DOCTYPE memo [&lt;!ELEMENT memo (from, to, cc, date, content)&gt;&lt;!ELEMENT from (#PCDATA)&gt;&lt;!ELEMENT to (#PCDATA)&gt;&lt;!ELEMENT cc (#PCDATA)&gt;&lt;!ELEMENT date (#PCDATA)&gt;&lt;!ELEMENT content (p+)&gt;&lt;!ELEMENT p (#PCDATA)&gt;]&gt;&lt;memo&gt;&lt;from&gt;Frank&lt;/from&gt;&lt;to&gt;Joan&lt;/to&gt;&lt;cc&gt;Joseph&lt;/cc&gt;&lt;date&gt;July 4 1997&lt;/date&gt;&lt;content&gt;&lt;p&gt;Thanks for the meeting minutes.&lt;/p&gt;&lt;p&gt;I'll try to update the background materials in timefor next week's meeting.&lt;/p&gt;&lt;/content&gt;&lt;/memo&gt;</PRE><!--  END CODE //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>Remember that the DTD is important even when you are notpitching for validity. In order to be well-formed, XML documents must also haveall their external entities declared in the DTD. In a well-designed application,it should be possible to place all of these declarations in the internal DTDsubset, thus avoiding the need to read and process the external DTD subsetwhen well-formedness is all you are interested in.</BLOCKQUOTE></TD></TR></TABLE><P>When an XML document has both an internal and an external DTDsubset, the internal one is processed first, so it takes precedence. Later in thischapter, you learn how this feature can be used to control a standard DTD via theuse of parameter entity declarations.</P><H3><A NAME="ch08_ 9">Element Declarations</A></H3><P>The element declarations in the DTD determine the possible structure ofyour XML documents. They each take an element, state its name, and defineits possible content by means of a contentspecification. Here is an example:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT memo (from, to, cc, date, content)&gt;</PRE><!--  END CODE SNIP //--><A NAME="PAGENUM-128"><P>Page 128</P></A><P>This specifies an element type called memo and states that it can (in fact, itmust) contain the elements from, to, cc, date, andcontent, in that order. Each of these elements will, in its turn, have an element declaration that registersits name and states what it can contain:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT from (#PCDATA)&gt;&lt;!ELEMENT to (#PCDATA)&gt;&lt;!ELEMENT cc (#PCDATA)&gt;&lt;!ELEMENT date (#PCDATA)&gt;&lt;!ELEMENT content (p+)&gt;</PRE><!--  END CODE SNIP //--><P>The elements from, to, cc, and date all contain character data(#PCDATA). The content element must contain one or morep elements, which in turn contain character data:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT p (#PCDATA)&gt;</PRE><!--  END CODE SNIP //--><P>This is a very simple, rigid model. For an XML document to be a validmemo, the elements must be specified in exactly the right order. None of them canbe missed, and none (apart from p) can be repeated. In practice, very fewDTDs are this prescriptive, because real-life applications normally require moreflexibility than this (even for memos).</P><P>As you will see, there are methods for specifying that elements are optionalor repeatable, and that they can occur in any order. This makes it much easierto model real-life information. However, the real power of this approachto modeling comes from recursion&#151;the capability of elements to containthemselves. Here is a simple example:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT node (desc, node*)&gt;&lt;!ELEMENT desc (#PCDATA)&gt;</PRE><!--  END CODE SNIP //--><P>This says a node contains a mandatory desc, followed by zero or moresubnodes. This simple two-element model can describe an arbitrarily complex tree ofnode elements:</P><!--  CODE //--><PRE>&lt;node&gt;&lt;desc&gt;top node&lt;desc&gt;&lt;node&gt;&lt;desc&gt;level 1, #1&lt;/desc&gt;&lt;/node&gt;&lt;node&gt;&lt;desc&gt;level 1, #2&lt;/desc&gt;&lt;node&gt;&lt;desc&gt;level 2, #1&lt;/desc&gt;&lt;node&gt;&lt;desc&gt;level 3, #1&lt;/desc&gt;&lt;/node&gt;&lt;node&gt;&lt;desc&gt;level 3, #2&lt;/desc&gt;&lt;/node&gt;&lt;/node&gt;&lt;/node&gt;&lt;/node&gt;</PRE><!--  END CODE //--><P>In this case, the node element can contain itself directly. More frequently,the recursion is less direct, with a child or grandchild of an element itselfbeing able to contain that element.</P><A NAME="PAGENUM-129"><P>Page 129</P></A><H4><A NAME="ch08_ 10">EMPTY and ANY</A></H4><P>Before looking at more complex cases, examine these simple types ofcontent specifications. The following element is declared as beingEMPTY:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT image EMPTY&gt;</PRE><!--  END CODE SNIP //--><P>It cannot have any contents, and it must always appear as an empty elementin the document: &lt;image/&gt;.</P><P>Clearly, empty elements are not of much use on their own (although thehr and br element types in HTML would qualify asEMPTY in XML). They usually have attributes that give them useful properties.</P><P>If an element has a content specification ofANY, it's open season. There are no restrictions on what that element can contain. As in the following example,it can be a mixture of character data and any element types allowed by theDTD, in any order:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT experimental ANY&gt;</PRE><!--  END CODE SNIP //--><H4><A NAME="ch08_ 11">Element Content</A></H4><P>You can choose to define element types that can contain only otherelements as their children. They cannot contain character data. The possibleoccurrences and sequence of child elements is specified by a simple grammar tool calleda content model. You have already seen the content model for the memoelement type in the memo DTD:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT memo (from, to, cc, date, content)&gt;</PRE><!--  END CODE SNIP //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>Content models apply only to the immediate children of anelement. After a child element is inserted into the document, its own contentspecification is used to determine what it, in turn, is allowed to contain.</BLOCKQUOTE></TD></TR></TABLE><P>Element content is a useful technique for structuring the higher levels of aDTD cleanly. It comes with a rather cool expression language for specifying theallowed patterns of child elements. This language uses the following:</P><UL><LI>    Parentheses,( ), surround a sequence or a set of alternatives.<LI>    The , character precedes each element type, except the first, ina sequence.</UL><A NAME="PAGENUM-130"><P>Page 130</P></A><UL><LI>     The | character precedes each element type, except the first, in a listof alternatives.<LI>     The ? character follows an element or group of elements andindicates that it occurs zero or one time.<LI>     The * character follows an element or group of elements andindicates that it occurs zero or more times.<LI>     The + character follows an element or group of elements andindicates that it occurs one or more times.</UL><P>Here are some simple examples.</P><P>Here is the memo content model refined by including some qualifierson the individual elements:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT memo (from, to+, cc*, date?, content)&gt;</PRE><!--  END CODE SNIP //--><P>Obviously, the commas between the elements are significant. They indicatea sequence&#151;meaning that the elements have to occur in the order specified.The unadorned from element type mandates that a memo must have preciselyone sender. By adding + after the to element type, you are allowing a memoto have any number of recipients (while mandating that there must be atleast one). It is not necessary to send copies (cc), but they can be sent to morethan one person&#151;this is indicated by the * qualifier. The? after date indicates that it is an optional element.</P><P>You can develop the content element type by allowing a mixture ofp (paragraph) and note (note) elements:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT content (p | note)+ &gt;</PRE><!--  END CODE SNIP //--><P>This states that you can have one or more paragraphs, or notes, in anyorder. There must, however, be at least one p or onenote element.</P><P>By combining these expressions, you can build a content model for yourmemos that dispenses with the content element completely:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT memo (from, to+, date?, (p | note)+)&gt;</PRE><!--  END CODE SNIP //--><P>This nesting of bracketed expressions can go on to whatever level isrequired. So, with this grammar you can build up quite complex contentmodels.</P><P><CENTER><A HREF="0123-0126.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0131-0134.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>

⌨️ 快捷键说明

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