Buildings.xsd
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="buildings">
<xs:complexType>
<xs:sequence>
<xs:element name="building" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="BuildingCode">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z]{3}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="BuildingName" type="xs:string"/>
<xs:element name="Position" type="Position"/>
<xs:element name="Address" type="Address" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="PKBuildingCode">
<xs:selector xpath="building"/>
<xs:field xpath="BuildingCode"/>
</xs:key>
</xs:element>
<xs:complexType name="Position">
<xs:sequence>
<xs:element name="Latitude" type="xs:decimal"/>
<xs:element name="Longitude" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Address">
<xs:sequence>
<xs:element name="StreetNo">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]+"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="StrName" type="xs:string"/>
<xs:element name="City" type="xs:string"/>
<xs:element name="State">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z]{2}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Zip">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{5}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
buildings.xml
<?xml version="1.0" encoding="UTF-8"?>
<buildings>
<building>
<BuildingCode>KOH</BuildingCode>
<BuildingName>King Olympic Hall</BuildingName>
<Position>
<Latitude>34.024547</Latitude>
<Longitude>-118.288</Longitude>
</Position>
<Address>
<StreetNo>1027</StreetNo>
<StrName>W 34th St</StrName>
<City>Los Angeles</City>
<State>CA</State>
<Zip>90007</Zip>
</Address>
</building>
<building>
<BuildingCode>CFX</BuildingCode>
<BuildingName>Cromwell Field</BuildingName>
<Position>
<Latitude>34.021631</Latitude>
<Longitude>-118.289</Longitude>
</Position>
<Address>
<StreetNo>1026</StreetNo>
<StrName>W 34th St</StrName>
<City>Los Angeles</City>
<State>CA</State>
<Zip>90089</Zip>
</Address>
</building>
<building>
<BuildingCode>JEP</BuildingCode>
<BuildingName>JEP House</BuildingName>
<Position>
<Latitude>34.022947</Latitude>
<Longitude>-118.284</Longitude>
</Position>
<Address>
<StreetNo>801</StreetNo>
<StrName>W 34th St</StrName>
<City>Los Angeles</City>
<State>CA</State>
<Zip>90089</Zip>
</Address>
</building>
<building>
<BuildingCode>SHC</BuildingCode>
<BuildingName>Student Health Center</BuildingName>
<Position>
<Latitude>34.023303</Latitude>
<Longitude>-118.285</Longitude>
</Position>
<Address>
<StreetNo>849</StreetNo>
<StrName>W 34th St</StrName>
<City>Los Angeles</City>
<State>CA</State>
<Zip>90089</Zip>
</Address>
</building>
<building>
<BuildingCode>LVY</BuildingCode>
<BuildingName>Leavey Library</BuildingName>
<Position>
<Latitude>34.021595</Latitude>
<Longitude>-118.282</Longitude>
</Position>
<Address>
<StreetNo>651</StreetNo>
<StrName>W 35th St</StrName>
<City>Los Angeles</City>
<State>CA</State>
<Zip>90089</Zip>
</Address>
</building>
<building>
<BuildingCode>VKC</BuildingCode>
<BuildingName>Von KleinSmid Center</BuildingName>
<Position>
<Latitude>34.021649</Latitude>
<Longitude>-118.284</Longitude>
</Position>
<Address>
<StreetNo>3518</StreetNo>
<StrName>Trousdale</StrName>
<City>Los Angeles</City>
<State>CA</State>
<Zip>90089</Zip>
</Address>
</building>
<building>
<BuildingCode>WPH</BuildingCode>
<BuildingName>Waite Phillips Hall</BuildingName>
<Position>
<Latitude>34.022289</Latitude>
<Longitude>-118.284</Longitude>
</Position>
<Address>
<StreetNo>3550</StreetNo>
<StrName>Trousdale</StrName>
<City>Los Angeles</City>
<State>CA</State>
<Zip>90089</Zip>
</Address>
</building>
<building>
<BuildingCode>JHH</BuildingCode>
<BuildingName>John Hubbard Hall</BuildingName>
<Position>
<Latitude>34.020101</Latitude>
<Longitude>-118.284</Longitude>
</Position>
<Address>
<StreetNo>615</StreetNo>
<StrName>ChildsWay</StrName>
<City>Los Angeles</City>
<State>CA</State>
<Zip>90089</Zip>
</Address>
</building>
<building>
<BuildingCode>REG</BuildingCode>
<BuildingName>Registration Builing</BuildingName>
<Position>
<Latitude>34.019603</Latitude>
<Longitude>-118.282</Longitude>
</Position>
<Address>
<StreetNo>611</StreetNo>
<StrName>ChildsWay</StrName>
<City>Los Angeles</City>
<State>CA</State>
<Zip>90089</Zip>
</Address>
</building>
<building>
<BuildingCode>STU</BuildingCode>
<BuildingName>Student Union</BuildingName>
<Position>
<Latitude>34.020226</Latitude>
<Longitude>-118.286</Longitude>
</Position>
<Address>
<StreetNo>3551</StreetNo>
<StrName>Trousdale</StrName>
<City>Los Angeles</City>
<State>CA</State>
<Zip>90089</Zip>
</Address>
</building>
<building>
<BuildingCode>BKS</BuildingCode>
<BuildingName>Bookstore</BuildingName>
<Position>
<Latitude>34.020635</Latitude>
<Longitude>-118.286</Longitude>
</Position>
<Address>
<StreetNo>840</StreetNo>
<StrName>ChildsWay</StrName>
<City>Los Angeles</City>
<State>CA</State>
<Zip>90089</Zip>
</Address>
</building>
<building>
<BuildingCode>RTH</BuildingCode>
<BuildingName>Ronald Tutor Hall</BuildingName>
<Position>
<Latitude>34.020137</Latitude>
<Longitude>-118.29</Longitude>
</Position>
<Address>
<StreetNo>3710</StreetNo>
<StrName>McClintock</StrName>
<City>Los Angeles</City>
<State>CA</State>
<Zip>90089</Zip>
</Address>
</building>
<building>
<BuildingCode>SAL</BuildingCode>
<BuildingName>Salvatori Com. Center</BuildingName>
<Position>
<Latitude>34.01955</Latitude>
<Longitude>-118.289</Longitude>
</Position>
<Address>
<StreetNo>941</StreetNo>
<StrName>W 37th Place</StrName>
<City>Los Angeles</City>
<State>CA</State>
<Zip>90089</Zip>
</Address>
</building>
<building>
<BuildingCode>EEB</BuildingCode>
<BuildingName>Electrical Engr Center</BuildingName>
<Position>
<Latitude>34.019728</Latitude>
<Longitude>-118.29</Longitude>
</Position>
<Address>
<StreetNo>3715</StreetNo>
<StrName>McClintock</StrName>
<City>Los Angeles</City>
<State>CA</State>
<Zip>90089</Zip>
</Address>
</building>
<building>
<BuildingCode>OHE</BuildingCode>
<BuildingName>Olin Hall Engineering</BuildingName>
<Position>
<Latitude>34.020493</Latitude>
<Longitude>-118.29</Longitude>
</Position>
<Address>
<StreetNo>3650</StreetNo>
<StrName>McClintock</StrName>
<City>Los Angeles</City>
<State>CA</State>
<Zip>90089</Zip>
</Address>
</building>
</buildings>
我想将BuildingCode设置为主键并验证buildings.xml文件。我添加了一个名为PKBuildingCode的键,但即使在xml文件中添加了重复的BuildingCode,它也没有验证xml文件。 有人可以帮助我解决问题吗?
答案 0 :(得分:1)
您可能只想要xsd:unique
:
<xs:unique name="PKBuildingCode">
<xs:selector xpath="building"/>
<xs:field xpath="BuildingCode"/>
</xs:unique>
另见: