📄 0104-0106.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="0100-0103.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0107-0108.html">Next</A></CENTER></P><A NAME="PAGENUM-104"><P>Page 104</P></A><P>Therefore, class name is an intrinsic property of all XML classes. Inaddition, XMl classes have another 10 or so intrinsic base properties, such as aproperty that lists the names of all properties exhibited by a particular instance ofthe class.</P><P>Also, certain properties are unique to each class. For example, theelement class has the following properties:</P><UL><LI> genericidentifier is the GI (element type name) of the element.<LI> uniqueidentifier is a unique ID that has been assigned tothe element.<LI>attributes is a list of attribute assignments—one for eachdeclared attribute of the element.<LI>content is the actual content of the element: character data,child elements, and markup such as comment declarations andprocessing instructions that happen to occur within the element.</UL><P>Comment declarations have the single propertymarkup, containing the actual comment. Processinginstructions have the single property system data.</P><P>Each property has a data type, such as string,integer, strlist (a list of strings), enum (an enumerated set of possible values),node, or nodelist. The last two (node and nodelist) provide the glue that keeps everythingtogether.</P><H4><A NAME="ch06_ 32">Nodes and Nodelists</A></H4><P>To make your object-oriented view of an XML document into a coherentsingle object, you need to be able to connect your objects together. The best wayto do this is to consider each object instance to be anode in a tree structure that you are building.</P><P>For example, consider the following person element with some text and acomment declaration inside it:</P><!-- CODE SNIP //--><PRE><person>Fred Flintstone<!-- not! --></person></PRE><!-- END CODE SNIP //--><P>This person element is a node that exhibits the followingproperties:</P><UL><LI> classname: element<LI> genericidentifier: The string person<LI>content: The string Fred Flintstone followed by a commentde-claration</UL><A NAME="PAGENUM-105"><P>Page 105</P></A><P>The key question is, how do you represent the content? It is obviously asequence of data characters followed by a comment declaration.</P><P>If you check out the data type for an element'scontent property, you find that it is nodelist—that is, a list of nodes or objects. So you can describe anelement's content as a list of the objects found within that element. The comment,which is an object in its own right, appears as the last node on that list. (It is quitea long list. Each of the 15 characters in FredFlintstone is treated as a separate data character object in its own right.)</P><P>In a similar way, any attributes that had been declared would beconstructed as attribute assignment objects and attached to the element'sattributes property. Each nodelist property has an associated list of the types ofobject that it can validly contain.</P><P>This is how the whole grove is put together.The sgml document object is the root of the tree structure, or grove, that you are building. This object hasproperties relating to the whole XML document, such asprolog (a nodelist that in turn contains the document type declaration),docelem (a node that contains the document element, or root element of the XML document), andelements (a list of all the elements in the XML document that have uniqueidentifiers).</P><H4><A NAME="ch06_ 33">Grove Plans</A></H4><P>Starting from the root of your grove, you can obtain any of the informationin an XML document—right down to the tiniest detail of the document itselfor its DTD—in a useful object-oriented form. Often, this is much morethan you actually need.</P><P>A grove plan is a list of the object types (classes) and properties in whichyou are interested. It is used to "prune" the complete grove so that it containsonly the aspects of the document that are of interest to your application.Broadly speaking, you take your shears to the root node of your grove structure,and you prune off any objects that are not in the grove plan. For each objectthat is left, you prune off the properties that are not mentioned in the grove plan.</P><P>Then you move on to the subnodes of the root node and do the same thingto them, to their subnodes, and so on. Eventually, you work your waythrough the whole tree, pruning out all classes and properties that are not in thegrove plan. Finally, to tidy up, you remove all references to bits of the tree thatare no longer present as a result of your pruningactivities.</P><A NAME="PAGENUM-106"><P>Page 106</P></A><H4><A NAME="ch06_ 34">Summary</A></H4><P>In this chapter, you examined the logical structures that are found inXML documents.</P><P>The chapter began by outlining the overall logical structure of an XMLdocument. You found that it has an optional prolog, which contains thehighly recommended XML declaration, and a document type declaration, whichis essential for any XML document that has ambitions to be valid. After thiscomes the document element, which contains the actual document.</P><P>You learned that XML documents can be well-formed, which means thatthey contain nicely nested elements and are self-contained. Furthermore, theycan be valid, which means that they pass all the XML rules.</P><P>You then went on to learn just what an element is, and the suitcasemetaphor stressed that elements are containers for information and that the start tagsand end tags you see in XML documents are there to mark the boundaries ofelements. You found that all elements have an element type, and that someelements are officially empty elements. Talking in terms of suitcases alsohelped you to learn why elements have to nest neatly inside each other and howan XML document is, in one sense, just a single element.</P><P>Next, I covered the attributes that can qualify elements. You saw how theycan be used to add value to the text of a document without disturbing its flow,by acting as luggage labels. You saw the different attribute types, each with itsown particular job to do.</P><P>You also reviewed what elements can contain. They can have elementcontent or mixed content (which includes the simple case, in which only datacontent is present). The content of elements in valid XML documents is controlledby content models in the document's DTD.</P><P>Next, you learned how attributes can be used to support hyperlinking.You used the ID and IDREF attribute types to support internal cross-referenceswithin an XML document. Then you saw how theENTITY and ENTITIES attribute types can be used to link to external resources such as images and video clips.</P><P><CENTER><A HREF="0100-0103.html">Previous</A> | <A HREF="../ewtoc.html">Table of Contents</A> | <A HREF="0107-0108.html">Next</A></CENTER></P></TD></TR></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -