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

📄 jaxpdom5.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 2 页
字号:
&nbsp;&nbsp;...&nbsp;&nbsp;DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();&nbsp;&nbsp;<code class="cCodeBold">factory.setExpandEntityReferences(false);</code>&nbsp;&nbsp;...<a name="wp75882"> </a></pre></div><a name="wp75878"> </a><p class="pBody"></p><div align="left"><img src="images/pd-210e25.gif" height="285" width="447" alt="JAXP 1.1 in 1.4 Platform -- Entity Reference Node Displayed" border="0" hspace="0" vspace="0"/></div><p class="pBody"></p><p>  <a name="64649"> </a><strong><font >Figure 6-6    JAXP 1.1 in 1.4 Platform-- Entity Reference Node Displayed</font></strong></p><a name="wp64650"> </a><p class="pBody">Here, the Entity Reference node is highlighted. Note that the entity reference contains multiple nodes under it. This example shows only comment and a text nodes, but the entity could conceivably contain other element nodes, as well.</p><a name="wp64651"> </a><p class="pBody">Finally, moving down to the last <code class="cCode">item</code> element under the last <code class="cCode">slide</code> brings up the display shown in <a  href="JAXPDOM5.html#wp64660">Figure 6-7</a>.</p><a name="wp64658"> </a><p class="pBody"></p><div align="left"><img src="images/pd-210f6.gif" height="284" width="447" alt="CDATA Node Displayed" border="0" hspace="0" vspace="0"/></div><p class="pBody"></p><p>  <a name="64660"> </a><strong><font >Figure 6-7    CDATA Node Displayed</font></strong></p><a name="wp64661"> </a><p class="pBody">Here, the <code class="cCode">CDATA</code> node is highlighted. Note that there are no nodes under it. Since a <code class="cCode">CDATA</code> section is entirely uninterpreted, all of its contents are contained in the node's <code class="cCode">value</code> property.</p><a name="wp75940"> </a><h4 class="pHeading3">Summary of Lexical Controls</h4><a name="wp75944"> </a><p class="pBody"><span style="font-style: italic">Lexical information</span> is the information you need to reconstruct the original syntax of an XML document. As we discussed earlier, preserving lexical information is important for editing applications, where you want to save a document that is an accurate reflection of the original--complete with comments, entity references, and any CDATA sections it may have included at the outset.</p><a name="wp75970"> </a><p class="pBody">A majority of applications, however, are only concerned with the content of the XML structures. They can afford to ignore comments, and they don't care whether data was coded in a CDATA section, as plain text, or whether it included an entity reference. For such applications, a minimum of lexical information is desirable, because it simplifies the number and kind of DOM nodes that the application has to be prepared to examine.</p><a name="wp75976"> </a><p class="pBody">The following <code class="cCode">DocumentBuilderFactory</code> methods give you control over the lexical information you see in the DOM:</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp76075"> </a><div class="pSmartList1"><li><code class="cCode">setCoalescing()</code></li></div><a name="wp78705"> </a><p class="pBodyRelative">To convert CDATA nodes to Text node and append to an adjacent Text node (if any).</p><a name="wp76079"> </a><div class="pSmartList1"><li><code class="cCode">setExpandEntityReferences()</code></li></div><a name="wp78709"> </a><p class="pBodyRelative">To expand entity reference nodes.</p><a name="wp76082"> </a><div class="pSmartList1"><li><code class="cCode">setIgnoringComments()</code></li></div><a name="wp78745"> </a><p class="pBodyRelative">To ignore comments.</p><a name="wp76085"> </a><div class="pSmartList1"><li><code class="cCode">setIgnoringElementContentWhitespace()</code></li></div><a name="wp78713"> </a><p class="pBodyRelative">To ignore whitespace that is not a significant part of element content.</p></ul></div><a name="wp76238"> </a><p class="pBody">The default values for all of these properties is <code class="cCode">false</code>, which preserves all the lexical information necessary to reconstruct the incoming document in its original form. Setting them to true lets you construct the simplest possible DOM, so the application can focus on the data's semantic content, without having to worry about lexical syntax details. <a  href="JAXPDOM5.html#wp79323">Table 6-2</a> summarizes the effect of the settings.</p><div align="left"><table border="1" summary="Configuring DocumentBuilderFactory" id="wp79323">  <caption><a name="wp79323"> </a><div class="pTableTitle">Table 6-2   Configuring DocumentBuilderFactory</div></caption>  <tr align="center">    <th><a name="wp79329"> </a><div class="pCellHeading">API</div></th>    <th><a name="wp79331"> </a><div class="pCellHeading">Preserve Lexical Info</div></th>    <th><a name="wp79333"> </a><div class="pCellHeading">Focus on Content</div></th></tr>  <tr align="left">    <td><a name="wp79335"> </a><div class="pCellBody"><code class="cCode">setCoalescing()</code></div></td>    <td><a name="wp79337"> </a><div class="pCellBody">false</div></td>    <td><a name="wp79339"> </a><div class="pCellBody">true</div></td></tr>  <tr align="left">    <td><a name="wp79341"> </a><div class="pCellBody"><code class="cCode">setExpandEntityReferences()</code></div></td>    <td><a name="wp79343"> </a><div class="pCellBody">false</div></td>    <td><a name="wp79345"> </a><div class="pCellBody">true</div></td></tr>  <tr align="left">    <td><a name="wp79347"> </a><div class="pCellBody"><code class="cCode">setIgnoringComments()</code></div></td>    <td><a name="wp79349"> </a><div class="pCellBody">false</div></td>    <td><a name="wp79351"> </a><div class="pCellBody">true</div></td></tr>  <tr align="left">    <td><a name="wp79353"> </a><div class="pCellBody"><code class="cCode">setIgnoringElement<br />&nbsp;&nbsp;&nbsp;&nbsp;ContentWhitespace()</code></div></td>    <td><a name="wp79355"> </a><div class="pCellBody">false</div></td>    <td><a name="wp79357"> </a><div class="pCellBody">true</div></td></tr></table></div><p class="pBody"></p><a name="wp64663"> </a><h3 class="pHeading2">Finishing Up </h3><a name="wp64664"> </a><p class="pBody">At this point, you have seen most of the nodes you will ever encounter in a DOM tree. There are one or two more that we'll mention in the next section, but you now know what you need to know to create or modify a DOM structure. In the next section, you'll see how to convert a DOM into a <code class="cCode">JTree</code> that is suitable for an interactive GUI. Or, if you prefer, you can skip ahead to the 5th section of the DOM tutorial, <a  href="JAXPDOM7.html#wp65002">Creating and Manipulating a DOM</a>, where you'll learn how to create a DOM from scratch. </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="JAXPDOM4.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="JAXPDOM6.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 + -