下面的schema为撒不起到验证作用,尤其是unique那块???
....................................................................
schema代码如下
.....................................................................
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<!--Define the type of company name which base on string -->
<xs:simpleType name="ComNameType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<!--Define the type of company CEO which base on string maybe complex in the furture-->
<xs:simpleType name="ComCEOType">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<!--Define a company structor which contain name of it and a CEO-->
<xs:complexType name="CompanyType">
<xs:sequence>
<xs:element name="Name" type="ComNameType"/>
<xs:element name="CEO" type="ComCEOType"/>
</xs:sequence>
<xs:attribute name="PID" type="xs:string"/>
</xs:complexType>
<!--Combin the companies -->
<xs:complexType name="CompaniesType">
<xs:sequence maxOccurs="unbounded">
<xs:element name="Company" type="CompanyType">
<xs:unique name="CompanyID">
<xs:selector xpath="Companies/Company"/>
<xs:field xpath="@PID"/>
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
<!--Initialize root element-->
<xs:element name="Companies" type="CompaniesType"/>
</xs:schema>
..........................................................
xml代码如下
..........................................................
<?xml version="1.0" encoding="UTF-8"?>
<Companies xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\MyCompany\CompanySch.xsd">
<Company PID="c02">
<Name>Microsoft</Name>
<CEO>Bill Gates</CEO>
</Company>
<Company PID="c02">
<Name>TCL</Name>
<CEO>ShiHong Wu</CEO>
</Company>
<Company PID="c02">
<Name>SUN</Name>
<CEO>James Gosling</CEO>
</Company>
</Companies>