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

📄 0227-0230.html

📁 Presenting XML.rar,详细介绍有关XML的知识
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "html.dtd"><HTML><HEAD><TITLE>Presenting XML:Morphing Existing HTML into XML: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=12 //--><!--  PAGES=0213-0234 //--><!--  UNASSIGNED1 //--><!--  UNASSIGNED2 //--><P><CENTER><A HREF="0223-0226.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0231-0234.html">Next</A></CENTER></P><A NAME="PAGENUM-227"><P>Page 227</P></A><P>The external DTD subset declares all the resources (such as entityreferences for common accented characters and markup characters) that anyHTML document might contain. Now you want to declare the resources that areused by this particular document. For that, you have theinternal DTD subset. You might remember that this appears inside square brackets, just before theend of the document type declaration:</P><!--  CODE SNIP //--><PRE>&lt;!DOCTYPE HTML SYSTEM &quot;HTML2_X.DTD&quot; [&lt;!-- internal DTD subset goes here --&gt;]&gt;</PRE><!--  END CODE SNIP //--><P>Because you changed the img element type's SRC attribute in the DTD,you now need to declare your one image as a proper entity. This is done as follows.</P><P>First, put an entity declaration for the image file into the internal DTDsubset. Because the image uses the GIF notation, which isn't yet declared inyour DTD, you need a notation declaration for that too:</P><!--  CODE //--><PRE>&lt;!DOCTYPE HTML SYSTEM &quot;HTML2_X.DTD&quot; [&lt;!NOTATION GIF SYSTEM &quot;/software/gifview.exe&quot;&gt;&lt;!ENTITY image.home SYSTEM &quot;home.gif&quot; NDATA GIF&gt;]&gt;</PRE><!--  END CODE //--><P>Now you need to amend the img element so that itsSRC attribute specification points to this entity:</P><!--  CODE SNIP //--><PRE>&lt;IMG ALIGN=&quot;MIDDLE&quot; SRC=&quot;image.home&quot;/&gt;</PRE><!--  END CODE SNIP //--><P>That's it! Your image is now a properly declared XML entity.</P><H3><A NAME="ch12_ 20">Health Check: Does It Validate?</A></H3><P>By now, you should have a valid XML document. Let's check it and see.Using the RUNSP program to run the NSGMLS parser reveals oneremaining error, which is shown in Figure 12.2. The error is that you have used aul (unordered list) element inside a p (paragraph). This is not permitted by theoriginal HTML 2.0 DTD or your XML version. (Did you know that? I didn't!)</P><P>You need to finish the previous paragraph with a&lt;/p&gt; end-tag and remove the spurious /p end-tag from after the list. Then the whole page will be valid.</P><A NAME="PAGENUM-228"><P>Page 228</P></A><BR><A HREF="javascript:displayWindow('images/ch12fg02.jpg',288,204)"><IMG SRC="images/tn_ch12fg02.jpg"></A><BR>Figure 12.2.<BR>Checking the sample page for XML validity.<BR><H3><A NAME="ch12_ 21">Adding Custom Elements</A></H3><P>If you now want to extend the HTML tagset, the internal DTD subsetgives you a clean way of doing it. Suppose that you want to haveperson and date element types so that mentions of people and dates within your pageswould be unambiguously marked up.</P><P>All you need to do is declare the additional elements in the internal DTDsubset, like this:</P><!--  CODE SNIP //--><PRE>&lt;!ELEMENT person (#PCDATA)&gt;&lt;!ELEMENT date (#PCDATA)&gt;</PRE><!--  END CODE SNIP //--><P>Then you provide a place for the new elements to live, by redeclaring thephrase parameter entity to include them:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY % phrase &quot;EM | STRONG | CODE | SAMP | KBD | VAR| CITE | PERSON | DATE &quot;&gt;</PRE><!--  END CODE SNIP //--><P>The rule is that declarations in the internal DTD subset override those inthe external subset, so your local definition ofphrase will take precedence. This means thatperson and date will be allowed anywhere that phrase-typeelements are allowed in the DTD.</P><A NAME="PAGENUM-229"><P>Page 229</P></A><P>You can now mark up phrases that identify people and dates within your page:</P><!--  CODE SNIP //--><PRE>&lt;p&gt;&lt;tt&gt;Page last updated &lt;date&gt;July 8th 1997&lt;/date&gt;by &lt;person&gt;Richard Light&lt;/person&gt;&lt;/tt&gt;&lt;/p&gt;</PRE><!--  END CODE SNIP //--><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>Although it is technically possible to extend any XML DTD inthis way for individual documents, you should bear in mind the potentiallarger-scale problems you might be creating. If several people or organizationsare independently adding their own extensions to a base DTD, it isreasonably certain that they will add different element types with the samemeaning (persName, for example). Worse, they might use a single element type tomean two or more completely different things! This all reduces theinteroperability of the documents concerned. If a community is working with a single DTD,it is best to put in the extra work of coordinating extensions to that DTD ona central basis.</BLOCKQUOTE></TD></TR></TABLE><H3><A NAME="ch12_ 22">Entities: Creating Microdocuments</A></H3><P>As I explain in Chapter 7, &quot;Physical Structures in XML Documents,&quot;XML supports the concept of entities. In this section I suggest some ways inwhich entities might be put to good use within an XML-based Web site.</P><H4><A NAME="ch12_ 23">Consistent Page Headers</A></H4><P>You can use XML's built-in entity support to make your Web site easierto manage. For example, all the header and footer stuff that goes at the topand bottom of every page could be stored in a file and referenced from each pageas an external text entity. This has two major advantages:</P><UL><LI>          You don't need to repeat the text in each page you create.<LI>          If you decide to change the style of your header, you can do itonce, and every page on the site will automatically be updated.</UL><P>The content of the external file will be the markup, optionally preceded byan encoding processing instruction:</P><!--  CODE //--><PRE>&lt;?XML ENCODING='utf-8'?&gt;&lt;hr&gt;&lt;a href=&quot;l12_1.htm&quot;&gt;&lt;IMG ALIGN=&quot;MIDDLE&quot; SRC=&quot;home.gif&quot;alt=&quot;[home page]&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;l12html1.htm&quot;&gt;&lt;IMG ALIGN=&quot;MIDDLE&quot; SRC=&quot;html.gif&quot;alt=&quot;[HTML]&quot;/&gt;&lt;/a&gt;&lt;a href=&quot;l12xml1.htm&quot;&gt;&lt;IMG ALIGN=&quot;MIDDLE&quot; SRC=&quot;xml.gif&quot;</PRE><!--  END CODE //--><A NAME="PAGENUM-230"><P>Page 230</P></A><!--  CODE SNIP //--><PRE>alt=&quot;[XML]&quot;/&gt;&lt;/a&gt;&lt;hr&gt;</PRE><!--  END CODE SNIP //--><P>This entity needs to be declared in the internal DTD subset:</P><!--  CODE SNIP //--><PRE>&lt;!ENTITY header.line SYSTEM &quot;header.XML&quot;&gt;</PRE><!--  END CODE SNIP //--><P>Then it must be referenced from the document itself:</P><!--  CODE //--><PRE>&lt;html&gt;&lt;head&gt;&lt;title&gt;Morphing existing HTML into XML&lt;/title&gt;&lt;/head&gt;&amp;header.line;&lt;h1&gt;Morphing existing HTML into XML&lt;/h1&gt;...</PRE><!--  END CODE //--><P>This is a simple example; there are plenty of other potential uses forXML entities.</P><H4><A NAME="ch12_ 24">Combating &quot;Link Rot&quot;</A></H4><P>Another idea is to use XML entities to keep all the links from your site inone place. This won't stop people from changing the URLs of their Web sites,but it will ease the administrative headache of ensuring that all your links tothose sites are kept up-to-date.</P><P>Create a file that consists of nothing but entity declarations, one per link.Let's call this file <!--  CODE SNIP //--><PRE>&quot;/resources/ext_links.ent&quot;:</PRE><!--  END CODE SNIP //--></P><!--  CODE //--><PRE>&lt;!ENTITY W3C.home`&lt;a <A HREF="href=&quot;http://www.w3c.org/&quot;&gt;the">href=&quot;http://www.w3c.org/&quot;&gt;The</A> W3C Consortium Home Page&lt;/a&gt;'&gt;&lt;!ENTITY W3C.XML`&lt;a <A HREF="href=&quot;http://www.w3c.org/activity/xml/&quot;&gt;the">href=&quot;http://www.w3c.org/Activity/XML/&quot;&gt;The</A> W3C XML Page&lt;/a&gt;'&gt;&lt;!ENTITY CIMI`&lt;a <A HREF="href=&quot;http://www.cimi.org/&quot;&gt;the">href=&quot;http://www.cimi.org/&quot;&gt;The</A> CIMI Consortium&lt;/a&gt;'&gt;...</PRE><!--  END CODE //--><P>Declare this file and then include it in the internal DTD subset of eachXML document:</P><!--  CODE //--><PRE>&lt;!DOCTYPE HTML SYSTEM &quot;HTML2_X.DTD&quot; [&lt;!ENTITY % external.links SYSTEM &quot;/resources/ext_links.ent&quot;&gt;%external.links;...]&gt;</PRE><!--  END CODE //--><P>Now you can use any of the entities you have declared as a shorthand for ana link within the text of your pages:</P><!--  CODE SNIP //--><PRE>&lt;p&gt;For an overview of W3C's work see &amp;W3C.home;. Fordetails of their work on XML see &amp;W3C.XML;. ...</PRE><!--  END CODE SNIP //--><P><CENTER><A HREF="0223-0226.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0231-0234.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>

⌨️ 快捷键说明

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