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

📄 4_design.html

📁 XML_JAVA指南 书籍语言: 简体中文 书籍类型: 程序设计 授权方式: 免费软件 书籍大小: 377 KB
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><!--NewPage--><html><head><title>Designing an XML Data Structure</title><style type="text/css"><!----></style><meta name="fileID" content="quickIntro"><meta name="keywords" content="XML"></head><body BGCOLOR="#ffffff"><table width="100%">  <tr>     <td align=left> <a href="3_apis.html"><img src="../images/PreviousArrow.gif" width=26 height=26 align=bottom border=0 alt="Previous | "></a><ahref="index.html"><img src="../images/NextArrow.gif" width=26 height=26 align=bottom border=0 alt="Next | "></a><a href="../alphaIndex.html"><img src="../images/xml_IDX.gif" width=26 height=26 align=bottom border=0 alt="Index | "></a><a href="../TOC.html"><imgsrc="../images/xml_TOC.gif" width=26 height=26 align=bottom border=0 alt="TOC | "></a><a href="../index.html"><imgsrc="../images/xml_Top.gif" width=26 height=26 align=bottom border=0 alt="Top | "></a>     </td>    <td align=right><strong><em><a href="index.html">Top</a></em></strong> <a href="../TOC.html#intro"><strong><em>Contents</em></strong></a>       <a href="../alphaIndex.html"><strong><em>Index</em></strong></a> <a href="../glossary.html"><strong><em>Glossary</em></strong></a>     </td>  </tr></table><p>   <center>    <IMG SRC="../images/shoeline2.gif" ALIGN="BOTTOM" BORDER="0" WIDTH="202"    HEIGHT="25" NATURALSIZEFLAG="3"> <IMG SRC="../images/shoeline2.gif" ALIGN="BOTTOM" BORDER="0" WIDTH="202"    HEIGHT="25" NATURALSIZEFLAG="3">   </center><blockquote>   <blockquote>     <hr size=4>  </blockquote></blockquote><p> <h2> 4. Designing an XML Data Structure</h2><table width="40%" border="1" align="right">  <tr>     <td>       <div align="center"><b><i>Link Summary</i></b></div>    </td>  </tr>  <tr>     <td>       <dl>         <dt><b><i>Local Links</i></b></dt>      </dl>      <ul>        <li><a href="../sax/5c_dtd.html">Defining Attributes and Entities in the           DTD</a></li>      </ul>      <p><b><i>External Links</i></b></p>      <ul>        <li><a href="http://www.XML.org">http://www.XML.org</a></li>        <li><a href="http://www.xmlx.com">http://www.xmlx.com</a></li>        <li><a href="http://www.oasis-open.org/cover/elementsAndAttrs.html">http://www.oasis-open.org/cover/elementsAndAttrs.html</a><a href="http://www.w3.org/TR/WD-xsl"></a></li>      </ul>      <p><b><i>Glossary Terms</i></b></p>      <dl>         <dd><a href="../glossary.html#DTD">DTD</a>, <a href="../glossary.html#entity">entity</a>,           <a href="../glossary.html#externalEntity">external entity</a>, <a href="../glossary.html#parameterEntity">parameter           entity</a></dd>      </dl>    </td>  </tr></table><p> This page covers some heuristics you can use when making XML design decisions. <h3></h3><h3><a name="saveWork"></a>Saving Yourself Some Work </h3><p>Whenever possible, use an existing DTD. It's usually a lot easier to ignore   the things you don't need than to design your own from scratch. In addition,   using a standard DTD makes data interchange possible, and may make it possible   to use data-aware tools developed by others. <p>So, if an industry standard exists, consider referencing that DTD with an external   <a href="../glossary.html#parameterEntity">parameter entity</a>. One place to   look for industry-standard DTDs is at the repository created by the Organization   for the Advancement of Structured Information Standards (OASIS) at <a href="http://www.XML.org"><code>http://www.XML.org</code></a>.   Another place to check is CommerceOne's XML Exchange at <a href="http://www.xmlx.com"><code>http://www.xmlx.com</code></a>,   which is described as &quot;a repository for creating and sharing document type   definitions&quot;.</p><blockquote>   <p><b>Note: </b><br>    Many more good thoughts on the design of XML structures are at the OASIS page,     <a href="http://www.oasis-open.org/cover/elementsAndAttrs.html"><code>http://www.oasis-open.org/cover/elementsAndAttrs.html</code></a>.     If you have any favorite heuristics that can improve this page, please send     an email! For the address, see <a href="../info/inProgress.html">Work in Progress</a>.</p></blockquote><h3><a name="attributesAndElements"></a>Attributes and Elements</h3><p>One of the issues you will encounter frequently when designing an XML structure   is whether to model a given data item as a subelement or as an attribute of   an existing element. For example, you could model the title of a slide either   as:</p><blockquote>   <pre>&lt;slide&gt;  &lt;title&gt;This is the title&lt;/title&gt;&lt;/slide&gt;</pre></blockquote><p>or as:</p><blockquote>   <pre>&lt;slide title=&quot;This is the title&quot;&gt;...&lt;/slide&gt;</pre></blockquote><p>In some cases, the different characteristics of attributes and elements make   it easy to choose. Let's consider those cases first, and then move on to the   cases where the choice is more ambiguous.</p><h4><a name="forced"></a>Forced Choices</h4><p>Sometimes, the choice between an attribute and an element is forced on you   by the nature of attributes and elements. Let's look at a few of those considerations:</p><dl>   <dl>     <dt><b>The data contains substructures</b></dt>    <dd>In this case, the data item must be modeled as an <i>element</i>. It can't       be modeled as an attribute, because attributes take only simple strings.       So if the title can contain emphasized text like this: <code>The &lt;em&gt;Best&lt;/em&gt;       Choice</code>, then the title must be an element.</dd>    <dt>&nbsp;</dt>    <dt><b>The data contains multiple lines</b></dt>    <dd>Here, it also makes sense to use an <i>element</i>. Attributes need to       be simple, short strings or else they become unreadable, if not unusable.</dd>    <dt>&nbsp;</dt>    <dt> <b>The data changes frequently</b></dt>    <dd>When the data will be frequently modified, especially by the end user,       then it makes sense to model it as an <i>element</i>. XML-aware editors       tend to make it very easy to find and modify element data. Attributes can       be somewhat harder to get to, and therefore somewhat more difficult to modify.</dd>    <dt>&nbsp;</dt>    <dt><b>The data is a small, simple string that rarely if ever changes</b></dt>    <dd>This is data that can be modeled as an <i>attribute</i>. However, just       because you <i>can</i> does not mean that you should. Check the &quot;Stylistic       Choices&quot; section below, to be sure.</dd>    <dt>&nbsp;</dt>    <dt><b>The data is confined to a small number of fixed choices</b></dt>    <dd>Here is one time when it really makes sense to use an <i>attribute</i>.       Using the <a href="../glossary.html#DTD">DTD</a>, the attribute can be prevented       from taking on any value that is not in the preapproved list. An XML-aware       editor can even provide those choices in a drop-down list. Note, though,       that the gain in validity restriction comes at a cost in extensibility.       The author of the XML document cannot use any value that is not part of       the DTD. If another value becomes useful in the future, the DTD will have       to be modified before the document author can make use of it.</dd>  </dl></dl><h4><a name="style"></a>Stylistic Choices</h4><p>As often as not, the choices are not as cut and dried as those shown above.   When the choice is not forced, you need a sense of &quot;style&quot; to guide   your thinking. The question to answer, then, is what makes good XML style, and 

⌨️ 快捷键说明

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