0089-0092.html
来自「Presenting XML.rar,详细介绍有关XML的知识」· HTML 代码 · 共 409 行
HTML
409 行
<!DOCTYPE HTML PUBLIC "html.dtd"><HTML><HEAD><TITLE>Presenting XML:Logical Structures in XML Documents: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=06 //--><!-- PAGES=0085-0108 //--><!-- UNASSIGNED1 //--><!-- UNASSIGNED2 //--><P><CENTER><A HREF="0085-0088.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0093-0096.html">Next</A></CENTER></P><A NAME="PAGENUM-89"><P>Page 89</P></A><P>The fact that an XML document is well-formed does not necessarily meanthat no DTD exists for that document. It might be that there is no DTD, butequally the document might have been deliberately delivered without a DTDbecause the current application doesn't need one. Even if the document has aDTD and that DTD is available, there is nothing to force XML applications touse a DTD if it doesn't suit their purposes.</P><P>A well-formed XML document must have a properly declared physicalstructure. Any entity references it contains must relate to entities that havebeen declared in the DTD (apart from the predefined entitiesamp, lt, gt, apos, and quot).</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>For an XML document to be valid, as opposed to well-formed, allthe entities it uses, including these predefined entities, must be declared in the DTD.</BLOCKQUOTE></TD></TR></TABLE><P>The concept of being well-formed sounds like an invitation to anarchy,but that is not its purpose. The concept is provided in XML because, formany purposes, it is not necessary to provide a DTD or to formally check adocument against that DTD. Reading a DTD takes time and bandwidth;checking an XML document against its DTD takes even more time. If a serverof XML documents has already ensured that they are all valid and clean, it isa waste of time for each client to have to do the same.</P><P>Because an XML document defines its own hierarchical elementstructure, applications that simply want to display the document might workperfectly well without the DTD. See Chapter 11, "The XML Processor," for amore detailed discussion of how an XML processor deals with well-formeddocuments.</P><H4><A NAME="ch06_ 8">Valid Documents</A></H4><P>In contrast to well-formed XML documents, valid XML documents haveto obey all the rules. Not only must they have a DTD, but each elementmust conform to the rules that the DTD lays down for it. This is the mode inwhich XML documents will typically be created and updated. Chapter 8contains further details of the rules that the DTD imposes.</P><A NAME="PAGENUM-90"><P>Page 90</P></A><P>XML's validity rules are an additional layer on top of the rules for beingwell-formed. Every valid XML document must be well-formed as well.</P><P>Whether an application checks that an XML document is valid as well asbeing well-formed is determined by the XML processor it uses. If a non-validatingXML processor is used, it will just check that the XML document is well-formed. Ifa validating XML processor is used, it will report any validityerrors in addition to checking that the XML document is well-formed. Chapter 11 discussesthe operation of both types of XML processor indetail.</P><H3><A NAME="ch06_ 9">Elements</A></H3><P>Now let's look at elements in more detail. First of all, what is an element? Itis more than just a tag, or even a pair of tags. Let's start by reviewing whatan element appears to be in HTML and then move on to the XML case.</P><H4><A NAME="ch06_ 10">Elements in HTML</A></H4><P>In HTML, the concept of an element isn't particularly relevant. HTMLtags tend to be used as style indicators, markers, and switches. It's not clearwhere a thing called element would fit into the picture.</P><P>For example, paragraphs tend to have only start tags, effectively saying "starta new paragraph here" or "make the following text paragraph style," as inthe following example:</P><!-- CODE SNIP //--><PRE><p>The boy stood on the burning deck ...</PRE><!-- END CODE SNIP //--><P>Although p elements can have end tags, these end tags are frequentlyomitted. This means that you know where each paragraph starts, but you have toguess where it ends, and so does any software that is processing the HTMLdocument.</P><P>Some tags are included simply to mark where visual elements should beplaced. For example, <hr> marks the placement of a horizontal line in the HTML page.</P><P>Other tags switch on and off typesetting features such as bold and italic.For example, the following line marks a phrase that is to appear as both boldand italic:</P><!-- CODE SNIP //--><PRE><b><i>This is really important</b></i></PRE><!-- END CODE SNIP //--><A NAME="PAGENUM-91"><P>Page 91</P></A><P>Each start tag switches the relevant feature on, and each end tag switches <BR>it off.</P><H4><A NAME="ch06_ 11">XML Elements: The Suitcase Model</A></H4><P>To understand XML elements, you need to put the HTML view ofmarkup out of your mind and dream up a new metaphor. Think of an XMLelement as a particular type of suitcase, with an optional luggage label on the sidegiving extra useful information. This suitcase might contain baggage(character data) or smaller suitcases. These smaller suitcases might also have aluggage label and contents. Some suitcases will be empty, but they will be therebecause their luggage labels hold useful information.</P><P>Figure 6.1 illustrates this idea by showing a p element that contains amixture of character data and subelements (rs andemph). Each of these three elements is represented by a suitcase that has a luggage label containing a single pieceof information. Inside the rs and emph suitcases (elements) will be morebaggage (character data).<BR></P><A HREF="javascript:displayWindow('images/ch06fg01.jpg',252,209)"><IMG SRC="images/tn_ch06fg01.jpg"></A><BR>Figure 6.1.<BR>Elements as suitcases.<BR><A NAME="PAGENUM-92"><P>Page 92</P></A><P>You learned in Chapter 5 that an XML document consists of a singleelement. To put that in terms of the suitcase model, if you want to fly XML Air,you must check in with a single item of baggage. Everything else must bepacked inside it. (Fortunately, XML Air doesn't impose any size or weight restrictions!)</P><H5><A NAME="ch06_ 12">Start Tags and End Tags</A></H5><P>In order to be able to contain things, elements need to have a finite size.Moving from the three-dimensional world of suitcases to the two-dimensionalworld of structured documents, the finite size of a document is achieved by havinga start tag and an end tag, which mark the boundaries of an element (itsbeginning and its end). Each of these tags includes a name that indicates theelement's type. Start tags take the following form:</P><!-- CODE SNIP //--><PRE><Name></PRE><!-- END CODE SNIP //--><P>End tags look like this:</P><!-- CODE SNIP //--><PRE></Name></PRE><!-- END CODE SNIP //--><P>Here is a complete example:</P><!-- CODE SNIP //--><PRE><mytag> [content goes here] </mytag></PRE><!-- END CODE SNIP //--><BR><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>In XML, you are not allowed to omit end tags for elements thatare not empty. This is in contrast to both HTML and generic SGML, whereboth start tags and end tags can be omitted in certaincircumstances.</BLOCKQUOTE></TD></TR></TABLE><H5><A NAME="ch06_ 13">Empty Elements</A></H5><P>Empty elements have a special format. Because they have no contents, theydon't need to have a start tag and an end tag to hold those contents. Instead,they use a format for their start tag that indicates quite clearly (both to humanreaders and to XML-aware software) that they are empty. This format includesa / just before the end of the empty element's starttag:</P><!-- CODE SNIP //--><PRE><Name/></PRE><!-- END CODE SNIP //--><P>Here is an example:</P><!-- CODE SNIP //--><PRE><emptytag/></PRE><!-- END CODE SNIP //--><P>Empty elements do not have an end tag.</P><P><CENTER><A HREF="0085-0088.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0093-0096.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?