📄 0251-0254.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="0247-0250.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0255-0259.html">Next</A></CENTER></P><A NAME="PAGENUM-251"><P>Page 251</P></A><P>So quotation elements and their child citation andsource elements go into a separate document and do not form part of your memo DTD. Thedocument might look like the following after a couple of entries have beenadded to it:</P><!-- CODE //--><PRE><?XML version="1.0"?><!DOCTYPE links SYSTEM "links.dtd"><links> <quotation> <citation HREF="memoex2.xml#a1"/> <source HREF="memoex1.xml#p1"/> </quotation> <quotation> <citation HREF="memoex2.xml#a2"/> <source HREF="memoex1.xml#p7"/> </quotation></links></PRE><!-- END CODE //--><P>The preceding code has two links from the sample memo"memoex2.xml". One is from the element withID="a1" to the element withID="p1" in document"memoex1.xml" (the original memo to which your example is a reply). Theother is from the element with ID="a2" to the element withID="p7" in the original memo.</P><H4><A NAME="ch13_ 16">Making the Memo DTD Links-Aware</A></H4><P>The link farm document should be referred to by every single memo, incase that memo is part of a link. Back in your memo DTD, you need anextended link group with a single, fixed document locator pointing to the link farm.Here is an example:</P><!-- CODE //--><PRE><!ELEMENT links (memolinks)><!ATTLIST links XML-LINK CDATA #FIXED "group"><!ELEMENT memolinks EMPTY><!ATTLIST memolinks XML-LINK CDATA #FIXED "document" HREF CDATA #FIXED "memo-links.xml"></PRE><!-- END CODE //--><P>The memo DTD should include a reference to this links file. A referenceto the links file can be enforced for all memos by including a mandatorylinks element within memo. Here is an example:</P><!-- CODE SNIP //--><PRE><!ELEMENT memo (header, links, text)></PRE><!-- END CODE SNIP //--><P>The following code ensures that each valid memo has the element structurein which the memolinks element contains the HREF link to the link farm as afixed attribute value:</P><A NAME="PAGENUM-252"><P>Page 252</P></A><!-- CODE SNIP //--><PRE><memo><header> ... </header><links><memolinks/></links><text> ... </text></memo></PRE><!-- END CODE SNIP //--><P>In addition, the memo DTD could use another low-level element that canact as an anchor for one end of these out-of-line links. In accordance withHTML practice, call it anchor. It can contain text (which will be underlined by anXML browser to indicate that it is one end of a link) and has anID attribute, as in the following example:</P><!-- CODE SNIP //--><PRE><!ELEMENT anchor (#PCDATA)><!ATTLIST anchor %a.global;></PRE><!-- END CODE SNIP //--><P>Now you need to update your definition of thecommon-elements parameter entity to include anchor, as in the following example:</P><!-- CODE SNIP //--><PRE><!ENTITY % common-elements "list | image | quote | anchor"></PRE><!-- END CODE SNIP //--><P>That's all! There is no need to make anchor into a linking element. Theactual linking will be done from the link farm by acitation locator element.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>Clearly it isn't the easiest job in the world creating these out-of-linelinks correctly by hand. It would be extremely useful if your XML editorcould support creating links by letting you just highlight the two ends of thelink, and then adding a correctly formatted entry to the link farm, whichwould require that the editor know about all aspects of XPointers, including whereto find the links file.</BLOCKQUOTE></TD></TR></TABLE><P>Now you can drop the original quote element completely and rely onyour out-of-line links in the link farm. However, please leave it in place for now.</P><H4><A NAME="ch13_ 17">The Full Memo DTD</A></H4><P>Listing 13.1 shows the design for your memo application.</P><P>Listing 13.1. The memo DTD.</P><!-- CODE SNIP //--><PRE><!-- Memo DTD. First declare the parameter entities: --><!ENTITY % common-elements "list | image | quote | anchor"><!ENTITY % a.global "</PRE><!-- END CODE SNIP //--><A NAME="PAGENUM-253"><P>Page 253</P></A><!-- CODE //--><PRE> ID ID #IMPLIED"><!-- The top-level memo element: --><!ELEMENT memo (header, links, text)><!-- Header information: --><!ELEMENT header (sender | recipient | date | main-heading | subject)*><!ATTLIST header %a.global;><!ELEMENT sender (#PCDATA)><!ELEMENT recipient (#PCDATA)><!ATTLIST recipient %a.global;><!ELEMENT date (#PCDATA)><!ATTLIST date %a.global; SORTFORM CDATA #IMPLIED><!ELEMENT main-heading (#PCDATA)><!ELEMENT subject (#PCDATA)><!-- Fixed GROUP and DOCUMENT elements to reference `link farm': --><!ELEMENT links (memolinks)><!ATTLIST links %a.global; XML-LINK CDATA #FIXED "group"><!ELEMENT memolinks EMPTY><!ATTLIST memolinks XML-LINK CDATA #FIXED "document" HREF CDATA #FIXED "memo-links.xml"><!-- Elements within the text of the memo: --><!ELEMENT text (section | p | %common-elements;)+><!ATTLIST text %a.global;><!ELEMENT section (head?, (section | p | %common-elements;)+)><!ATTLIST section %a.global;><!ELEMENT p (#PCDATA | %common-elements;)*><!ATTLIST p %a.global;><!ELEMENT list (item)+><!ATTLIST list %a.global; TYPE (bullet|number|plain) "bullet"><!ELEMENT item (#PCDATA)><!ATTLIST item %a.global;><!ELEMENT image EMPTY><!ATTLIST image %a.global; SRC ENTITY #REQUIRED DESC CDATA #IMPLIED ALIGN (TOP|MIDDLE|BOTTOM) "middle"><!ELEMENT anchor (#PCDATA)><!ATTLIST anchor %a.global;><!-- Notation declarations: --><!NOTATION GIF SYSTEM <A HREF=""http://www.viewers.org/gview.exe">">"http://www.viewers.org/gview.exe"></A><!NOTATION JPEG SYSTEM <A HREF=""http://www.viewers.org/jview.exe">">"http://www.viewers.org/jview.exe"></A></PRE><!-- END CODE //--><P>Listing 13.2 shows the supporting DTD you have invented to hold yourout-of-line links.</P><A NAME="PAGENUM-254"><P>Page 254</P></A><P>Listing 13.2. DTD for link farm.</P><!-- CODE //--><PRE><!ELEMENT quotation (citation, source+)><!ATTLIST quotation XML-LINK CDATA #FIXED "extended" ROLE CDATA #IMPLIED TITLE CDATA #IMPLIED SHOW (EMBED|REPLACE|NEW) "REPLACE" ACTUATE (AUTO|USER) "USER" BEHAVIOR CDATA #IMPLIED><!ELEMENT citation EMPTY><!ATTLIST citation XML-LINK CDATA #FIXED "LOCATOR" ROLE CDATA #FIXED "citation" HREF CDATA #REQUIRED TITLE CDATA #IMPLIED SHOW (EMBED|REPLACE|NEW) "EMBED" ACTUATE (AUTO|USER) "AUTO" BEHAVIOR CDATA #IMPLIED><!ELEMENT source EMPTY><!ATTLIST source XML-LINK CDATA #FIXED "LOCATOR" ROLE CDATA #FIXED "source" HREF CDATA #REQUIRED TITLE CDATA #IMPLIED SHOW (EMBED|REPLACE|NEW) "REPLACE" ACTUATE (AUTO|USER) "USER"</PRE><!-- END CODE //--><P> BEHAVIOR CDATA #IMPLIED></P><H3><A NAME="ch13_ 18">Encoding Your Sample Memo</A></H3><P>Now that you have a DTD framework, you need to add XML markup tothe sample memo. The job is pretty simple for the sample memo, because thetext of the memo itself falls into paragraphs. The only complicating factor isthat you need to strip out the quoted material and put in ananchor element as a placeholder for the references to the previous memo. Note also that youneed to give these anchor elements, and every paragraph, a uniqueID.</P><P>Listing 13.3 shows the full memo as a valid XML document.</P><P>Listing 13.3. Sample memo marked up as an XML document.</P><P><CENTER><A HREF="0247-0250.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0255-0259.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -