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

📄 0243-0246.html

📁 Presenting XML.rar,详细介绍有关XML的知识
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "html.dtd"><HTML><HEAD><TITLE>Presenting XML:Developing an XML Memo Application: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=13 //--><!--  PAGES=0235-0262 //--><!--  UNASSIGNED1 //--><!--  UNASSIGNED2 //--><P><CENTER><A HREF="0240-0242.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0247-0250.html">Next</A></CENTER></P><A NAME="PAGENUM-243"><P>Page 243</P></A><H4><A NAME="ch13_ 9">Structure of the Memo Text</A></H4><P>Let's try to provide a framework for text that is reasonably flexible, yetsimple. I've identified the following element types that can occur within the textof memos:</P><UL><LI>          Sections and subsections with optional headings<LI>          Paragraphs<LI>          Lists<LI>          Images and diagrams<LI>          Quotations from other memos</UL><P>In the simplest case, you want to be able to place any of the precedingelement types directly inside the text element. You don't know how many of eachthere will be or in what order they will occur. This is a definite case for the| separator. The following is an example:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT text (section | p | list | image | quote)+&gt;</PRE><!--  END CODE SNIP //--><TABLE BGCOLOR="#FFFF99"><TR>Note:<TD></TD></TR><TR><TD><BLOCKQUOTE>By using the + qualifier (one or more) rather than* (zero or more), you are insisting that text actually contains something, thus outlawingempty memos.</BLOCKQUOTE></TD></TR></TABLE><P>The following stipulates that each section consists of an optionalheading followed by the same subelements:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT section (head?, (section | p | list | image | quote)+)&gt;</PRE><!--  END CODE SNIP //--><P>One important feature of this content model is that it allowssection to be a subelement of itself. This is not a mistake; it is a powerful feature of XMLcalled recursion. (I discuss this concept in Chapter 8 under the heading&quot;Element Declarations.&quot;) It means that sections can nest within sections to any levelrequired. When you have this generalized sort of design, it's a good idea toprovide some attributes so that you can distinguish onesection from another, as in the following:</P><A NAME="PAGENUM-244"><P>Page 244</P></A><!--  CODE SNIP //--><PRE>&lt;!ATTLIST section    TYPE CDATA #IMPLIED    LEVEL CDATA #IMPLIED&gt;</PRE><!--  END CODE SNIP //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>Strictly speaking, the LEVEL attribute is redundant because asection element's level of nesting can always be calculated by software or workedout by a careful person.</BLOCKQUOTE></TD></TR></TABLE><P>Now you can say that paragraphs can contain text plus the other three typesof information I have identified. Here is an example:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT p (#PCDATA | list | image | quote)*&gt;</PRE><!--  END CODE SNIP //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>What you leave out of a content model can be as important as whatyou include. This example says that paragraphs cannot contain nestedparagraphs, nor can they contain sections. This enforces an orderly approach tothe structuring of your memos.</BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch13_ 10">Parameter Entities as a DTD Design Aid</A></H4><P>You can use parameter entities as a shortcut for commonly occurringstructures. In the content models I have developed so far, the following pattern cropsup repeatedly:</P><!--  CODE SNIP //--><PRE>list | image | quote</PRE><!--  END CODE SNIP //--><P>You can declare that pattern as a parameter entity calledcommon-elements, as follows:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY % common-elements &quot;list | image | quote&quot;&gt;</PRE><!--  END CODE SNIP //--><P>Now you can shorten all of the preceding element declarations into thefollowing:</P><!--  CODE //--><PRE>&lt;!ELEMENT text (section | p | %common-elements;)+&gt;&lt;!ELEMENT section (head?, (section | p | %common-elements;)+)&gt;&lt;!ELEMENT p (#PCDATA | %common-elements;)*&gt;</PRE><!--  END CODE //--><P>Using a parameter entity like common-elements makes for greaterconsistency between element declarations, and it also makes your intentions clearer.</P><P>The use of parameter entities has an added advantage when you decide (asI think you certainly will) that you want to add another information type tothe DTD. Having declared the new element type, all you have to do is tochange the declaration for common-elements to include that element type.</P><A NAME="PAGENUM-245"><P>Page 245</P></A><P>The following element declaration is required if you decide to mark uppeople's names within the text:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT person (#PCDATA)&gt;</PRE><!--  END CODE SNIP //--><P>You would just add the following new element type tocommon-elements to finish the job:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY % common-elements &quot;list | image | quote | person&quot;&gt;</PRE><!--  END CODE SNIP //--><P>Now all you have to do is to declare the following common elementswithin text, and your DTD is complete:</P><UL><LI>          Lists<LI>          Images and diagrams<LI>          Quotations</UL><H4><A NAME="ch13_ 11">Using Attributes to Generalize Elements</A></H4><P>Although there are different types of lists, they can be generalized to asingle list element type. You can provide a TYPE attribute to distinguishbulleted lists, numbered lists, and so on. This can be an open-ended set of possibletypes (declared as CDATA) or a fixed set of possibilities. For simplicity, try a fixedset of list types. Each list will consist of one or moreitem elements. Here is an example:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT list (item)+&gt;&lt;!ATTLIST list    TYPE (bullet|number|plain) &quot;bullet&quot;&gt;&lt;!ELEMENT item (#PCDATA)&gt;</PRE><!--  END CODE SNIP //--><H4><A NAME="ch13_ 12">Declaring Notations in the DTD</A></H4><P>Now you need to declare an element type for images and other visualmaterial. The following shows how to declare an empty element that has anumber of attributes to contain the information required to find and display the image:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT image EMPTY&gt;&lt;!ATTLIST image    SRC ENTITY #REQUIRED    DESC CDATA #IMPLIED    ALIGN (TOP|MIDDLE|BOTTOM) &quot;middle&quot;&gt;</PRE><!--  END CODE SNIP //--><P>At this point you come up against the real world! The actual imagesincluded in the memos will all be in some notation that must be declared in theDTD.</P><A NAME="PAGENUM-246"><P>Page 246</P></A><P>You can choose to declare those notations up front in the DTD or leavethe job to the users (in the internal DTD subset found at the start of theirdocuments).</P><P>It makes sense to decide which notations are going to be supported withinyour memo application, and to pre-declare those in the memo DTD. If youdecided to support GIF and JPEG images only, you would include the followingnotation declarations:</P><!--  CODE //--><PRE>&lt;!NOTATION GIF SYSTEM <A HREF="&quot;http://www.viewers.org/gview.exe&quot;&gt;">&quot;http://www.viewers.org/gview.exe&quot;&gt;</A>&lt;!NOTATION JPEG SYSTEM <A HREF="&quot;http://www.viewers.org/jview.exe&quot;&gt;">&quot;http://www.viewers.org/jview.exe&quot;&gt;</A></PRE><!--  END CODE //--><P>If users choose to include images in any other format in their memos, theycan then add declarations for the relevant notations in their internal DTD subsets.</P><H4><A NAME="ch13_ 13">Quotation: Setting Up Links</A></H4><P>The final matter is quotations. These are perhaps the most interestingaspect of the XML memo application.</P><P>Most e-mail spends a lot of its time quoting previous e-mails in order toreply to the points made. The quoted text is physically copied and inserted intothe reply.</P><P>A similar process is bound to happen with your memos. The sample memois a reply to an earlier one, and it quotes two passages from the earlier memo.In turn, it generated a reply that quoted three passages from this memo. Canyou use XML links to describe this sort of quotation? You certainly can, andmoreover, XML linking offers you a choice of approaches!</P><P>The simplest approach is to make the quote element type into an XMLsimple link, as follows:</P><!--  CODE //--><PRE>&lt;!ELEMENT quote EMPTY&gt;&lt;!ATTLIST quote    XML-LINK CDATA #FIXED &quot;simple&quot;    ROLE CDATA #IMPLIED    HREF CDATA #REQUIRED    TITLE CDATA #IMPLIED    SHOW (EMBED|REPLACE|NEW) &quot;EMBED&quot;    ACTUATE (AUTO|USER) &quot;AUTO&quot;    BEHAVIOR CDATA #IMPLIED&gt;</PRE><!--  END CODE //--><P>The attribute list declaration for the quote element type sets upquote elements so that by default they haveSHOW=&quot;EMBED&quot; andACTUATE=&quot;AUTO&quot;. These SHOW and ACTUATE values mean that the quoted text will be fetched andphysically inserted into the memo as part of the process of reading the memo.</P><P><CENTER><A HREF="0240-0242.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0247-0250.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>

⌨️ 快捷键说明

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