📄 0231-0234.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="0227-0230.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="../ch13/0235-0239.html">Next</A></CENTER></P><A NAME="PAGENUM-231"><P>Page 231</P></A><P>This will be processed as though you had entered thea element in full each time:</P><!-- CODE //--><PRE><p>For an overview of W3C's work see <a <A HREF="href="http://www.w3c.org/"">href="http://www.w3c.org/"</A>>The W3C Consortium Home Page</a>. Fordetails of their work on XML see <a<A HREF="href="http://www.w3c.org/activity/xml/">the">href="http://www.w3c.org/Activity/XML/">The</A> W3C XMLPage</a>. ...</PRE><!-- END CODE //--><P>The advantage of this approach is that all your external links are now inone place, and each link is declared only once. So, if you find that a URLhas changed, you need to update it only once. You can then be sure that anyof your pages that are linked to that URL will continue to work.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>One useful idea would be to have a test page, containing references toall your external links. This would provide a straightforward (if tedious) meansof testing that all your links still work, by going through the test page clickingon all the links. Alternatively, you could employ link-checking software toscan your test page.</BLOCKQUOTE></TD></TR></TABLE><H3><A NAME="ch12_ 25">Better Links</A></H3><P>Your sample page contains a number of links that vary in their intentions.By using the built-in features of XML-Link, you can ensure that an XMLprocessor is able to act sensibly on each of these links.</P><P>The three links that are wrapped around the images at the head of the pageare standard URL links. They are passive links, which will be acted upon onlyif the client clicks on them. Not surprisingly, the default setting for XML'slink attributes deals with this case, so there is no need to specify them. Just forthe record, the first three links behave as though they were marked up like this:</P><!-- CODE SNIP //--><PRE><a href="l12_1.htm" SHOW="REPLACE" ACTUATE="USER">...</a></PRE><!-- END CODE SNIP //--><P>The link to the footnote is rather different. The target of the link is just acomment, not a separate page. In this case, the link can be marked up like so:</P><!-- CODE SNIP //--><PRE><a href="l12note1.htm" SHOW="NEW" ACTUATE="USER">Note 1</a></PRE><!-- END CODE SNIP //--><P>The SHOW="NEW" attribute specification tells an XML browser to place thenote in a new window. This allows the note to appear as a pop-up rather thantake over the entire screen. As before,ACTUATE="USER" means that the note willappear only if the client clicks on the link.</P><A NAME="PAGENUM-232"><P>Page 232</P></A><H4><A NAME="ch12_ 26">Linking in a Header File</A></H4><P>XML links give you two more ways of dealing with standard header andfooter material, in addition to the technique described in the previous section.</P><P>The first method allows you to treat the header material as aself-contained XML "document" rather than a file containing some orphaned markup.However, this works only if the header material can be packed into a singleelement so that it can be a valid (or at least a well-formed) XML document. Thebody element is ideal for this purpose:</P><!-- CODE //--><PRE><?XML version="1.0"?><body><hr><a href="l12_1.htm"><IMG ALIGN="MIDDLE" SRC="home.gif"alt="[home page]"/></a><a href="l12html1.htm"><IMG ALIGN="MIDDLE" SRC="html.gif"alt="[HTML]"/></a><a href="l12xml1.htm"><IMG ALIGN="MIDDLE" SRC="xml.gif"alt="[XML]"/></a><hr></body></PRE><!-- END CODE //--><P>In this case, you can set up a link to the header information with theoptions SHOW="EMBED" andACTUATE="AUTO":</P><!-- CODE SNIP //--><PRE><a SHOW="EMBED" ACTUATE="AUTO" href="header.xml"></a></PRE><!-- END CODE SNIP //--><P>These options tell an XML processor that the header information is anessential part of the current document and that it should be inserted into the textat the point where the link is declared. However, it doesn't imply that theheader information is actually a physical part of the page, in the way thatembedding an entity reference does. This might affect the way that the header istreated by your XML-aware browser.</P><H4><A NAME="ch12_ 27">Linking in Part of Another Page</A></H4><P>Instead of putting the header information into a separate file, you can useXML links in a slightly smarter way to "copy forward" the header informationfrom the first page. If the header information is simply placed into the firstpage, but surrounded by an a element with a suitableID, like</P><!-- CODE SNIP //--><PRE><a ID="header">...</a></PRE><!-- END CODE SNIP //--><A NAME="PAGENUM-233"><P>Page 233</P></A><P>then subsequent pages can "pull in" the header information by using anXML link with the special ?XML-XPTR= connector:</P><!-- CODE SNIP //--><PRE><a SHOW="EMBED" ACTUATE="AUTO"href="homepage.htm?XML-XPTR=header"></a></PRE><!-- END CODE SNIP //--><P>This approach has the advantage that there is no need to manage theheader information as a separate file. Admittedly, it means that your server willneed to read the full home page to extract the header information, but in this caseit is likely that it already did this when you first accessed the site.</P><H3><A NAME="ch12_ 28">Separating the Style Information</A></H3><P>A fair proportion of the markup in your sample page is just there toensure that the result looks right when the page is displayed. It is more in the spiritof XML to separate out the style information, so let's see what you can dowith the example.</P><P>One obvious visual convention is the insertion of horizontal rules betweeneach section of the document. In the absence of markup to show thesesections unambiguously, you could simply place a horizontal rule before eachh1 heading that you encounter. This means that you can take out thehr tags completely and, instead, have a style sheet entry forh1 (and h2, and so on) that looks something like this:</P><!-- CODE SNIP //--><PRE>(element H1 (HEADING-WITH-RULE 16 "center"))(element H2 (HEADING-WITH-RULE 14 "left"))(element H3 (HEADING-WITH-RULE 12 "left"))</PRE><!-- END CODE SNIP //--><P>In this entry, the procedure HEADING-WITH-RULE outputs a horizontal rule,followed by the heading, using the quadding and point size specified (16ptcentered for the h1 heading; 14pt left-justified for theh2 heading, and so on).</P><P>See Chapter 10, "The XML Style Mechanism," for a fuller description ofthe XML style mechanism.</P><A NAME="PAGENUM-234"><P>Page 234</P></A><H3><A NAME="ch12_ 29">Summary</A></H3><P>In this chapter, you took a piece of HTML and learned how it would standup as XML.</P><P>You found that the habit of using SGML-style markup shortcutswithout SGML strength checking has led to HTML that routinely containsmarkup errors. Looking more closely, you found that even when these errors areremoved, HTML won't be acceptable as XML because of these shortcuts.You spelled out everything and then managed to make the sample page awell-formed XML document.</P><P>The process of upgrading that well-formed instance to a valid XMLdocument wasn't too difficult, but first you had a great deal of work to do on theHTML DTD itself. This revealed some differences between SGML and XMLDTDs that will require some careful thought on the part of DTD designer folks.</P><P>After you made the sample HTML page into a valid XML document, yougave some thought to how you might leverage XML's built-in capabilities tomake life easier for the XML-based Web site manager. You saw how entitiescould be used to hold information that occurs in several different pages and evento manage links more effectively. Then you explored how XML's linkingfacilities might be used to give closer control over the relationships betweenpages within a site. Finally, you looked briefly at how XML styles might be usedto simplify the markup of the Web pages themselves.</P><P><CENTER><A HREF="0227-0230.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="../ch13/0235-0239.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -