xml-d~ix.htm

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

HTM
811 行
字号
          <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>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="shipTo" 
            content="eltOnly" /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="name" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="street" 
            /&gt;</FONT></P>
          <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" 
            content="textOnly" /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="street" 
            content="textOnly" /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="city" 
            content="textOnly" /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="state" 
            content="textOnly" /&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" minOccurs="0" /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="comments" 
            minOccurs="0" content="textOnly" /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="items" 
            model="closed"&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="Item" 
            maxOccurs="*"/&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;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 class="normal105">&lt;/ElementType&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="product" 
            content="textOnly" /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;ElementType name="backOrderedProduct" 
            content="textOnly" /&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><span class="normal105">&lt;/schema&gt;</span></FONT><span class="normal105"><FONT size=2> 
            </FONT></span><FONT size=2> </FONT></P>
        </LI></DIR>
      <P><B><I class="normal105">名域</I></B></P>
      <P><FONT 
      size=2 class="normal105">能从标准部分中建立子定义的大纲,例如我们的定货单,将是件很不错的事.譬如,假设有他人已经定义了一个我们需要用于<EM>shipTo</EM>元素的<I>Address元素</I>.我们将在PurchaseOrder定单中直接使用,不是只照抄<I>Address</I>元素的定义,而是索引原定义使使用和初始一致."名域"将助我们一臂之力. 
        </FONT></P>
      <P><FONT 
      size=2 class="normal105">要吟咏在另一大纲中定义的元素,我们得做两件事.首先,我们使用名域声明来引出另一大纲.该声明包括一个以"xmlns:"开头的属性,其后是可选择的前缀名,最后是另一大纲的统一资源标识符,Universal 
        Resource Identifier (简称URI).</FONT></P>
      <DIR>
        <LI><FONT face="Courier New" size=1><span class="normal105">&lt;ElementType 
          name="PurchaseOrder"</span><BR>
          <span class="normal105">xmlns:abcde="http://electrocommerce.org/stuff.xml" 
          &gt;</span></FONT><span class="normal105"><FONT size=2> </FONT></span></LI>
      </DIR>
      <P><FONT 
      size=2 class="normal105">这里我们介绍了URI为"http://electrocommerce.org/stuff.xml"的大纲并给出前缀"abcde".URI明确表明另一大纲;前缀是我们在本地引用该名域的局部名称.完成之后,我们就可以在那个大纲中引用该元素,就象是我们自己定义的元素.如果另一个大纲有合适的shipTo元素被定义,我们可以这样写来使用</FONT></P>
      <DIR>
        <LI><FONT face="Courier New" size=1><span class="normal105">&lt;ElementType 
          name="shipTo"</span><BR>
          <span class="normal105">xmlns:abcde="http://electrocommerce.org/stuff.xml" 
          &gt;</span><BR>
          <span class="normal105">&lt;element type="abcde:Address"/&gt;</span><BR>
          <span class="normal105">&lt;/ElementType&gt;</span></FONT><span class="normal105"><FONT size=2> 
          </FONT></span><FONT size=2> </FONT></LI>
      </DIR>
      <P><FONT 
      size=2 class="normal105">在第一个子元素的类型(type)属性中,我们发现了值"abcde:Address".前缀"abcde"这里与嵌套名域声明相匹配,这样"abcde:Address"意指"由http://electrocommerce.org/stuff.xml中的大纲定义的Address元素".</FONT></P>
      <P><FONT size=2 class="normal105">而且,这对我们的定货单文档产生了影响: 我们也要引用另一大纲名域.</FONT></P>
      <DIR> 
        <LI><FONT face="Courier New" size=1 class="normal105">&lt;PurchaseOrder 
          xmlns:abcde="http://electrocommerce.org/stuff.xml"&gt;</FONT> 
          <P><FONT face="Courier New" size=1 class="normal105">&lt;shipTo&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;abcde:Address&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;abcde:name&gt;Alice 
            Smith&lt;/abcde:name&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;abcde:street&gt;123 
            Maple Street&lt;/abcde:street&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;abcde:city&gt;Mill 
            Valley&lt;/abcde:city&gt;</FONT></P>
          <P><FONT face="Courier New" 
      size=1 class="normal105">&lt;abcde:state&gt;CA&lt;/abcde:state&gt;</FONT></P>
          <P><FONT face="Courier New" 
      size=1><span class="normal105">&lt;abcde:zip&gt;90952&lt;/abcde:zip&gt;</span><BR>
            <span class="normal105">&lt;/abcde:Address&gt;</span></FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;/shipTo&gt;</FONT></P>
          <P><FONT face="Courier New" 
      size=1 class="normal105">&lt;orderDate&gt;1999-05-20&lt;/orderDate&gt;</FONT></P>
          <P><FONT face="Courier New" 
      size=1 class="normal105">&lt;shipDate&gt;1999-05-25&lt;/shipDate&gt;</FONT></P>
          <P><FONT face="Courier New" size=1><span class="normal105">&lt;comments&gt;</span><BR>
            <span class="normal105">Get these things to me in a hurry, my lawn 
            is going wild!</span><BR>
            <span class="normal105">&lt;/comments&gt;</span></FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;Items&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;Item&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;productName&gt;Lawnmower, 
            model BUZZ-1&lt;/productName&gt;</FONT></P>
          <P><FONT face="Courier New" 
      size=1 class="normal105">&lt;quantity&gt;1&lt;/quantity&gt;</FONT></P>
          <P><FONT face="Courier New" 
      size=1 class="normal105">&lt;price&gt;148.95&lt;/price&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;/Item&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;Item&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;productName&gt;Baby 
            Monitor, model SNOOZE-2&lt;/productName&gt;</FONT></P>
          <P><FONT face="Courier New" 
      size=1 class="normal105">&lt;quantity&gt;1&lt;/quantity&gt;</FONT></P>
          <P><FONT face="Courier New" 
      size=1 class="normal105">&lt;price&gt;39.98&lt;/price&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;/Item&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;/Items&gt;</FONT></P>
          <P><FONT face="Courier New" size=1><span class="normal105">&lt;/PurchaseOrder&gt;</span></FONT><span class="normal105"><FONT 
      size=2> </FONT></span></P>
        </LI>
      </DIR>
      <P><FONT size=2 class="normal105">在阅读该文档实例的任何人,甚至是并不理解我们 "定货单"的意思的人都能够判断<I>Address</I> 
        元素是由"http://electrocommerce.org/stuff.xml"处的大纲定义的. 如果我们能从更被广泛理解、标准部分中(如地址Address元素)中构建专业化大纲(如我们的定货单PurchaseOrder),那么那些专业文档部分可以由标准软件模块来处理.例如, 
        如果我们已经有了用于"由http://electrocommerce.org/stuff.xml定义的Address元素"的XSL样式表,我们在任何这样的地址元素出现处重用该通用地址样式代码.我们几乎是免费得到定货单地址的格式.</FONT></P>
      <P><FONT size=2 class="normal105">我们在大纲和文档实例中使用同样的前缀.但我们不是非这样不可. 因为前缀是名域URI的唯一局部别名, 
        我们可以在文档实例中使用任何我们喜欢的前缀.我们所有要做的是:在一个文档中,在声明名域和由该名域使用元素时采用相同的前缀.</FONT></P>
      <DIR>
        <LI><FONT face="Courier New" size=1 class="normal105">&lt;PurchaseOrder 
          xmlns:z="http://electrocommerce.org/stuff.xml"&gt;</FONT> 
          <P><FONT face="Courier New" size=1 class="normal105">&lt;shipTo&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;z:Address&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;z:name&gt;Alice 
            Smith&lt;/z:name&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;z:street&gt;123 
            Maple Street&lt;/z:street&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;z:city&gt;Mill 
            Valley&lt;/z:city&gt;</FONT></P>
          <P><FONT face="Courier New" 
      size=1 class="normal105">&lt;z:state&gt;CA&lt;/z:state&gt;</FONT></P>
          <P><FONT face="Courier New" 
      size=1><span class="normal105">&lt;z:zip&gt;90952&lt;/z:zip&gt;</span><BR>
            <span class="normal105">&lt;/z:Address&gt;</span></FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;/shipTo&gt;</FONT></P>
          <P><FONT size=1 class="normal105">…</FONT></P>
        </LI></DIR>
      <P><FONT 
      size=2 class="normal105">名域的声明限于其出现的元素.它使得名域前缀有效并与URI相结合.因此声明不必在PurchaseOrder元素中出现,因为我们只用另一名域代表Address元素,它可以在那儿直接出现.</FONT></P>

⌨️ 快捷键说明

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