📄 0235-0239.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="../ch12/0231-0234.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0240-0242.html">Next</A></CENTER></P><A NAME="PAGENUM-235"><P>Page 235</P></A><H3><A NAME="ch13_ 1">CHAPTER 13</A></H3><H2>Developing an <BR>XML Memo Application</H2><B>by Richard Light</B><P>In the last chapter I discussed HTML in detail andshowed how it might shape up as an XML application. Now Iam going to discuss how to use XML for the job it isreally designed to do—creating a custom application. I'll goover the following main tasks that must be performed for anyXML application:</P><UL><LI> Designing a DTD<LI> Deciding on a linking strategy<LI> Writing style sheets</UL><P>I'll go through a concrete example to help you gain abetter understanding of just how all this XML stuff fits together.</P><A NAME="PAGENUM-236"><P>Page 236</P></A><H3><A NAME="ch13_ 2">The XML Memo Application</A></H3><P>The application that I use for an example is one for memos. Memos are acommonly found type of information resource and are made up of areasonably consistent, simple structure. This simplicity makes it possible for me to tryto cover all the bases of an XML application within a single chapter.</P><P>Memos are a suitable case for treatment by XML, because it is quite likelythat a group of people might want to use a memo format to exchange anddevelop ideas. These people might be scattered around the world, using the Internetas their communications medium, or they might be employees of a singlecompany, working within an intranet. In either case, the benefit of using XMLis that it allows them to communicate their ideas using the framework they <BR>already have, without having to compromise the form of those ideas.</P><H4><A NAME="ch13_ 3">The Scenario</A></H4><P>This is the situation. A group of people is discussing a topic of interest (suchas how to write a book on XML!) and communicating their ideas via amemo format.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>This task could equally be entrusted to a threaded e-mail discussionlist. I will cover the extent to which XML provides a better (or worse) solutionto this problem.</BLOCKQUOTE></TD></TR></TABLE><P>For the purposes of this design exercise, it doesn't really matter how thediscussion group is physically organized. However, it helps to have an idea ofthe possibilities. Here is my vision of how the physical setup might go:</P><UL><LI> Each member of the discussion group has an XML-aware editorthat helps the member write correctly structured XML memos.<LI> Each person has access to a directory within a site where memos canbe posted.<LI> This posting site is equipped with push technology that causeseach new memo to be sent to every designated recipient.<LI> The posting site is also equipped with an XML-aware database.</UL><A NAME="PAGENUM-237"><P>Page 237</P></A><P>A typical memo is shown in Figure 13.1. It contains the following features:</P><UL><LI> Name of sender<LI> Names of recipients<LI> Date sent<LI> Main heading<LI> Optional subject keywords<LI> Text of memo</UL><P>Although the memo contains only paragraphs, I will assume that the textof memos can contain the following features:</P><UL><LI> Sections and subsections with optional headings<LI> Paragraphs<LI> Lists<LI> Images and diagrams<LI> Quotations from other memos<BR></UL><A HREF="javascript:displayWindow('images/ch13fg01.jpg',288,204)"><IMG SRC="images/tn_ch13fg01.jpg"></A><BR>Figure 13.1.<BR>An example of a memo.<BR><A NAME="PAGENUM-238"><P>Page 238</P></A><H3><A NAME="ch13_ 4">Writing the DTD</A></H3><P>The first step of the job is to design an XML DTD for the memoapplication. You might recall that in Chapter 8, "Keeping It Tidy: The XML RuleBook," I discussed the markup constructs that can occur in a DTD. Now it's timeto put those theories into practice!</P><P>On one hand, this DTD needs to be flexible enough to cope with anymemo. On the other hand, the DTD needs to be strict about those aspects ofmemos that are really vital. (The DTD can also be strict about aspects that reallydon't matter at all, but that is a different issue!) Start by doing an inventory ofthe types of information you need to support in your DTD.</P><H4><A NAME="ch13_ 5">Overall Structure</A></H4><P>First of all, you have the following header information:</P><UL><LI> Name of sender<LI> Names of recipients<LI> Date<LI> Main heading<LI> Optional subject keywords</UL><P>You can start by saying that a memo consists of a header followed by text.The following is an element declaration for thememo element type, which says in XML-speak that the element consists of a header followed by text:</P><!-- CODE SNIP //--><PRE><!ELEMENT memo (header, text)></PRE><!-- END CODE SNIP //--><P>Well, that's the beginning of your DTD!</P><H4><A NAME="ch13_ 6">Header Information</A></H4><P>The header's contents include the five different types of information listedin the previous section. The following is a discussion of each of them in turn.</P><P>The "name of sender" clearly needs to be mandatory. You don't want tohave unattributed memos in the discussion. So there must be at least onesender. But will there always be just one—or do you want to allow for thepossibility of jointly authored submissions?</P><A NAME="PAGENUM-239"><P>Page 239</P></A><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>Note: This is the first difficult DTD design decision. I'll say that jointauthorship should be allowed. The effect of this decision on the DTD willbecome clear when you declare the header element type at the end of this section.</BLOCKQUOTE></TD></TR></TABLE><P>What will "name of sender" actually contain? It's a simple element, sothe following contains only character data:</P><!-- CODE SNIP //--><PRE><!ELEMENT sender (#PCDATA)></PRE><!-- END CODE SNIP //--><P>Next is "names of recipients." Again, you need to decide how many ofthese are allowed. There must be at least one recipient, and this time it's prettyobvious that you need to support multiple recipients as well.</P><P>In fact, the problem here is how to indicate neatly that a memo is to bebroadcast to all the people who are on the discussion list. At this point, you mustgo beyond the issue of DTD design. Anything to do with the data content ofan XML document is an application-specific issue. So you might have anapplication-specific convention such as the following:</P><!-- CODE SNIP //--><PRE><recipient>broadcast</recipient></PRE><!-- END CODE SNIP //--><P>This convention is to be taken as an instruction to send the memo toeveryone on the list. And that raises another issue. How do you control the valuesof both sender and recipient so that they are valid identifiers for peopletaking part in the discussion? The answer is that your XML application must takeon the job of ensuring that this information is correct. There is no way thatthe XML DTD can do it for you. Its job is simply to declare and enforce thelogical structure of your XML documents.</P><P>To finish off your work on the recipient element, just declare its elementtype as follows:</P><!-- CODE SNIP //--><PRE><!ELEMENT recipient (#PCDATA)></PRE><!-- END CODE SNIP //--><H4><A NAME="ch13_ 7">Dates: Analysis Versus Attributes</A></H4><P>The "date" raises some more issues. In itself, it's a simple concept, and itshould certainly appear only once in all memos. In fact, you might expect theediting application to be able to add the current date for you. The issues ariseover how the date might be used.</P><P><CENTER><A HREF="../ch12/0231-0234.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0240-0242.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -