Informacje o używaniu xs: unikalne w xsi: type w sekwencji
Możliwe jest unikalne ograniczenie typu elementu?
Powiedzmy, że mam Arkę Noego, gdzie nazwa zwierzęcia / @ musi być unikalna.
Poniżej znajduje się kod XML, który nie sprawdza poprawności względem schematu:
<ns:NoahsArk xmlns:ns="http://www.xxx.com" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="http://www.xxx.com Persons.xsd">
<Animal xs:type="ns:Dog" ns:name="Gipsy" ns:pedigree="caniche"/>
<Animal xs:type="ns:Spider" ns:name="Gipsy" ns:legNumber="5"/>
</ns:NoahsArk>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns="http://www.xxx.com"
targetNamespace="http://www.xxx.com" elementFormDefault="unqualified" attributeFormDefault="qualified">
<xs:element name="NoahsArk">
<xs:complexType>
<xs:sequence>
<xs:element name="Animal" maxOccurs="unbounded" type="ns:Animal"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="NameUnicity">
<xs:selector xpath="Animal"/>
<xs:field xpath="@ns:name"/>
</xs:unique>
</xs:element>
<xs:complexType name="Animal" abstract="true">
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="Dog">
<xs:complexContent>
<xs:extension base="ns:Animal">
<xs:attribute name="pedigree" type="xs:string" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Spider">
<xs:complexContent>
<xs:extension base="ns:Animal">
<xs:attribute name="legNumber" type="xs:integer" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
To dobrze, ale teraz powiedzmy, że chcę Arkę Noego, gdzie typ Animal / @ xsi: jest unikalny.
Próbowałem tego ograniczenia:
<xs:unique name="AnimalUnicity">
<xs:selector xpath="Animal"/>
<xs:field xpath="@xs:type"/>
</xs:unique>
Ale ten XML jest nadal ważny :(
<?xml version="1.0" encoding="UTF-8"?>
<ns:NoahsArk xmlns:ns="http://www.xxx.com" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:schemaLocation="http://www.xxx.com Persons.xsd">
<Animal xs:type="ns:Dog" ns:name="Pierre-Louis" ns:pedigree="doberman"/>
<Animal xs:type="ns:Spider" ns:name="Gipsy" ns:legNumber="5"/>
</ns:NoahsArk>
Jakieś pomysły ?
Dzięki, -E