xs:complexType使用方法比較:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://mynamespace/schema">
<xs:element name="書本">
<xs:complexType>
<xs:attribute name="名稱" type="xs:string"/>
<xs:attribute name="作者" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<書本 xmlns="http://mynamespace/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://mynamespace/schema file:///C:/Documents%20and%20Settings/Administrator/%e6%a1%8c%e9%9d%a2/Untitled1.xsd" 名稱="書籍" 作者="hehe"/>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="element" type="myElementType"/>
<xs:complexType name="myElementType">
<xs:attributeGroup ref="myAttributeGroup"/>
</xs:complexType>
<xs:attributeGroup name="myAttributeGroup">
<xs:attribute name="someattribute1" type="xs:integer" use="required"/>
<xs:attribute name="someattribute2" type="xs:string"/>
</xs:attributeGroup>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?>
<element xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:///C:/Documents%20and%20Settings/Administrator/%e6%a1%8c%e9%9d%a2/Untitled1.xsd" someattribute1="4"/>
simpleContent元素:
應用於complexType,對它的內容進行約束和擴充。l作用:定義一個簡單類型,它決定了元素和屬性值的約束和相關資訊l屬性:
namel內容:應用已經存在的簡單類型,三種方式:lrestriction→限定一個範圍l
list→從列表中選擇l
union→包含一個值的結合
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:attribute name="allframesize">
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="roadbikesize"/>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="mountainbikesize"/>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:attribute>
complexType與simpleType區別(重要)l
simpleType類型的元素中不能包含元素或者屬性。l當需要聲明一個元素的子項目和/或屬性時,用
complexType;l當需要基於內建的基礎資料型別 (Elementary Data Type)定義一個新的資料類型時,用
simpleType。