📄 introxml3.html
字号:
<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <title>XML and Related Specs: Digesting the Alphabet Soup</title> <link rel="StyleSheet" href="document.css" type="text/css" media="all" /> <link rel="StyleSheet" href="catalog.css" type="text/css" media="all" /> <link rel="Table of Contents" href="J2EETutorialTOC.html" /> <link rel="Previous" href="IntroXML2.html" /> <link rel="Next" href="IntroXML4.html" /> <link rel="Index" href="J2EETutorialIX.html" /> </head> <body> <table width="550" summary="layout" id="SummaryNotReq1"> <tr> <td align="left" valign="center"> <font size="-1"> <a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a> </td> <td align="center" valign="center"><a accesskey="p" href="IntroXML2.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="IntroXML4.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a> </td> <td align="right" valign="center"> <font size="-1"> <a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a> <br> <a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font> </font> </td> </tr> </table> <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"> <blockquote><a name="wp64046"> </a><h2 class="pHeading1">XML and Related Specs: Digesting the Alphabet Soup</h2><a name="wp64047"> </a><p class="pBody">Now that you have a basic understanding of XML, it makes sense to get a high-level overview of the various XML-related acronyms and what they mean. There is a lot of work going on around XML, so there is a lot to learn. </p><a name="wp64048"> </a><p class="pBody">The current APIs for accessing XML documents either serially or in random access mode are, respectively, <a href="IntroXML3.html#wp64117">SAX</a> and <a href="IntroXML3.html#wp64126">DOM</a>. The specifications for ensuring the validity of XML documents are <a href="IntroXML3.html#wp64130">DTD</a> (the original mechanism, defined as part of the XML specification) and various <a href="IntroXML3.html#wp71944">Schema Standards</a> proposals (newer mechanisms that use XML syntax to do the job of describing validation criteria). </p><a name="wp64064"> </a><p class="pBody">Other future standards that are nearing completion include the <a href="IntroXML3.html#wp64148">XSL</a> standard--a mechanism for setting up translations of XML documents (for example to HTML or other XML) and for dictating how the document is rendered. The transformation part of that standard, <a href="IntroXML3.html#wp64153">XSLT (+XPATH)</a>, is completed and covered in this tutorial. Another effort nearing completion is the XML Link Language specification (<a href="IntroXML3.html#wp64198">XML Linking</a>), which enables links between XML documents. </p><a name="wp64071"> </a><p class="pBody">Those are the major initiatives you will want to be familiar with. This section also surveys a number of other interesting proposals, including the HTML-lookalike standard, <a href="IntroXML3.html#wp64211">XHTML</a>, and the meta-standard for describing the information an XML document contains, <a href="IntroXML3.html#wp64220">RDF</a>. There are also standards efforts that extend XML's capabilities, such as XLink and XPointer. </p><a name="wp64078"> </a><p class="pBody">Finally, there are a number of interesting standards and standards-proposals that build on XML, including Synchronized Multimedia Integration Language (<a href="IntroXML3.html#wp64240">SMIL</a>), Mathematical Markup Language (<a href="IntroXML3.html#wp64245">MathML</a>), Scalable Vector Graphics (<a href="IntroXML3.html#wp64250">SVG</a>), and <a href="IntroXML3.html#wp64255">DrawML</a>, as well as a number of eCommerce standards. </p><a name="wp64091"> </a><p class="pBody">The remainder of this section gives you a more detailed description of these initiatives. To help keep things straight, it's divided into: </p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp64095"> </a><div class="pSmartList1"><li><a href="IntroXML3.html#wp64114">Basic Standards</a></li></div><a name="wp64099"> </a><div class="pSmartList1"><li><a href="IntroXML3.html#wp71944">Schema Standards</a></li></div><a name="wp64103"> </a><div class="pSmartList1"><li><a href="IntroXML3.html#wp64195">Linking and Presentation Standards</a></li></div><a name="wp64107"> </a><div class="pSmartList1"><li><a href="IntroXML3.html#wp64216">Knowledge Standards</a></li></div><a name="wp64111"> </a><div class="pSmartList1"><li><a href="IntroXML3.html#wp64234">Standards That Build on XML</a></li></div></ul></div><a name="wp64112"> </a><p class="pBody">Skim the terms once, so you know what's here, and keep a copy of this document handy so you can refer to it whenever you see one of these terms in something you're reading. Pretty soon, you'll have them all committed to memory, and you'll be at least "conversant" with XML! </p><a name="wp64114"> </a><h3 class="pHeading2">Basic Standards</h3><a name="wp64115"> </a><p class="pBody">These are the basic standards you need to be familiar with. They come up in pretty much any discussion of XML. </p><a name="wp64117"> </a><h4 class="pHeading3">SAX</h4><a name="wp64118"> </a><p class="pBody">Simple API for XML</p><a name="wp64119"> </a><p class="pBody">This API was actually a product of collaboration on the XML-DEV mailing list, rather than a product of the W3C. It's included here because it has the same "final" characteristics as a W3C recommendation.</p><a name="wp64120"> </a><p class="pBody">You can also think of this standard as the "serial access" protocol for XML. This is the fast-to-execute mechanism you would use to read and write XML data in a server, for example. This is also called an event-driven protocol, because the technique is to register your handler with a SAX parser, after which the parser invokes your callback methods whenever it sees a new XML tag (or encounters an error, or wants to tell you anything else).</p><a name="wp64126"> </a><h4 class="pHeading3">DOM</h4><a name="wp64127"> </a><p class="pBody">Document Object Model</p><a name="wp66310"> </a><p class="pBody">The Document Object Model protocol converts an XML document into a collection of objects in your program. You can then manipulate the object model in any way that makes sense. This mechanism is also known as the "random access" protocol, because you can visit any part of the data at any time. You can then modify the data, remove it, or insert new data. </p><a name="wp66315"> </a><h4 class="pHeading3">JDOM and dom4j</h4><a name="wp66281"> </a><p class="pBody">While the Document Object Model (DOM) provides a lot of power for document-oriented processing, it doesn't provide much in the way of object-oriented simplification. Java developers who are processing more data-oriented structures--rather than books, articles, and other full-fledged documents--frequently find that object-oriented APIs like JDOM and dom4j are easier to use and more suited to their needs.</p><a name="wp66324"> </a><p class="pBody">Here are the important differences to understand when choosing between the two:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp66325"> </a><div class="pSmartList1"><li>JDOM is somewhat cleaner, smaller API. Where "coding style" is an important consideration, JDOM is a good choice.</li></div><a name="wp66338"> </a><div class="pSmartList1"><li>JDOM is a Java Community Process (JCP) initiative. When completed, it will be an endorsed standard.</li></div><a name="wp66339"> </a><div class="pSmartList1"><li>dom4j is a smaller, faster implementation that has been in wide use for a number of years.</li></div><a name="wp66341"> </a><div class="pSmartList1"><li>dom4j is a factory-based implementation. That makes it easier to modify for complex, special-purpose applications. At the time of this writing, JDOM does not yet use a factory to instantiate an instance of the parser (although the standard appears to be headed in that direction). So, with JDOM, you always get the original parser. (That's fine for the majority of applications, but may not be appropriate if your application has special needs.)</li></div></ul></div><a name="wp66330"> </a><p class="pBody">For more information on JDOM, see <code class="cCode"><a href="http://www.jdom.org/" target="_blank">http://www.jdom.org/</a></code>.</p><a name="wp66283"> </a><p class="pBody">For more information on dom4j, see <code class="cCode"><a href="http://dom4j.org/" target="_blank">http://dom4j.org/</a></code>.</p><a name="wp64130"> </a><h4 class="pHeading3">DTD</h4><a name="wp64131"> </a><p class="pBody">Document Type Definition</p><a name="wp64132"> </a><p class="pBody">The DTD specification is actually part of the XML specification, rather than a separate entity. On the other hand, it is optional--you can write an XML document without it. And there are a number of <a href="IntroXML3.html#wp71944">Schema Standards</a> proposals that offer more flexible alternatives. So it is treated here as though it were a separate specification.</p><a name="wp64136"> </a><p class="pBody">A DTD specifies the kinds of tags that can be included in your XML document, and the valid arrangements of those tags. You can use the DTD to make sure you don't create an invalid XML structure. You can also use it to make sure that the XML structure you are reading (or that got sent over the net) is indeed valid.</p><a name="wp64137"> </a><p class="pBody">Unfortunately, it is difficult to specify a DTD for a complex document in such a way that it prevents all invalid combinations and allows all the valid ones. So constructing a DTD is something of an art. The DTD can exist at the front of the document, as part of the prolog. It can also exist as a separate entity, or it can be split between the document prolog and one or more additional entities.</p><a name="wp64138"> </a><p class="pBody">However, while the DTD mechanism was the first method defined for specifying valid document structure, it was not the last. Several newer schema specifications have been devised. You'll learn about those momentarily.</p><a name="wp64144"> </a><h4 class="pHeading3">Namespaces</h4><a name="wp64145"> </a><p class="pBody">The namespace standard lets you write an XML document that uses two or more sets of XML tags in modular fashion. Suppose for example that you created an XML-based parts list that uses XML descriptions of parts supplied by other manufacturers (online!). The "price" data supplied by the subcomponents would be amounts you want to total up, while the "price" data for the structure as a whole would be something you want to display. The namespace specification defines mechanisms for qualifying the names so as to eliminate ambiguity. That lets you write programs that use information from other sources and do the right things with it.</p><a name="wp64146"> </a><p class="pBody">The latest information on namespaces can be found at <code class="cCode"><a href="http://www.w3.org/TR/REC-xml-names" target="_blank">http://www.w3.org/TR/REC-xml-names</a></code>.</p><a name="wp64148"> </a><h4 class="pHeading3">XSL</h4><a name="wp64149"> </a><p class="pBody">Extensible Stylesheet Language</p><a name="wp64150"> </a><p class="pBody">The XML standard specifies how to identify data, not how to display it. HTML, on the other hand, told how things should be displayed without identifying what they were. The XSL standard has two parts, XSLT (the transformation standard, described next) and XSL-FO (the part that covers <span style="font-style: italic">formatting objects</span>, also known as <span style="font-style: italic">flow objects</span>). XSL-FO gives you the ability to define multiple areas on a page and then link them together. When a text stream is directed at the collection, it fills the first area and then "flows" into the second when the first area is filled. Such objects are used by newsletters, catalogs, and periodical publications. </p><a name="wp64151"> </a><p class="pBody">The latest W3C work on XSL is at <code class="cCode"><a href="http://www.w3.org/TR/WD-xsl" target="_blank">http://www.w3.org/TR/WD-xsl</a></code>. </p><a name="wp64153"> </a><h4 class="pHeading3">XSLT (+XPATH)</h4><a name="wp64154"> </a><p class="pBody">Extensible Stylesheet Language for Transformations</p><a name="wp64155"> </a><p class="pBody">The XSLT transformation standard is essentially a translation mechanism that lets you specify what to convert an XML tag into so that it can be displayed--for example, in HTML. Different XSL formats can then be used to display the same data in different ways, for different uses. (The XPATH standard is an addressing mechanism that you use when constructing transformation instructions, in order to specify the parts of the XML structure you want to transform.)</p><a name="wp71944"> </a><h3 class="pHeading2">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -