📄 jaxpintro5.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>The Document Object Model (DOM) APIs</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="JAXPIntro4.html" /> <link rel="Next" href="JAXPIntro6.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="JAXPIntro4.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="JAXPIntro6.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="wp64247"> </a><h2 class="pHeading1">The Document Object Model (DOM) APIs</h2><a name="wp64251"> </a><p class="pBody"><a href="JAXPIntro5.html#wp64257">Figure 4-2</a> shows the JAXP APIs in action:</p><a name="wp64647"> </a><p class="pBody"></p><div align="left"><img src="images/Fig5-22.gif" height="191" width="355" alt="DOM APIs: DocumentBuilderFactory creates a DocumentBuilder, which reads the XML data and creates a Document, or DOM." border="0" hspace="0" vspace="0"/></div><p class="pBody"></p><p> <a name="64257"> </a><strong><font >Figure 4-2 DOM APIs</font></strong></p><a name="wp64258"> </a><p class="pBody">You use the <code class="cCode">javax.xml.parsers.DocumentBuilderFactory</code> class to get a DocumentBuilder instance, and use that to produce a <code class="cCode">Document</code> (a DOM) that conforms to the DOM specification. The builder you get, in fact, is determined by the System property, <code class="cCode">javax.xml.parsers.DocumentBuilderFactory</code>, which selects the factory implementation that is used to produce the builder. (The platform's default value can be overridden from the command line.) </p><a name="wp64259"> </a><p class="pBody">You can also use the <code class="cCode">DocumentBuilder</code> <code class="cCode">newDocument()</code> method to create an empty <code class="cCode">Document</code> that implements the <code class="cCode">org.w3c.dom.Document</code> interface. Alternatively, you can use one of the builder's parse methods to create a <code class="cCode">Document</code> from existing XML data. The result is a DOM tree like that shown in the diagram.</p><hr><a name="wp64260"> </a><p class="pNote">Note: Although they are called objects, the entries in the DOM tree are actually fairly low-level data structures. For example, under every <span style="font-style: italic">element node</span> (which corresponds to an XML element) there is a <span style="font-style: italic">text node</span> which contains the name of the element tag! This issue will be explored at length in the DOM section of the tutorial, but users who are expecting objects are usually surprised to find that invoking the <code class="cCode">text()</code> method on an element object returns nothing! For a truly object-oriented tree, see the JDOM API at <code class="cCode">http://www.jdom.org</code>. </p><hr><a name="wp64262"> </a><h3 class="pHeading2">The DOM Packages</h3><a name="wp64263"> </a><p class="pBody">The Document Object Model implementation is defined in the packages listed in <a href="JAXPIntro5.html#wp64269">Table 4-2</a>.:</p><div align="left"><table border="1" summary="DOM Packages" id="wp64269"> <caption><a name="wp64269"> </a><div class="pTableTitle">Table 4-2 DOM Packages</div></caption> <tr align="center"> <th><a name="wp65994"> </a><div class="pCellHeading">Package</div></th> <th><a name="wp65996"> </a><div class="pCellHeading">Description</div></th></tr> <tr align="left"> <td><a name="wp64277"> </a><div class="pCellBody"><code class="cCode"> org.w3c.dom </code></div></td> <td><a name="wp64279"> </a><div class="pCellBody">Defines the DOM programming interfaces for XML (and, optionally, HTML) documents, as specified by the W3C.</div></td></tr> <tr align="left"> <td><a name="wp64281"> </a><div class="pCellBody"><code class="cCode"> javax.xml.parsers</code></div></td> <td><a name="wp64283"> </a><div class="pCellBody">Defines the <code class="cCode">DocumentBuilderFactory</code> class and the <code class="cCode">DocumentBuilder</code> class, which returns an object that implements the W3C Document interface. The factory that is used to create the builder is determined by the <code class="cCode">javax.xml.parsers</code> system property, which can be set from the command line or overridden when invoking the <code class="cCode">new Instance</code> method. This package also defines the <code class="cCode">ParserConfigurationException</code> class for reporting errors.</div></td></tr></table></div><p class="pBody"></p> </blockquote> <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"> <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="JAXPIntro4.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="JAXPIntro6.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"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -