This problem is taking me too long to fix
I could use some guidance
I’m trying to define a game board and i want to be
sure each house can only exist once, meaning it has a
set of coordinates unique.
I don’t understand why my code accepts repeated values of Coordinates
<xs:element name="Board">
<xs:complexType>
<xs:sequence minOccurs="3" maxOccurs="unbounded">
<xs:element name="house" type="Tile">
<xs:unique name="tileKey">
<xs:selector xpath="./Point"/>
<xs:field xpath="x"/>
<xs:field xpath="y"/>
</xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Tile">
<xs:sequence>
<xs:element name="Point" type="Coords"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Coords">
<xs:sequence>
<xs:element name="x" type="xs:int"/>
<xs:element name="y" type="xs:int"/>
</xs:sequence>
</xs:complexType>
If i have 3 houses with x and y 0 the xml is valid.
What am I doing wrong?
output is something like
<Board>
<house>
<Point>
<x>0</x>
<y>0</y>
</Point>
</house>
</Board>
Thank you for your help
Your unique validation is only applying to the points within a house (of which there can only be one by your schema definition, so the validation would never trigger). If you want to validate across all points in all house tags, you need to move your unique check out one level: