1

I am inheriting an Xml format and have been tasked with designing a schema around it. Schema generation is fairly simple in most cases, but I have come to a snag.

The issue is that there are elements that have the same name, but will have different content based on an attribute.

Here is an example. This isnt exactly what the Xml looks like, but should show the issue:

<TravelArrgangement type="Hotel">
  <startDate>11-8-2016</startDate>
  <endDate>11-9-2016</endDate>
  <hotelName>Motel 6</hotelName>
  <address>123 Fake Street</address>
</TravelArrgangement>


<TravelArrgangement type="Flight">
  <startDate>11-8-2016 11:30:00AM</startDate>
  <endDate>11-8-2016 4:30:00PM</endDate>
  <carrier>Delta</carrier>
  <origin>NYC</origin>
  <destination>MIA</destination>
</TravelArrgangement>

Note that they are both TravelArrangements, but they have different child elements. Is there any way for me to write a schema definition where the same element can have different content based on a condition, such as the "type" attribute.

Now I know one suggestion would be to alter the Xml format so that a Flight and a HotelStay are their own elements, but there are many old systems relying on this data and they are unlikely to change any time soon.

bsayegh
  • 990
  • 6
  • 17
  • 1
    Either redesign so that `Hotel` and `Flight` are element names, or see duplicate link for how to use Conditional Type Assignment. – kjhughes Nov 08 '16 at 16:23
  • Redesign isnt an option, but ill check out the link. Seems promising. Thanks – bsayegh Nov 08 '16 at 16:26
  • Unfortunately i am stuck with the same issue as the OP of that thread, as 1.1 is not supported. There doesnt seem to be an additional information on the subject in that thread, but I will assume that it is just not possible in 1.0 – bsayegh Nov 08 '16 at 16:35
  • If you're stuck with XSD 1.0, your options are to redesign your XML or test out-of-band wrt XSD. The answer there says that XSD 1.1 is required for CTA. A [comment](http://stackoverflow.com/questions/27878402/how-to-make-type-depend-on-attribute-value-using-conditional-type-assignment#comment44158940_27878402) also says reinforces the point that with only XSD 1.0, for fixed XML, testing outside of XSD would be required. – kjhughes Nov 08 '16 at 16:37
  • Great, thanks @kjhughes. – bsayegh Nov 08 '16 at 16:47

0 Answers0