xml-d~ix.htm

来自「这是一本关于XML的学习的书」· HTM 代码 · 共 811 行 · 第 1/5 页

HTM
811
字号
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="city" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="state" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="zip" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;/ElementType&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="name" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="street" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="city" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="state" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="zip" 
            dt:type="number" /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="orderDate" 
            dt:type="date" /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="shipDate" 
            dt:type="date" /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="comments" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="items"&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="Item" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;/ElementType&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="Item"&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="product" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="quantity" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="price" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;/ElementType&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="product" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="quantity" 
            dt:type="int" /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="price" 
            dt:type="fixed.14.4" /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;/schema&gt;</FONT></P>
        </LI></DIR>
      <P align=left><span class="normal105">出现最少和最多次数</span></P>
      <P><span class="normal105"><FONT size=2 class="normal105">如果你仔细看上面的大纲,你会看到在items中只允许出现一个<I>Item</I> 
        .我们要允许顾客一次能订多于一项定单,就要这样标明: </FONT></span></P>
      <DIR>
        <LI><FONT face="Courier New" size=1 class="normal105">&lt;element type="Item" 
          maxOccurs="*" /&gt; </FONT></LI>
      </DIR>
      <P><FONT size=2><I><span class="nocolor"><span class="normal105"><span class="normal105">maxOccurs<span class="normal105">属性是一个限制规则</span></span></span></span></I><span class="normal105"><span class="normal105"><span class="nocolor">,<span class="normal105">表示可以出现不止一个但必须是有限个</span> 
        "<span class="normal105">Item</span>"<span class="normal105">元素.maxOccurs的有效值为 
        "1" 和 "*".同样,你可以用<I>minOccurs</I>规定最少次数.例如,你能设置minOccurs为"0"使得一个子元素是可选择的.minOccurs缺省值为1.maxOccurs也为‘1’,除非当content="mixed"时它为"*".最小和最大值都为1.</span></span></span></span></FONT></P>
      <P><FONT size=2><span class="normal105"><span class="normal105">这些属性不仅可以用于元素(element</span>)<span class="normal105">还适用于组声明</span>(<I class="normal105">group</I> 
        <span class="normal105">declarations</span>).</span></FONT><span class="normal105"><FONT face=Arial> 
        </FONT></span></P>
      <P class="normal105">内容</P>
      <P><FONT 
      size=2 class="normal105">一个元素可以包括简单的文字,其它简单的元素,文本和元素的混合或空.我们可以通过使用内容(content)属性来规定.假设我们想表明一个元素仅包括文本而不含子元素.我们可以这样说明</FONT></P>
      <DIR>
        <LI><FONT face="Courier New" size=1><span class="normal105">&lt;ElementType 
          name="street" content="textOnly" /&gt;</span></FONT><span class="normal105"><FONT size=2> 
          </FONT></span></LI>
      </DIR>
      <P><FONT size=2 class="normal105">相反的极端情况,我们可以限制一个元素仅包含子元素:</FONT></P>
      <DIR>
        <LI><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="PurchaseOrder" 
          content="eltOnly" /&gt;</FONT> </LI>
      </DIR>
      <P><FONT size=2 class="normal105">content值为"empty"表示不允许有文本或子元素;值为"mixed"允许两者混合.</FONT></P>
      <P><FONT 
      size=2><span class="normal105">如果<span class="normal105">ElementType也有规定的数据类型(比如日期,数字等)那么不必明确说明其内容值暗指</span>"<span class="normal105">textOnly</span>"(<span class="normal105">纯文本</span>).</span></FONT><span class="normal105"><FONT 
      face=Arial> </FONT></span></P>
      <P class="normal105">顺序</P>
      <P><FONT 
      size=2 class="normal105">如果子元素必须以一定顺序出现,或集合中仅能出现一个,可以用顺序属性来表示.要明确地表明在大纲中所列的子元素必须按序出现,使order属性为"seq"值</FONT></P>
      <DIR>
        <LI><span class="normal105"><FONT face="Courier New" size=1><span class="normal105">&lt;ElementType 
          name="PurchaseOrder" order="seq"&gt;</span></FONT><span class="normal105"><FONT size=2> 
          </FONT></span></span></LI>
      </DIR>
      <P><FONT 
      size=2 class="normal105">如果想要假定一个元素可以是从数个子元素中选出,使用的值为"one".例如,如果一个<I>Item</I>元素可以包括product元素或者backOrderedProduct元素,但不是两者同时,必须这样写</FONT></P>
      <DIR>
        <LI><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="Item" 
          order="one"&gt;</FONT> 
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="product" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="backOrderedProduct"<span class="normal105"> 
            /&gt;</span></FONT></P>
          <P><FONT face="Courier New" size=1><span class="normal105">&lt;/ElementType&gt;</span></FONT><span class="normal105"><FONT 
      size=2> </FONT></span></P>
        </LI></DIR>
      <P><FONT size=2><EM class="normal105">order</EM><span class="normal105">元素的第三个通常值为</span>"<span class="normal105">many</span>"<span class="normal105">,表示子元素可以以任意顺序任意数量出现. 
        </span></FONT></P>
      <P><FONT 
      size=2><span class="normal105">如果没有声明一个元素的内容模型的顺序,缺省值为:当</span><EM class="normal105">content</EM><span class="normal105">属性值为"<span class="normal105">eltOnly</span>"时</span><EM class="normal105">order</EM><span class="normal105">为"<span class="normal105">seq"</span>,当</span><EM class="normal105">content</EM><span class="normal105">属性值为</span>"<span class="normal105">mixed</span>"<span class="normal105">时为</span>"<span class="normal105">many</span>".</FONT><FONT 
      face=Arial> </FONT></P>
      <P><span class="normal105">分组<FONT size=2> </FONT></span></P>
      <P><FONT 
      size=2 class="normal105">有时限制不对元素的所有子元素适用,而只是其中的一些.要标明之,我们使用分组(<EM>group</EM>)元素.例如, 
        要标明<EM>Item</EM>元素有一个<I>product</I>或<I>backOrderedProduct</I>元素,以及<I>quantity</I>和<I>price</I>元素,应该这样写</FONT></P>
      <DIR>
        <LI><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="Item"&gt;</FONT> 
          <P><FONT face="Courier New" size=1 class="normal105">&lt;group order="one"&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="product" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="backOrderedProduct" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;/group&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="quantity"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="price"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1><span class="normal105">&lt;/ElementType&gt;</span></FONT><span class="normal105"><FONT 
      size=2> </FONT></span></P>
        </LI></DIR>
      <P><FONT size=2><span class="normal105">在一个分组元素中,可以置</span><I class="normal105">order</I>, 
        <I class="normal105">minOccurs</I><span class="normal105">和</span><I class="normal105">maxOccurs</I><span class="normal105"> 
        属性来控制所包含元素出现的顺序和数量.</span></FONT></P>
      <P><span class="normal105">开放和封闭的内容模型</span></P>
      <P><FONT 
      size=2 class="normal105">有些情况下,我们想要设置一个元素包含的最低需求.比如,我们假设一个定单(PurchaseOrder)必须至少有下列的直接子元素: 
        <I>shipTo, orderDate, shipDate, comments</I>和<I>Items</I>. 而且,其他的子元素也可以同时出现. 
        (可能有其他人会发明其他的有用项—当讨论名域空间(namespace)的时候我们将涉及.)设置model的属性值为"open" 时允许有其他子元素</FONT></P>
      <DIR>
        <LI><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="PurchaseOrder" 
          model="open"&gt;</FONT> 
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="shipTo"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="orderDate"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="shipDate"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="comments" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="Items"/&gt;</FONT></P>
          <P><FONT face="Courier New" 
      size=1 class="normal105">&lt;/ElementType&gt;</FONT></P>
        </LI></DIR>
      <P><FONT size=2><span class="normal105">缺省情况下,在XML-Data</span><span class="normal105">中内容模型是开放的. 
        </span> </FONT></P>
      <P><FONT 
      size=2><span class="normal105">当然,相反的情况是"封闭的</span>(<span class="normal105">closed)".<span class="normal105">不管元素的内容是"</span>eltOnly</span>"<span class="normal105">或</span>"<span class="normal105">mixed</span>",<span class="normal105">我们都能通过模型属性为</span>"<span class="normal105">closed</span>"<span class="normal105">来限制其只能包含列出的属性或子元素</span>.</FONT></P>
      <DIR>
        <LI><FONT face="Courier New" size=1 class="normal105">&lt;ElementType 
          name="PurchaseOrder" model="closed"&gt;</FONT> 
          <P><FONT face="Courier New" size=1><span class="normal105">&lt;element 
            type="shipTo"/&gt;</span></FONT></P>
          <P><span class="normal105"><FONT face="Courier New" size=1 class="normal105">&lt;element 
            type="orderDate"/&gt;</FONT></span></P>
          <P><span class="normal105"><FONT face="Courier New" size=1 class="normal105">&lt;element 
            type="shipDate"/&gt;</FONT></span></P>
          <P><span class="normal105"><FONT face="Courier New" size=1 class="normal105">&lt;element 
            type="comments" /&gt;</FONT></span></P>
          <P><span class="normal105"><FONT face="Courier New" size=1 class="normal105">&lt;element 
            type="Items"/&gt;</FONT></span></P>
          <P><span class="normal105"><FONT face="Courier New" size=1><span class="normal105">&lt;/ElementType&gt;</span></FONT><span class="normal105"><FONT 
      face=Arial> </FONT></span></span></P>
          <P><span class="normal9"><span class="normal105">总结</span></span></P>
          <P><span class="normal105"><span class="normal9"><FONT size=2>如果我们采用以上的所有观点并把它们添加到初始的大纲中,能得到</FONT><FONT size=1> 
            </FONT></span></span><FONT size=1> </FONT></P>
          <P><FONT face="Courier New" size=1><span class="normal105">&lt;schema xmlns="urn:schema-microsoft-com:xml-data"</span></FONT></P>
          <P><span class="normal105"><FONT face="Courier New" 
      size=1 class="normal105">xmlns:dt="urn:schema-microsoft-com:datatypes"&gt;</FONT></span></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="PurchaseOrder" 
            content="eltOnly" &gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="shipTo"/&gt;</FONT></P>

⌨️ 快捷键说明

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