So I have a "hotel" root element which contains an element "rooms". Inside the rooms element, there must be a list of present rooms:
<?xml version="1.0"?>
<h:hotel xmlns:h="hotel">
<existingRooms>
<room>101</room>
<room>102</room>
<room>201</room>
</existingRooms>
</h:hotel>
multiple rooms with the same roomnumber should be illegal:
<?xml version="1.0"?>
<h:hotel xmlns:h="hotel">
<existingRooms>
<room>101</room>
<room>102</room>
<room>201</room>
<room>201</room>
</existingRooms>
</h:hotel>
When I try to do this with , the validator only accepts one room, which is obviously not my goal:
<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:h="hotel"
targetNamespace="hotel">
<element name="hotel">
<complexType>
<sequence>
<element name="existingRooms">
<complexType>
<sequence>
<element name="room" type="integer" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
</sequence>
</complexType>
<unique name="inuqueRoomNumber">
<selector xpath="existingRooms"/>
<field xpath="room"/>
</unique>
</element>
</schema>
What can be the solution for this issue?
Change
<unique name="inuqueRoomNumber">
<selector xpath="existingRooms"/>
<field xpath="room"/>
</unique>
to
<unique name="inuqueRoomNumber">
<selector xpath="existingRooms/room"/>
<field xpath="."/>
</unique>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.