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

📄 0240-0242.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="0235-0239.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0243-0246.html">Next</A></CENTER></P><A NAME="PAGENUM-240"><P>Page 240</P></A><P>For the purpose of displaying the memo, you will want the date in auser-friendly form such as the following:</P><!--  CODE SNIP //--><PRE>August 12th, 1997</PRE><!--  END CODE SNIP //--><P>However, from an information-management point of view, you mightwant to be able to find all memos that were written before a certain date, aftera certain date, or within a range of dates. To be able to do this, you needthe date in a searchable form. Here is an example:</P><!--  CODE SNIP //--><PRE>19970812</PRE><!--  END CODE SNIP //--><P>How do you design a date element that meets both of these needs?</P><P>One approach is to analyze the date. This involves declaring subelementsthat each contain a component of the date:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT date (year, month, day)&gt;&lt;!ELEMENT year (#PCDATA)&gt;&lt;!ELEMENT month (#PCDATA)&gt;&lt;!ELEMENT day (#PCDATA)&gt;</PRE><!--  END CODE SNIP //--><P>With these subelements, the example date would be marked up as follows:</P><!--  CODE SNIP //--><PRE>&lt;date&gt;&lt;year&gt;1997&lt;/year&gt;&lt;month&gt;8&lt;/month&gt;&lt;day&gt;12&lt;/day&gt;&lt;/date&gt;</PRE><!--  END CODE SNIP //--><P>This analyzed form will support date-based searches, where the day,month, and year can be matched exactly, compared with a required range, or justignored. You can ask, for example, for memos with a date containing a yearequal to 1997, a month between six and nine, and any day you like. This wouldreturn all the memos from the summer of 1997.</P><P>For display, you would ask your style sheet to reorder the components ofthe date (month, then day, then year), convert the numerical month to a word(August), and add a suitable suffix (th) and a comma to theday. These steps require more work for the style sheet mechanism, but the approach is moreflexible. Here in the UK, people prefer to see dates in the formday month year. A variant on the style sheet could deliver the same analyzed date to me in the following <BR>UK-friendly format:</P><!--  CODE SNIP //--><PRE>12th August 1997</PRE><!--  END CODE SNIP //--><P>An alternative strategy is to use attributes to contain one of the forms inwhich the information is required. In this case, it is probably easier to have thefriendly form of the date as the actual data content and give the searchable form asa SORTFORM attribute value such as the following:</P><!--  CODE SNIP //--><PRE>&lt;date sortform=&quot;19970812&quot;&gt;August 12th 1997&lt;/date&gt;</PRE><!--  END CODE SNIP //--><A NAME="PAGENUM-241"><P>Page 241</P></A><P>To provide a place to store both forms of the date, you need to declare bothan element type and an attribute list for date, such as the following:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT date (#PCDATA)&gt;&lt;!ATTLIST dateSORTFORM CDATA #IMPLIED&gt;</PRE><!--  END CODE SNIP //--><P>The default for SORTFORM is #IMPLIED. If you had specified#REQUIRED instead, users would be forced to enter a searchable form of every date, or theauthoring software they use would have to generate a searchable form of each dateand insert it for them.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>Note that the SORTFORM attribute is of typeCDATA. Unlike SGML, XML doesn't have the NUMBER attribute type (that you find in the HTML DTD).It certainly doesn't have a special &quot;ISO date&quot; attribute type. Once again it isup to the application to ensure that this attribute is given sensible values.<P>The designers of XML are actively discussing this issue, and some methodof defining types of element content is likely to be added to theXML-Lang specification in the future.</BLOCKQUOTE></TD></TR></TABLE><P>Which approach to designing a date element type is better? There is noright answer to that question. The analyzed approach involves more markupand more work in writing the style sheet, but it is more flexible and onlyinvolves entering the actual data once. The attributes approach is more pragmaticand is simpler to support, but it does involve double-entry of the data in twodifferent forms, unless your authoring software can deduce one of thoseforms for you. For dates, double entry isn't really an issue, but it would be if thedata was a person's name, such as the following:</P><!--  CODE SNIP //--><PRE>&lt;person sortform=&quot;Light, Richard B.&quot;&gt;Richard B. Light&lt;/person&gt;</PRE><!--  END CODE SNIP //--><P>For this memo application, I'm going with the attributes approach.</P><H4><A NAME="ch13_ 8">Defining the header Element Type</A></H4><P>At this point, the decisions get simpler. You need to have a main headingthat can be used both as a title when viewing the memo and as a potential keyfor threading. You can say that there should be only one main heading, and itwill contain only data characters. Here is how:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT main-heading (#PCDATA)&gt;</PRE><!--  END CODE SNIP //--><A NAME="PAGENUM-242"><P>Page 242</P></A><P>Subject keywords also contain text. They are optional, and there can beany number of them. The following is for subject keywords:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT subject (#PCDATA)&gt;</PRE><!--  END CODE SNIP //--><P>Now you can pull together all of the header material. The following showsthe preceding decisions on the element types that can occur within the header,and the number of times each can or must appear:</P><UL><LI>          Sender must appear one or more times.<LI>          Recipient must appear one or more times.<LI>          Date must appear exactly once.<LI>          Main-heading must appear exactly once.<LI>          Subject can appear zero or more times.</UL><P>You can now declare the header element type as follows:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT header (sender+, recipient+, date,main-heading, subject*)&gt;</PRE><!--  END CODE SNIP //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>Note that by using the , separator you are mandating the order inwhich the elements of the header can occur. In general, if you want to controlthe contents of an element, you have to do this. The other approach thatXML offers is the | separator, which allows you to specify alternatives. However,this makes sense only if you make the whole group repeatable, as in the following:</BLOCKQUOTE></TD></TR></TABLE><!--  CODE SNIP //--><PRE>&lt;!ELEMENT header (sender | recipient | date | main-heading| subject)*&gt;</PRE><!--  END CODE SNIP //--><P>However, in this case you cannot specify that there is exactly onedate, and <BR>so on.</P><P>So far, your memo DTD looks like the following:</P><!--  CODE //--><PRE>&lt;!ELEMENT memo (header, text)&gt;&lt;!ELEMENT header (sender | recipient | date | main-heading | subject)*&gt;&lt;!ELEMENT sender (#PCDATA)&gt;&lt;!ELEMENT recipient (#PCDATA)&gt;&lt;!ELEMENT date (#PCDATA)&gt;&lt;!ATTLIST dateSORTFORM CDATA #IMPLIED&gt;&lt;!ELEMENT main-heading (#PCDATA)&gt;&lt;!ELEMENT subject (#PCDATA)&gt;</PRE><!--  END CODE //--><P>You now need to deal with the text element.</P><P><CENTER><A HREF="0235-0239.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0243-0246.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>

⌨️ 快捷键说明

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