xml-d~ix.htm
来自「这是一本关于XML的学习的书」· HTM 代码 · 共 811 行 · 第 1/5 页
HTM
811 行
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="normal9"><comments></span><BR>
<span class="normal105">Get these things to me in a hurry, my lawn
is going wild!<BR>
</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 class="normal105"><trackingInformation
xmlns="http://somewhere.com/tracking.xml"></FONT></P>
<P><FONT face="Courier New"
size=1 class="normal105"><route>1234-5678</route></FONT></P>
<P><FONT face="Courier New"
size=1 class="normal105"><signature>32143912850-3959159=1395</signature></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"></trackingInformation></FONT></P>
<P><FONT face="Courier New"
size=1 class="normal105"></PurchaseOrder></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"><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">></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><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" /></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><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" /></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><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" /></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">这需要一个不同的大纲.(实际上,要求几个大纲间存在差异,因为我们将需要改变"http://fabrikam.com/PO.xml"和"http://electrocommerce.org/stuff.xml".)让我们来看以下修改后的PurchaseOrder大纲.</FONT></P>
<DIR>
<LI><FONT face="Courier New" size=1 class="normal105"><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"></FONT></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"><AttributeType name="shipTo"
dt:type="idref"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><attribute type="shipTo"/>></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><AttributeType name="shipTo"
dt:type="idref"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><attribute type="shipTo"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><AttributeType name="items"
dt:type="idrefs"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><attribute type="items"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><AttributeType name="orderDate"
dt:type="date"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><attribute type="orderDate"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><AttributeType name="shipDate"
dt:type="date"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><attribute type="shipDate"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><AttributeType name="comments"
dt:type="string"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><attribute type="comments"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="abcde:Address"
</FONT></P>
<P><FONT face="Courier New"
size=1 class="normal105">xmlns:abcde="http://electrocommerce.org/stuff.xml"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><element type="Items"
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"><AttributeType name="id"
dt:type="id"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><attribute type="id"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><AttributeType name="product"
dt:type="string"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><attribute type="product"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><AttributeType name="quantity"
dt:type="int"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><attribute type="quantity"
/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><AttributeType name="price"
dt:type="fixed.14.4"/></FONT></P>
<P><FONT face="Courier New" size=1 class="normal105"><attribute type="price"
/></FONT></P>
<P><FONT face="Courier New" size=1><span class="normal105"></ElementType></span></FONT></P>
<P><span class="normal105"><FONT face="Courier New" size=1><span class="normal105"></schema></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"><AttributeType
name="shipTo" dt:type="idref"/></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"><attribute
type="shipTo"/></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"><AttributeType
name="shipTo" dt:type="idref"/></FONT>
<P><FONT face="Courier New" size=1><span class="normal105"><attribute
type="shipTo"/></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 + -
显示快捷键?