我正在學習xml和schema.I想要一個模式,其中電話元素值必須是唯一的。我嘗試獨特但不能理解它是如何工作的。 對不起,這個愚蠢的問題,但我正在學習。我想要電話元素的唯一值
XML
<?xml version="1.0" encoding="utf-8" ?>
<Company xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Employee>
<Name>ABC</Name>
<Telephone>9998887770</Telephone>
</Employee>
<Employee>
<Name>DEF</Name>
<Telephone>9998887770</Telephone>
</Employee>
<Employee>
<Name>GHI</Name>
<Telephone>1234567890</Telephone>
</Employee>
</Company>
模式
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="EmployeeSchema"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Name"/>
<xs:element name="Telephone" />
<xs:simpleType name="string32">
<xs:restriction base="xs:token">
<xs:maxLength value="32"/>
</xs:restriction>
<xs:element name="Company">
<xs:complexType>
<xs:sequence>
<xs:element ref="Employee" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<!--Here i try to implement unique--->
<xs:unique name="Company">
<xs:selector xpath="Telephone"/>
<xs:field xpath="Telephone"/>
</xs:unique>
</xs:element>
<xs:element name="Employee">
<xs:complexType>
<xs:sequence>
<xs:element ref="Name"/>
<xs:element ref="Telephone"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
「我嘗試獨特但不明白它是如何工作的」。你讀過什麼書?我會推薦Priscilla Walmsley's。 –
我從**學習 「XML模式由Eric範德瓦VLIST」 ** @MichaelKay –