五月综合缴情婷婷六月,色94色欧美sute亚洲线路二,日韩制服国产精品一区,色噜噜一区二区三区,香港三级午夜理伦三级三

您現(xiàn)在的位置: 365建站網(wǎng) > 建站教程 > Schema 教程 > XSD <anyAttribute> 元素

XSD <anyAttribute> 元素

此節(jié)有 337 人學(xué)習(xí)過     參與評論

<anyAttribute> 元素使我們有能力通過未被 schema 規(guī)定的屬性來擴展 XML 文檔!

<anyAttribute> 元素

<anyAttribute> 元素使我們有能力通過未被 schema 規(guī)定的屬性來擴展 XML 文檔!

下面的例子是來自名為 "family.xsd" 的 XML schema 的一個片段。它為我們展示了針對 "person" 元素的一個聲明。通過使用 <anyAttribute> 元素,我們就可以向 "person" 元素添加任意數(shù)量的屬性:

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
    </xs:sequence>
    <xs:anyAttribute/>
  </xs:complexType>
</xs:element>

現(xiàn)在,我們希望通過 "gender" 屬性來擴展 "person" 元素。在這種情況下我們就可以這樣做,即使這個 schema 的作者從未聲明過任何 "gender" 屬性。

請看這個 schema 文件,名為 "attribute.xsd":

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://theartemis.cn"
xmlns="http://theartemis.cn"
elementFormDefault="qualified">

<xs:attribute name="gender">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="male|female"/>
    </xs:restriction>
  </xs:simpleType>
</xs:attribute>

</xs:schema>

下面這個 XML(名為 "Myfamily.xml"),使用了來自不同 schema 的成分,"family.xsd" 和 "attribute.xsd":

<?xml version="1.0" encoding="ISO-8859-1"?>

<persons xmlns="http://www.microsoft.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:SchemaLocation="http://www.microsoft.com family.xsd
http://theartemis.cn attribute.xsd">

<person gender="female">
<firstname>Jane</firstname>
<lastname>Smith</lastname>
</person>

<person gender="male">
<firstname>David</firstname>
<lastname>Smith</lastname>
</person>

</persons>

上面這個 XML 文件是有效的,這是因為 schema "family.xsd" 允許我們向 "person" 元素添加屬性。

<any> 和 <anyAttribute> 均可用于制作可擴展的文檔!它們使文檔有能力包含未在主 XML schema 中聲明過的附加元素。

如對本文有疑問,請?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會為你解答!! 點擊進入論壇

您可能感興趣的文章:

發(fā)表評論 (337人查看,0條評論)
請自覺遵守互聯(lián)網(wǎng)相關(guān)的政策法規(guī),嚴禁發(fā)布色情、暴力、反動的言論。
昵稱:
最新評論
------分隔線----------------------------
Schema 教程目錄

其它欄目

· 建站教程
· 365學(xué)習(xí)

業(yè)務(wù)咨詢

· 技術(shù)支持
· 服務(wù)時間:9:00-18:00
365建站網(wǎng)二維碼

Powered by 365建站網(wǎng) RSS地圖 HTML地圖

copyright © 2013-2024 版權(quán)所有 鄂ICP備17013400號