📄 0223-0226.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="0219-0222.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0227-0230.html">Next</A></CENTER></P><A NAME="PAGENUM-223"><P>Page 223</P></A><P>In general, you will need to carefully reconsider the design of any SGMLDTD that uses exceptions if you are trying to produce an equivalent XML-<BR>compatible DTD. It is not easy to produce a DTD with exactly the sameproperties, and you will probably need to choose between making the XMLDTD more or less restrictive than the original.</P><H4><A NAME="ch12_ 13">& Connectors</A></H4><P>SGML allows the element types in a content model to be separated by&, which means that they must all occur, but in any order:</P><!-- CODE SNIP //--><PRE><!ENTITY % head.content "TITLE & ISINDEX? & BASE? %head.extra"></PRE><!-- END CODE SNIP //--><P>XML doesn't support the & connector, so all the content models that useit must be rewritten. This necessity was the other significant headache Ireceived in producing the HTML DTD for XML.</P><P>Here I decided that the TITLE element must be present and must appearonce only, but the other element types are less critical. So I produced a contentmodel where they can occur zero or more times, on either side ofTITLE:</P><!-- CODE SNIP //--><PRE><!ENTITY % head.optional "ISINDEX | BASE | META | LINK %head.extra;"><!ENTITY % head.content "(%head.optional;)*, TITLE, (%head.optional;)*"></PRE><!-- END CODE SNIP //--><P>This is not as precise as the original content model, but at least it isupward compatible.</P><H4><A NAME="ch12_ 14">Limited Attribute Types</A></H4><P>XML supports fewer types of attributes than SGML. The HTML DTDuses some of the types that XML doesn't support. For example, you need to change</P><!-- CODE SNIP //--><PRE><!ENTITY % linkType "NAMES"></PRE><!-- END CODE SNIP //--><P>to</P><!-- CODE SNIP //--><PRE><!ENTITY % linkType "NMTOKENS"></PRE><!-- END CODE SNIP //--><P>and</P><!-- CODE SNIP //--><PRE><!ATTLIST PRE WIDTH NUMBER #implied</PRE><!-- END CODE SNIP //--><P>to</P><!-- CODE SNIP //--><PRE><!ATTLIST PRE WIDTH CDATA #implied</PRE><!-- END CODE SNIP //--><A NAME="PAGENUM-224"><P>Page 224</P></A><H4><A NAME="ch12_ 15">XML-Link Support</A></H4><P>XML-Link provides a new method of indicating that certain attributelists contain link information. It also adds value to these links with someadditional attributes (ROLE, SHOW, and so on).</P><P>These additional attributes can all be neatly added in one place—tothe linkExtraAttributes parameter entity:</P><!-- CODE //--><PRE><!ENTITY % linkExtraAttributes"XML-LINK CDATA #FIXED `SIMPLE'ROLE CDATA #IMPLIEDSHOW (EMBED|REPLACE|NEW) `REPLACE'ACTUATE (AUTO|USER) `USER'BEHAVIOR CDATA #IMPLIEDREL %linkType #IMPLIED...</PRE><!-- END CODE //--><P>It is easy to add XML-Link support to HTML, because the designers ofXML-Link took great care to make the attributes that control linking in XML <BR>upward-compatible with existing HTML practice. For example, theyhave adopted the HREF and TITLE attributes and have given them the samemeaning as in HTML.</P><P>Another change I made that relates to linking was to convert theNAME attribute on the a element to an ID attribute. XML-Link gives preferential supportto IDs by allowing a simple, HTML-like syntax when an element with anID is the target of a link:</P><!-- CODE SNIP //--><PRE><a href="#backMatter"></PRE><!-- END CODE SNIP //--><P>This makes the full power of XML simple links available wherever linksare used in HTML.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>As I have outlined, changing from NAME toID gives you advantages in an XML environment, but it also has a price. The form thatID attribute values can take (they have to be an XMLName) is more restrictive than the form of a NAME (which can contain any character data you like).</BLOCKQUOTE></TD></TR></TABLE><P>For XML compatibility, the HREF attribute becomes mandatory for thea element type:</P><!-- CODE SNIP //--><PRE><!ATTLIST AHREF CDATA #REQUIREDID ID #IMPLIED%linkExtraAttributes;</PRE><!-- END CODE SNIP //--><A NAME="PAGENUM-225"><P>Page 225</P></A><!-- CODE SNIP //--><PRE>%SDAPREF; "<Anchor: #AttList>"></PRE><!-- END CODE SNIP //--><H4><A NAME="ch12_ 16">Images</A></H4><P>The img element type makes no attempt to check the presence of the image.I decided to redeclare IMG as an XML link that was automatically followed,with the resulting resource being embedded in the document:</P><!-- CODE //--><PRE><!ATTLIST IMGXML-LINK CDATA #FIXED `SIMPLE'HREF CDATA #REQUIREDROLE CDATA #IMPLIEDSHOW (EMBED|REPLACE|NEW) #FIXED `EMBED'ACTUATE (AUTO|USER) #FIXED `AUTO'BEHAVIOR CDATA #IMPLIEDALT CDATA #IMPLIED...</PRE><!-- END CODE //--><P>Another method that achieves a similar result is to change its declarationso that the SRC attribute points to an entity rather than just being any oldcharacter data:</P><!-- CODE SNIP //--><PRE><!ATTLIST IMGSRC ENTITY #REQUIRED...</PRE><!-- END CODE SNIP //--><P>This is not strictly necessary for XML compatibility, but it does emphasizethat the image is an integral part of the Web page, and not an optional link from it.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>This change means that all IMG elements in your sample page andthe GIF notation now need to be declared in the internal DTD subset:<!NOTATION GIF SYSTEM "lview.exe"><BR><!ENTITY logo.home SYSTEM "home.gif" NDATA GIF><BR><!ENTITY logo.html SYSTEM "html.gif" NDATA GIF><BR<!ENTITY LOGO.XML NDATA "XML.GIF" SYSTEM GIF></BLOCKQUOTE></BLOCKQUOTE></TD></TR></TABLE><H4><A NAME="ch12_ 17">Predefined Entities</A></H4><P>XML recognizes predefined entity references for five characters that areused in markup: <, >, &, `, and ". However, it then mandates that if theseentities are declared in an XML DTD, they must take exactly the form specified inthe XML standard:</P><A NAME="PAGENUM-226"><P>Page 226</P></A><!-- CODE //--><PRE><!ENTITY lt "&#60;"><!ENTITY gt "&#62;"><!ENTITY amp "&#38;"><!ENTITY apos "`"><!ENTITY quot `"`></PRE><!-- END CODE //--><P>Four of these characters are declared in the HTML DTD, but not in thisform, so their declarations have been changed, and the fifth character(apostrophe) was added for completeness.</P><H4><A NAME="ch12_ 18">General Tidying Up</A></H4><P>The following differences between the general syntax of SGML and XMLaffect this DTD:</P><UL><LI> Comments: Inline comments, surrounded by pairs of hyphens, arenot allowed within declarations in XML DTDs. Instead, they mustbe placed in "proper" comments before or (preferably) after thedeclaration.<LI> Parameter entity references: Where parameter entities are used,their name must be followed by a semicolon in XML. This is optionalin SGML.<LI> Default attribute values: Where a default value for an attributeis given, it must be surrounded by a pair of quote characters.<LI> Conditional sections: XML does not allow spaces on either side ofthe keyword that introduces a conditional section:</UL><!-- CODE SNIP //--><PRE> <![ %HTML.Recommended; [</PRE><!-- END CODE SNIP //--><UL> Therefore, these spaces had to be removed.</UL><H3><A NAME="ch12_ 19">Declaring Embedded Entities</A></H3><P>Now that you have an HTML DTD that is valid for XML, you can returnto the sample Web page.</P><P>One difference between SGML and XML is that all the external resourcesused within the document must be declared in the DTD. What you havebeen updating is, strictly speaking, only part of your document's DTD—theexternal DTD subset.</P><P><CENTER><A HREF="0219-0222.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0227-0230.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -