xml-d~ix.htm
来自「这是一本关于XML的学习的书」· HTM 代码 · 共 811 行 · 第 1/5 页
HTM
811 行
<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>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="shipTo"
content="eltOnly" /></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="name"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="street"
/></FONT></P>
<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"
content="textOnly" /></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="street"
content="textOnly" /></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="city"
content="textOnly" /></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="state"
content="textOnly" /></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" minOccurs="0" /></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="comments"
minOccurs="0" content="textOnly" /></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="items"
model="closed"></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="Item"
maxOccurs="*"/></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"><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 class="normal105"></ElementType></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="product"
content="textOnly" /></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><ElementType name="backOrderedProduct"
content="textOnly" /></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><span class="normal105"></schema></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"><ElementType
name="PurchaseOrder"</span><BR>
<span class="normal105">xmlns:abcde="http://electrocommerce.org/stuff.xml"
></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"><ElementType
name="shipTo"</span><BR>
<span class="normal105">xmlns:abcde="http://electrocommerce.org/stuff.xml"
></span><BR>
<span class="normal105"><element type="abcde:Address"/></span><BR>
<span class="normal105"></ElementType></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"><PurchaseOrder
xmlns:abcde="http://electrocommerce.org/stuff.xml"></FONT>
<P><FONT face="Courier New" size=1 class="normal105"><shipTo></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><abcde:Address></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><abcde:name>Alice
Smith</abcde:name></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><abcde:street>123
Maple Street</abcde:street></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><abcde:city>Mill
Valley</abcde:city></FONT></P>
<P><FONT face="Courier New"
size=1 class="normal105"><abcde:state>CA</abcde:state></FONT></P>
<P><FONT face="Courier New"
size=1><span class="normal105"><abcde:zip>90952</abcde:zip></span><BR>
<span class="normal105"></abcde:Address></span></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"></shipTo></FONT></P>
<P><FONT face="Courier New"
size=1 class="normal105"><orderDate>1999-05-20</orderDate></FONT></P>
<P><FONT face="Courier New"
size=1 class="normal105"><shipDate>1999-05-25</shipDate></FONT></P>
<P><FONT face="Courier New" size=1><span class="normal105"><comments></span><BR>
<span class="normal105">Get these things to me in a hurry, my lawn
is going wild!</span><BR>
<span class="normal105"></comments></span></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><Items></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><Item></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><productName>Lawnmower,
model BUZZ-1</productName></FONT></P>
<P><FONT face="Courier New"
size=1 class="normal105"><quantity>1</quantity></FONT></P>
<P><FONT face="Courier New"
size=1 class="normal105"><price>148.95</price></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"></Item></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><Item></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><productName>Baby
Monitor, model SNOOZE-2</productName></FONT></P>
<P><FONT face="Courier New"
size=1 class="normal105"><quantity>1</quantity></FONT></P>
<P><FONT face="Courier New"
size=1 class="normal105"><price>39.98</price></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"></Item></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"></Items></FONT></P>
<P><FONT face="Courier New" size=1><span class="normal105"></PurchaseOrder></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"><PurchaseOrder
xmlns:z="http://electrocommerce.org/stuff.xml"></FONT>
<P><FONT face="Courier New" size=1 class="normal105"><shipTo></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><z:Address></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><z:name>Alice
Smith</z:name></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><z:street>123
Maple Street</z:street></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><z:city>Mill
Valley</z:city></FONT></P>
<P><FONT face="Courier New"
size=1 class="normal105"><z:state>CA</z:state></FONT></P>
<P><FONT face="Courier New"
size=1><span class="normal105"><z:zip>90952</z:zip></span><BR>
<span class="normal105"></z:Address></span></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"></shipTo></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 + -
显示快捷键?