简体   繁体   中英

Single XSD schema for a slightly varied xml files

I have some xml that comes in and I want to validate and it can look like this

<hotel>
    <reservation>
         <hotelroom>47</hotelroom>
         ...
    </reservation>
</hotel>

or could be

<hotel>
    <restaurant>
         <tablenumber>3</tablenumber>
         ...
    </restaurant>
</hotel>

The idea is that if it is a reservation for the hotel I want to validate against one set of data as shown: hotelroom number requested, address, etc and then if it's some xml for the restaurant then I want the tablenumber, persons name etc.

I have just been learning xsd so still a noob. I have written a schema for each of the cases but am not sure what to do as I feel I want write something in the xsd file to say IF the reservation comes up then validate against this ELSE IF restaurant comes up then validate against this.

I have read the W3 xsd tutorial but couldn't see anything.

Thanks :D

You essentially would want either a reservation or a restuarant . You should use xsd:choice which is meant for this. Then the schema can be used to validate.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM