xml-d~ix.htm
来自「这是一本关于XML的学习的书」· HTM 代码 · 共 811 行 · 第 1/5 页
HTM
811 行
<P><FONT face="Courier New" size=1 class="normal105"><element type="city"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="state"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="zip"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"></ElementType></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="name"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="street"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="city"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="state"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="zip"
dt:type="number" /></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="orderDate"
dt:type="date" /></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="shipDate"
dt:type="date" /></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="comments"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="items"></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="Item"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"></ElementType></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="Item"></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="product"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="quantity"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="price"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"></ElementType></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="product"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="quantity"
dt:type="int" /></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="price"
dt:type="fixed.14.4" /></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"></schema></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"><element type="Item"
maxOccurs="*" /> </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"><ElementType
name="street" content="textOnly" /></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"><ElementType name="PurchaseOrder"
content="eltOnly" /></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"><ElementType
name="PurchaseOrder" order="seq"></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"><ElementType name="Item"
order="one"></FONT>
<P><FONT face="Courier New" size=1 class="normal105"><element type="product"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="backOrderedProduct"<span class="normal105">
/></span></FONT></P>
<P><FONT face="Courier New" size=1><span class="normal105"></ElementType></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"><ElementType name="Item"></FONT>
<P><FONT face="Courier New" size=1 class="normal105"><group order="one"></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="product"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="backOrderedProduct"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"></group></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="quantity"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="price"/></FONT></P>
<P><FONT face="Courier New" size=1><span class="normal105"></ElementType></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"><ElementType name="PurchaseOrder"
model="open"></FONT>
<P><FONT face="Courier New" size=1 class="normal105"><element type="shipTo"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="orderDate"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="shipDate"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="comments"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="Items"/></FONT></P>
<P><FONT face="Courier New"
size=1 class="normal105"></ElementType></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"><ElementType
name="PurchaseOrder" model="closed"></FONT>
<P><FONT face="Courier New" size=1><span class="normal105"><element
type="shipTo"/></span></FONT></P>
<P><span class="normal105"><FONT face="Courier New" size=1 class="normal105"><element
type="orderDate"/></FONT></span></P>
<P><span class="normal105"><FONT face="Courier New" size=1 class="normal105"><element
type="shipDate"/></FONT></span></P>
<P><span class="normal105"><FONT face="Courier New" size=1 class="normal105"><element
type="comments" /></FONT></span></P>
<P><span class="normal105"><FONT face="Courier New" size=1 class="normal105"><element
type="Items"/></FONT></span></P>
<P><span class="normal105"><FONT face="Courier New" size=1><span class="normal105"></ElementType></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"><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"></FONT></span></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="PurchaseOrder"
content="eltOnly" ></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="shipTo"/></FONT></P>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?