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

📄 0093-0096.html

📁 Presenting XML.rar,详细介绍有关XML的知识
💻 HTML
字号:
<!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="0089-0092.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0097-0099.html">Next</A></CENTER></P><A NAME="PAGENUM-93"><P>Page 93</P></A><H5><A NAME="ch06_ 14">Element Types</A></H5><P>The type of an element indicates the type of information that the elementcontains. As you learned in Chapter 1, &quot;Markup in Theory and Practice,&quot; theelement type should not imply any particular formatting. For example,heading is preferable to bold-centered. However, in practice this is not alwayspossible. It is very hard to mark up a table without elements to represent rowsand columns!</P><H3><A NAME="ch06_ 15">Attributes: The Luggage Label</A></H3><P>Now that you understand the suitcase, what about the luggage label? Thissection looks at the attributes of XML elements.</P><H4><A NAME="ch06_ 16">Attribute Specifications</A></H4><P>The luggage label, or additional information that is added to an element,is called its attribute specifications. These take the following form:</P><!--  CODE SNIP //--><PRE>Name Eq AttValue</PRE><!--  END CODE SNIP //--><P>Here is an example:</P><!--  CODE SNIP //--><PRE>HREF=&quot;http://www.w3.org/XML/Activity&quot;</A></PRE><!--  END CODE SNIP //--><P>In this case, HREF is the attribute name, and <A HREF="http://www.w3c.org/xml/">http://www.w3c.org/XML/</A><BR>Activity is the attribute value.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Warning:</TD></TR><TR><TD><BLOCKQUOTE>In XML, all attribute values must be quoted. This is differentfrom HTML (and SGML), in which the quotation marks are optional.Matched pairs of either single or double quotation marks can be used for thispurpose. Also, note that no spaces are allowed on either side of the= within the attribute specification.</BLOCKQUOTE></TD></TR></TABLE><P>If you need to include quotation marks in your attribute values, theentity references &amp;apos; and &amp;quot; can be used within attribute values asescapes for single and double quotation marks,respectively.</P><A NAME="PAGENUM-94"><P>Page 94</P></A><P>The attribute specifications appear in an element's start tag. You must havea space between the element type and the first attribute specification, andbetween each attribute specification if there is more than one. Here is an example:</P><!--  CODE SNIP //--><PRE>&lt;person KEY=&quot;A14768&quot; ROLE=&quot;designer&quot;&gt;</PRE><!--  END CODE SNIP //--><P>The following example is for an empty element:</P><!--  CODE SNIP //--><PRE>&lt;IMG ALIGN=&quot;left&quot; SRC=&quot;http://www.w3.org/pub/icons/w3c_48X48.gif&quot;/&gt;</A></PRE><!--  END CODE SNIP //--><P>One thing you are not allowed to put into an attribute value is an entityreference to an external entity. (See Chapter 7 for details of what these are.) Ifyou refer to an external entity, the XML document isn't even well-formed andis certainly not valid. You can refer to external entities in XML attributes,but you need to use the ENTITY or ENTITIES attribute type and quote them byname. (Attribute types are discussed in the nextsection.)</P><H4><A NAME="ch06_ 17">Attribute-List Declarations</A></H4><P>If you want your XML document to be valid, you don't have the freedomto write just anything on these luggage labels.</P><P>Each element type has a list of allowed attributes, which is declared in theDTD as an attribute-list declaration. For example, the declaration</P><!--  CODE SNIP //--><PRE>&lt;!ATTLIST PERSONID ID #REQUIREDROLE CDATA #IMPLIEDKEY CDATA #IMPLIEDTEIFORM CDATA &quot;PERSON&quot; &gt;</PRE><!--  END CODE SNIP //--><P>states that the person element type has four allowed attributes, calledID, ROLE, KEY, and TEIFORM.</P><P>You can add any or all of the attributes declared in its attribute-listdeclaration to each element in your XML documents, in any order. If you choose notto provide an attribute specification, its value is said tobe implied.</P><TABLE BGCOLOR="#FFFF99"><TR><TD>Note:</TD></TR><TR><TD><BLOCKQUOTE>A non-validating XML processor will not check the attributesagainst the DTD, so you can enter any attribute specifications you like and still havea well-formed XML document.</BLOCKQUOTE></TD></TR></TABLE><A NAME="PAGENUM-95"><P>Page 95</P></A><P>Only one attribute specification is allowed for each attribute definition inthe DTD. To put that in simpler terms, attribute specifications cannot repeatwithin an element's start tag. Therefore, the following is not a well-formed start tag:</P><!--  CODE SNIP //--><PRE>&lt;person role=&quot;author&quot; role=&quot;designer&quot;&gt;</PRE><!--  END CODE SNIP //--><P>Chapter 8 includes a section on attribute-list declarations, which gives afull description of their syntax.</P><H4><A NAME="ch06_ 18">Attribute Types</A></H4><P>Each attribute is declared to have an attributetype. For validity, each attribute specification you provide must have a value that is of the correct type forthat attribute. In the previous declaration example,ID is an ID-type attribute, which provides a unique identifier for eachperson element. ROLE and KEY both contain characterdata, which means any text.</P><P>XML divides attribute types into three groups: stringtypes, tokenized types, and enumerated types.</P><P>String type attributes are indicated by CDATA in the attribute-listdeclaration. (ROLE and KEY are string type attributes in this example.) They can takeany literal string as their value.</P><P>The following are the seven tokenized attributetypes:</P><UL><LI>     ID is an identifier for the element, which must be unique withinthe XML document. Attribute values of type ID must consist of aName symbol.<LI>     IDREF is a pointer to anID attribute value. An element with an ID with the specified value must be included somewhere in theXML document.<LI>     IDREFS is the same as theIDREF type, except that the value can contain any number ofID references separated by spaces.<LI>    ENTITY is a pointer to an external entity. The value must consist ofa Name symbol, and it must be a case-sensitive match for the nameof an external binary general entity declared in the DTD.<LI>ENTITIES is the same as the ENTITY type, except that the valuecan contain any number of entity names separated by spaces.</UL><A NAME="PAGENUM-96"><P>Page 96</P></A><UL><LI>NMTOKEN contains a value that is a Nmtoken.<LI>NMTOKENS contains a value that conforms to theNmtokens production.</UL><P>Nmtoken and Nmtokens are defined in the &quot;Primitive Constructs&quot; sectionof Chapter 5.</P><P>An enumerated attribute type is one that offers a fixed set of options. It iseither a notation type or a general-purposeenumeration.</P><P>Notation type attributes offer a set of possiblenotations (as covered in Chapter 7). They take the form</P><!--  CODE SNIP //--><PRE>NOTATION ( A | B | ...)</PRE><!--  END CODE SNIP //--><P>in which A, B, and so on must be the names of notations declared in theDTD. The following example could be used to specify a range of possible imageformats:</P><!--  CODE SNIP //--><PRE>NOTATION ( BMP | WMF | GIF | TIFF | JPEG )</PRE><!--  END CODE SNIP //--><P>Values must match one of these notation names.</P><P>Enumeration attributes consist of a set ofNmtoken tokens, as in the following example:</P><!--  CODE SNIP //--><PRE>( HAM | BEEF | MUSHROOM | EXTRA_CHEESE )</PRE><!--  END CODE SNIP //--><P>Values must match one of these Nmtoken tokens.</P><P>Because an XML processor folds all ID, IDREF,IDREFS, NMTOKEN, and NMTOKENS values to uppercase, it will check these types of attribute values against thevalues allowed by the DTD in a case-insensitive manner.CDATA, ENTITY, and ENTITIES values, on the other hand, are case sensitive and so must matchthe declared values exactly.</P><H4><A NAME="ch06_ 19">Mandatory Attributes</A></H4><P>Sometimes the DTD declares that it is mandatory to provide a certainattribute. In this example, you are required to specify anID for each person element.</P><H4><A NAME="ch06_ 20">Default and Fixed Values</A></H4><P>Sometimes an attribute is given a default value in the DTD, so you don'thave to type it in each time. The TEIFORMattribute has the default value person. Attributes can even be given a fixed value, which you can't change even ifyou want to.</P><P><CENTER><A HREF="0089-0092.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0097-0099.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>

⌨️ 快捷键说明

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