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

📄 introxml4.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 5 页
字号:
A space-separated list of names.</div></td></tr>  <tr align="left">    <td><a name="wp68170"> </a><div class="pCellBody"><code class="cCode">NOTATION</code></div></td>    <td><a name="wp68172"> </a><div class="pCellBody">The name of a DTD-specified notation, which describes a non-XML data format, such as those used for image files.* </div></td></tr></table></div><p class="pBody"></p><a name="wp68173"> </a><p class="pBody">*This is a rapidly obsolescing specification which will be discussed in greater length towards the end of this section.</p><a name="wp68175"> </a><p class="pBody">When the attribute type consists of a parenthesized list of choices separated by vertical bars, the attribute must use one of the specified values. For an example, add the text highlighted below to the DTD:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;!ELEMENT slide (title, item*)&gt;<code class="cCodeBold">&lt;!ATTLIST slide &nbsp;&nbsp;&nbsp;&nbsp;type   (tech | exec | all) #IMPLIED&gt;</code>&lt;!ELEMENT title (#PCDATA)&gt;&lt;!ELEMENT item (#PCDATA | item)* &gt;<a name="wp68176"> </a></pre></div><a name="wp68177"> </a><p class="pBody">This specification says that the <code class="cCode">slide</code> element's <code class="cCode">type</code> attribute must be given as <code class="cCode">type=&quot;tech&quot;</code>, <code class="cCode">type=&quot;exec&quot;</code>, or <code class="cCode">type=&quot;all&quot;</code>. No other values are acceptable. (DTD-aware XML editors can use such specifications to present a pop-up list of choices.) </p><a name="wp68178"> </a><p class="pBody">The last entry in the attribute specification determines the attributes default value, if any, and tells whether or not the attribute is required. <a  href="IntroXML4.html#wp68187">Table 2-4</a> shows the possible choices. </p><div align="left"><table border="1" summary="Attribute-Specification Parameters" id="wp68187">  <caption><a name="wp68187"> </a><div class="pTableTitle">Table 2-4   Attribute-Specification Parameters</div></caption>  <tr align="center">    <th><a name="wp68192"> </a><div class="pCellHeading">    Specification</div></th>    <th><a name="wp68194"> </a><div class="pCellHeading">Specifies...</div></th></tr>  <tr align="left">    <td><a name="wp68196"> </a><div class="pCellBody"><code class="cCode"> #REQUIRED</code></div></td>    <td><a name="wp68198"> </a><div class="pCellBody">The attribute value must be specified in the document.</div></td></tr>  <tr align="left">    <td><a name="wp68200"> </a><div class="pCellBody"><code class="cCode"> #IMPLIED</code></div></td>    <td><a name="wp68202"> </a><div class="pCellBody">The value need not be specified in the document. If it isn't, the application will have a default value it uses.</div></td></tr>  <tr align="left">    <td><a name="wp68204"> </a><div class="pCellBody"> &quot;defaultValue&quot;</div></td>    <td><a name="wp68206"> </a><div class="pCellBody">The default value to use, if a value is not specified in the document.</div></td></tr>  <tr align="left">    <td><a name="wp68208"> </a><div class="pCellBody"> <code class="cCode">#FIXED</code> &quot;fixedValue&quot;</div></td>    <td><a name="wp68210"> </a><div class="pCellBody">The value to use. If the document specifies any value at all, it must be the same. </div></td></tr></table></div><p class="pBody"></p><a name="wp68213"> </a><p class="pBody">Finally, save a copy of the DTD as <code class="cCode">slideshow1b.dtd</code>, for use when experimenting with attribute definitions.</p><a name="wp68562"> </a><h4 class="pHeading3">Defining Entities in the DTD</h4><a name="wp68214"> </a><p class="pBody">So far, you've seen predefined entities like <code class="cCode">&amp;amp;</code> and you've seen that an attribute can reference an entity. It's time now for you to learn how to define entities of your own.</p><hr><a name="wp68216"> </a><p class="pNote">Note: The XML you'll create here is contained in <code class="cCode"><a  href="../examples/xml/samples/slideSample06.xml" target="_blank">slideSample06.xml</a></code>. (The browsable version is <code class="cCode"><a  href="../examples/xml/samples/slideSample06-xml.html" target="_blank">slideSample06-xml.html</a></code>.)</p><hr><a name="wp68220"> </a><p class="pBody">Add the text highlighted below to the <code class="cCode">DOCTYPE</code> tag in your XML file:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;!DOCTYPE slideshow SYSTEM &quot;slideshow.dtd&quot; [<code class="cCodeBold">&nbsp;&nbsp;&lt;!ENTITY product  &quot;WonderWidget&quot;&gt;&nbsp;&nbsp;&lt;!ENTITY products &quot;WonderWidgets&quot;&gt;]</code>&gt;<a name="wp68221"> </a></pre></div><a name="wp68222"> </a><p class="pBody">The <code class="cCode">ENTITY</code> tag name says that you are defining an entity. Next comes the name of the entity and its definition. In this case, you are defining an entity named &quot;product&quot; that will take the place of the product name. Later when the product name changes (as it most certainly will), you will only have to change the name one place, and all your slides will reflect the new value. </p><a name="wp68223"> </a><p class="pBody">The last part is the substitution string that replaces the entity name whenever it is referenced in the XML document. The substitution string is defined in quotes, which are not included when the text is inserted into the document.</p><a name="wp68224"> </a><p class="pBody">Just for good measure, we defined two versions, one singular and one plural, so that when the marketing mavens come up with &quot;Wally&quot; for a product name, you will be prepared to enter the plural as &quot;Wallies&quot; and have it substituted correctly.</p><hr><a name="wp68225"> </a><p class="pNote">Note: Truth be told, this is the kind of thing that really belongs in an external DTD. That way, all your documents can reference the new name when it changes. But, hey, this is an example...</p><hr><a name="wp68226"> </a><p class="pBody">Now that you have the entities defined, the next step is to reference them in the slide show. Make the changes highlighted below to do that:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;slideshow &nbsp;&nbsp;title=&quot;<span style="text-decoration: line-through">WonderWidget</span><code class="cCodeBold">&amp;product;</code> Slide Show&quot; &nbsp;&nbsp;...<a name="wp68227"> </a>&nbsp;&nbsp;&lt;!-- TITLE SLIDE --&gt;&nbsp;&nbsp;&lt;slide type=&quot;all&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Wake up to <span style="text-decoration: line-through">WonderWidgets</span><code class="cCodeBold">&amp;products;</code>!&lt;/title&gt;&nbsp;&nbsp;&lt;/slide&gt;<a name="wp68228"> </a>&nbsp;&nbsp; &lt;!-- OVERVIEW --&gt;&nbsp;&nbsp;&lt;slide type=&quot;all&quot;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;title&gt;Overview&lt;/title&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;item&gt;Why &lt;em&gt;<span style="text-decoration: line-through">WonderWidgets</span><code class="cCodeBold">&amp;products;</code>&lt;/em&gt; are great&lt;/item&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;item/&gt;&nbsp;&nbsp;&nbsp;&nbsp;&lt;item&gt;Who &lt;em&gt;buys&lt;/em&gt; <span style="text-decoration: line-through">WonderWidgets</span><code class="cCodeBold">&amp;products;</code>&lt;/item&gt;&nbsp;&nbsp;&lt;/slide&gt;<a name="wp68229"> </a></pre></div><a name="wp68230"> </a><p class="pBody">The points to notice here are that entities you define are referenced with the same syntax (<code class="cCode">&amp;entityName;</code>) that you use for predefined entities, and that the entity can be referenced in an attribute value as well as in an element's contents.</p><a name="wp68232"> </a><p class="pBody">When you echo this version of the file with an XML parser, here is the kind of thing you'll see:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">Wake up to <code class="cCodeBold">WonderWidgets</code>!<a name="wp68233"> </a></pre></div><a name="wp68234"> </a><p class="pBody">Note that the product name has been substituted for the entity reference.</p><a name="wp68595"> </a><p class="pBody">To finish, save a copy of the file as <code class="cCode">slideSample06.xml</code>.</p><a name="wp68237"> </a><h4 class="pHeading3">Additional Useful Entities</h4><a name="wp68238"> </a><p class="pBody">Here are several other examples for entity definitions that you might find useful when you write an XML document:    </p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;!ENTITY ldquo  &quot;&amp;#147;&quot;&gt; &lt;!-- Left Double Quote --&gt; &lt;!ENTITY rdquo  &quot;&amp;#148;&quot;&gt; &lt;!-- Right Double Quote --&gt;&lt;!ENTITY trade  &quot;&amp;#153;&quot;&gt; &lt;!-- Trademark Symbol (TM) --&gt;&lt;!ENTITY rtrade &quot;&amp;#174;&quot;&gt; &lt;!-- Registered Trademark (R) --&gt;&lt;!ENTITY copyr  &quot;&amp;#169;&quot;&gt; &lt;!-- Copyright Symbol --&gt; <a name="wp68239"> </a></pre></div><a name="wp68241"> </a><h4 class="pHeading3">Referencing External Entities</h4><a name="wp68242"> </a><p class="pBody">You can also use the <code class="cCode">SYSTEM</code> or <code class="cCode">PUBLIC</code> identifier to name an entity that is defined in an external file. You'll do that now.</p><hr><a name="wp68605"> </a><p class="pNote">Note: The XML defined here is contained in <code class="cCode"><a  href="../examples/xml/samples/slideSample07.xml" target="_blank">slideSample07.xml</a></code> and in <code class="cCode"><a  href="../examples/xml/samples/copyright.xml" target="_blank">copyright.xml</a></code>. (The browsable versions are <code class="cCode"><a  href="../examples/xml/samples/slideSample07-xml.html" target="_blank">slideSample07-xml.html</a></code> and <code class="cCode"><a  href="../examples/xml/samples/copyright-xml.html" target="_blank">copyright-xml.html</a></code>.)</p><hr><a name="wp68250"> </a><p class="pBody">To reference an external entity, add the text highlighted below to the <code class="cCode">DOCTYPE</code> statement in your XML file:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;!DOCTYPE slideshow SYSTEM &quot;slideshow.dtd&quot; [&nbsp;&nbsp;&lt;!ENTITY product  &quot;WonderWidget&quot;&gt;&nbsp;&nbsp;&lt;!ENTITY products &quot;WonderWidgets&quot;&gt;&nbsp;&nbsp;<code class="cCodeBold">&lt;!ENTITY copyright SYSTEM &quot;copyright.xml&quot;&gt;</code>]&gt;<a name="wp68251"> </a></pre></div><a name="wp68625"> </a><p class="pBody">This definition references a copyright message contained in a file named <code class="cCode">copyright.xml</code>. Create that file and put some interesting text in it, perhaps something like this: </p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">  &lt;!--  A SAMPLE copyright  --&gt;<a name="wp68253"> </a>This is the standard copyright message that our lawyersmake us put everywhere so we don&#39;t have to shell out amillion bucks every time someone spills hot coffee in theirlap...<a name="wp68254"> </a></pre></div><a name="wp68629"> </a><p class="pBody">Finally, add the text highlighted below to your <code class="cCode">slideSample.xml</code> file to reference the external entity, and save a copy of the file as <code class="cCode">slideSample07.html</code>:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">&lt;!-- TITLE SLIDE --&gt;&nbsp;&nbsp;...&lt;/slide&gt;<a name="wp68256"> </a><code class="cCod

⌨️ 快捷键说明

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