xml-d~ix.htm

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

HTM
811 行
字号
      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="normal9">&lt;comments&gt;</span><BR>
            <span class="normal105">Get these things to me in a hurry, my lawn 
            is going wild!<BR>
            &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 class="normal105">&lt;trackingInformation 
            xmlns="http://somewhere.com/tracking.xml"&gt;</FONT></P>
          <P><FONT face="Courier New" 
      size=1 class="normal105">&lt;route&gt;1234-5678&lt;/route&gt;</FONT></P>
          <P><FONT face="Courier New" 
      size=1 class="normal105">&lt;signature&gt;32143912850-3959159=1395&lt;/signature&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;/trackingInformation&gt;</FONT></P>
          <P><FONT face="Courier New" 
      size=1 class="normal105">&lt;/PurchaseOrder&gt;</FONT></P>
        </LI></DIR>
      <P><FONT 
      size=2 class="normal105">因为我们要求任何未提及的属性或元素都要有名域限制,<I>trackingInformation</I>元素如果没有<EM>xmlns</EM>属性将是无效的</FONT></P>
      <P><B><I>属性</I></B></P>
      <P><FONT size=2 class="normal105">XML文档主要由元素和属性组成.目前为止,我们已经看到了信息完全用元素来表达的定货单(Purchase 
        Order).假设我们想要这样的文档:</FONT></P>
      <DIR>
        <LI><FONT face="Courier New" size=1 class="normal105">&lt;PurchaseOrder 
          xmlns="http://fabrikam.com/PO.xml"</FONT> 
          <P><FONT face="Courier New" size=1 class="normal105">orderDate="1999-05-20"</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">shipDate="1999-05-25"</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">comments=</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">"Get these things to 
            me in a hurry, my lawn is going wild!"</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">shipTo="Address-1"</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">items="Item-1 Item-2"</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;Address id="Address-1"</FONT></P>
          <P><FONT face="Courier New" 
      size=1 class="normal105">xmlns="http://electrocommerce.org/stuff.xml"</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">name="Alice Smith"</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">street="123 Maple Street"</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">city="Mill Valley"</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">state="CA"</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">zip="90952" /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;Item productName="Lawnmower, 
            model BUZZ-1"</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">quantity="1"</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">price="148.95" /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;Item productName="Baby 
            Monitor, model SNOOZE-2"</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">quantity="1"</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">price="39.98" /&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">这需要一个不同的大纲.(实际上,要求几个大纲间存在差异,因为我们将需要改变"http://fabrikam.com/PO.xml"和"http://electrocommerce.org/stuff.xml".)让我们来看以下修改后的PurchaseOrder大纲.</FONT></P>
      <DIR>
        <LI><FONT face="Courier New" size=1 class="normal105">&lt;schema xmlns="urn:schema-microsoft-com:xml-data"</FONT> 
          <P><FONT face="Courier New" 
      size=1 class="normal105">xmlns:dt="urn:schema-microsoft-com:datatypes"&gt;</FONT></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;AttributeType name="shipTo" 
            dt:type="idref"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;attribute type="shipTo"/&gt;&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;AttributeType name="shipTo" 
            dt:type="idref"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;attribute type="shipTo"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;AttributeType name="items" 
            dt:type="idrefs"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;attribute type="items" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;AttributeType name="orderDate" 
            dt:type="date"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;attribute type="orderDate"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;AttributeType name="shipDate" 
            dt:type="date"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;attribute type="shipDate"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;AttributeType name="comments" 
            dt:type="string"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;attribute type="comments" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="abcde:Address" 
            </FONT></P>
          <P><FONT face="Courier New" 
      size=1 class="normal105">xmlns:abcde="http://electrocommerce.org/stuff.xml" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;element type="Items" 
            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;AttributeType name="id" 
            dt:type="id"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;attribute type="id" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;AttributeType name="product" 
            dt:type="string"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;attribute type="product" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;AttributeType name="quantity" 
            dt:type="int"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;attribute type="quantity" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;AttributeType name="price" 
            dt:type="fixed.14.4"/&gt;</FONT></P>
          <P><FONT face="Courier New" size=1 class="normal105">&lt;attribute type="price" 
            /&gt;</FONT></P>
          <P><FONT face="Courier New" size=1><span class="normal105">&lt;/ElementType&gt;</span></FONT></P>
          <P><span class="normal105"><FONT face="Courier New" size=1><span class="normal105">&lt;/schema&gt;</span></FONT><span class="normal105"><FONT size=2> 
            </FONT></span></span></P>
        </LI></DIR>
      <P><FONT size=2 class="normal105">属性类型用<I>AttributeType</I>元素声明:</FONT></P>
      <DIR>
        <LI><FONT face="Courier New" size=1><span class="normal105">&lt;AttributeType 
          name="shipTo" dt:type="idref"/&gt;</span></FONT> </LI>
      </DIR>
      <P><FONT size=2 class="normal105">然后用<EM>attribute</EM>元素来引用:</FONT></P>
      <DIR>
        <LI><FONT face="Courier New" size=1><span class="normal105">&lt;attribute 
          type="shipTo"/&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;AttributeType 
          name="shipTo" dt:type="idref"/&gt;</FONT> 
          <P><FONT face="Courier New" size=1><span class="normal105">&lt;attribute 
            type="shipTo"/&gt;</span></FONT><span class="normal105"><FONT size=2> 
            </FONT></span></P>
        </LI></DIR>
      <P><FONT size=2 class="normal105">类似与元素,属性也可能有数据类型.比如,shipTo元素的数据类型是"idref". 
        我们还没有讨论过该数据类型,以及其他两个相关的数据类型"id"和"idrefs."数据类型是"id"的属性在文档实例中保留有标识值,该值不会在出现在文档中任何其他的id属性中.An 
        attribute of type "idref"类型的属性是用匹配的id值来引用元素."Idrefs"类似"idref",但有一系列用空格分开的id值.例如</FONT></P>
      <DIR>
        <LI><span class="normal105"><FONT size=1 class="normal105">shipTo="Address-1"</FONT> 
          </span> 
          <P><span class="normal105"><FONT face="Courier New" size=1><span class="normal105">items="Item-1 
            Item-2"</span></FONT><span class="normal105"><FONT 
      size=2> </FONT></span></span></P>
        </LI></DIR>
      <P><FONT 
      size=2 class="normal105">在某些方面属性比元素更受限制.属性不能包含子元素.你不能要求属性一特殊的顺序出现,也不能指定两者择一("product"或"backOrderedProduct"). 
        你可以说明一个属性是必须的还是可选的,但在一个元素

⌨️ 快捷键说明

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