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

📄 0097-0099.html

📁 Presenting XML.rar,详细介绍有关XML的知识
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "html.dtd"><HTML><HEAD><TITLE>Presenting XML:Logical Structures in XML Documents: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=06 //--><!--  PAGES=0085-0108 //--><!--  UNASSIGNED1 //--><!--  UNASSIGNED2 //--><P><CENTER><A HREF="0093-0096.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0100-0103.html">Next</A></CENTER></P><A NAME="PAGENUM-97"><P>Page 97</P></A><H3><A NAME="ch06_ 21">Content: What's In the Suitcase</A></H3><P>If a suitcase isn't empty, obviously it has some contents. In XML,elements can have three main types of content. These can be other elements, datacontent, or a mixture of the two.</P><H4><A NAME="ch06_ 22">Data Content</A></H4><P>The case in which an element has only data content is simplest:</P><!--  CODE SNIP //--><PRE>&lt;person KEY=&quot;A14768&quot; ROLE=&quot;designer&quot;&gt;Fred Flintstone&lt;/person&gt;</PRE><!--  END CODE SNIP //--><P>Here, the person element has no child elements, or subelements.</P><P>Note the clear distinction in XML between an emptyelement, which has a special syntax as described earlier, and an element whose content is theempty string. The following is not an emptyelement:</P><!--  CODE SNIP //--><PRE>&lt;person&gt;&lt;/person&gt;</PRE><!--  END CODE SNIP //--><H4><A NAME="ch06_ 23">Element Content</A></H4><P>The next simplest case is one in which an element contains only otherelements. There is a special name for this: elementcontent. It is obvious from the suitcase metaphor that elements have tonest neatly: You can't have a suitcase that is partially inside another one. (If you do, you certainly can't close eitherone!) This means that constructions like the following innocent little piece ofHTML are not even well-formed in XML:</P><!--  CODE SNIP //--><PRE>&lt;b&gt;&lt;i&gt;This is really important&lt;/b&gt;&lt;/i&gt;</PRE><!--  END CODE SNIP //--><P>In this example, you start a b element and then you start ani element. Therefore, the i element is part of the content of theb element. This means that the i element has to be closed (by an end tag) before you can close theb element in which it is contained. In fact, it's the other way around: You close theb first and then try to close i. Swapping the end tags fixes theproblem:</P><!--  CODE SNIP //--><PRE>&lt;b&gt;&lt;i&gt;This is really important&lt;/i&gt;&lt;/b&gt;</PRE><!--  END CODE SNIP //--><H4><A NAME="ch06_ 24">Mixed Content</A></H4><P>The most complex case is one in which an element contains a mixture ofdata content and markup:</P><!--  CODE //--><PRE>&lt;p&gt;We are going to see &lt;person&gt;Joe Brown&lt;/person&gt;and &lt;person&gt;Elaine&lt;/person&gt; on &lt;date&gt;October 15th&lt;/date&gt;.&lt;/p&gt;</PRE><!--  END CODE //--><A NAME="PAGENUM-98"><P>Page 98</P></A><P>Unsurprisingly, this is called mixed content.</P><P>However, just to confuse you, the term mixed content is also applied toour first case, where an element contains only character data. This is becausethe key distinction here is between element content and mixed content.Because an element has mixed content if it can contain any data characters, this hasto include the case where it contains only data characters and nomarkup.</P><H4><A NAME="ch06_ 25">Content Models</A></H4><P>You can't pack just anything into an XML suitcase. In a valid XMLdocument, each element type has a &quot;packing list&quot; that says what that type of suitcaseis allowed to contain. These packing lists are part of theelement declaration for each element type. These are found in the document's DTD. See thesection on element declarations in Chapter 8 for details.</P><P>For elements that have element content, the packing list takes the form ofa content model, which specifies the allowed sequence and number ofoccurrences of subelements. Content models use a simple grammar, which is describedin Chapter 8. Here is an example of a content model:</P><!--  CODE SNIP //--><PRE>(front,  body,  back?)</PRE><!--  END CODE SNIP //--><P>This model requires a front element, followed by abody element, and optionally followed by a back element.</P><P>For an XML document to be valid, each element in the document musthave content that matches the designated packing list for that element's type. Ifan element has the preceding content model, the following content is acceptable:</P><!--  CODE SNIP //--><PRE>&lt;front&gt;&lt;title&gt;Growing Up&lt;/title&gt;&lt;/front&gt;&lt;body&gt;&lt;div1&gt; ... &lt;/div1&gt;&lt;/body&gt;</PRE><!--  END CODE SNIP //--><P>Note that the title and div1 elements do not affect the situation. Whenassessing validity, you don't look inside the suitcases you are trying to packinto the currently open suitcase. Or, to put it slightly more formally, anelement's content model is checked against only its level-one subelements.</P><P>An element with the following content would not be valid, because themandatory front element is missing:</P><!--  CODE SNIP //--><PRE>&lt;body&gt;&lt;div1&gt; ... &lt;/div1&gt;&lt;/body&gt;&lt;back&gt;&lt;index&gt; ... &lt;/index&gt;&lt;/back&gt;</PRE><!--  END CODE SNIP //--><P>Here is a slightly more complex content model:</P><A NAME="PAGENUM-99"><P>Page 99</P></A><!--  CODE SNIP //--><PRE>(head, (p | list | note)*, div2*)</PRE><!--  END CODE SNIP //--><P>This model requires a head element; followed by zero or morep, list, or note elements; and followed by zero or morediv2 elements.</P><H4><A NAME="ch06_ 26">Mixed-Content Declarations</A></H4><P>Elements with mixed content have a special type of content model calleda mixed-content declaration, which states that character data(#PCDATA) is allowed and lists the elements that are additionally allowed within this element.The mixed-content declaration is phrased in such a way that no restrictionsare placed on the order or number of occurrences of thesesubelements:</P><!--  CODE SNIP //--><PRE>(#PCDATA | A | B | ...)*</PRE><!--  END CODE SNIP //--><P>This declaration means &quot;zero or more occurrences of character data orelements A, B, and so on, in any order.&quot;</P><P>The following form also counts as a mixed-content declaration, eventhough it allows character data only within the element in question:</P><!--  CODE SNIP //--><PRE>(#PCDATA)</PRE><!--  END CODE SNIP //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>The presence of child elements within a mixed-content model isalways optional, which means that an element containing only character datawill always be valid against any mixed-content declaration.</BLOCKQUOTE></TD></TR></TABLE><P>Here are two examples of mixed-content declarations:</P><!--  CODE SNIP //--><PRE>(#PCDATA | person | date | place)*(#PCDATA)</PRE><!--  END CODE SNIP //--><P>The first example states that the element can have data content, plus anynumber of person, date, and place subelements. The following would be validcontent for such an element:</P><!--  CODE //--><PRE>We are going to see &lt;person&gt;Joe Brown&lt;/person&gt;and &lt;person&gt;Elaine&lt;/person&gt; on &lt;date&gt;October 15th&lt;/date&gt;.</PRE><!--  END CODE //--><P>But the following would not be valid content, because the elementclub does not appear in the list of allowed subelements:</P><!--  CODE SNIP //--><PRE>We are going to see &lt;person&gt;Joe Brown&lt;/person&gt;at &lt;club&gt;Smokey's&lt;/club&gt; on &lt;date&gt;October 15th&lt;/date&gt;.</PRE><!--  END CODE SNIP //--><P><CENTER><A HREF="0093-0096.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0100-0103.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>

⌨️ 快捷键说明

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