Hello,
I have a complex bit of polymorphism I've achieved via xs:alternative in XSD 1.1. However, I'd like this weird amalgamated "type" I've created to be used in multiple elements. This is a problem, since as far as I can tell, the xs:alternative tag can only be a child of xs:element. Is there any way to do code re-use here, where I can have a the set of alternatives defined in a single place and multiple elements use it?
xs:alternative & reuse?
Re: xs:alternative & reuse?
Hello,
You cannot reuse xs:alternative, you can reuse the types referred in the alternative. Here is an example:
Best Regards,
Octavian
You cannot reuse xs:alternative, you can reuse the types referred in the alternative. Here is an example:
Code: Select all
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" vc:minVersion="1.1">
<xs:element name="Example">
<xs:complexType>
<xs:sequence>
<xs:element name="Beverage" type="BeverageType" maxOccurs="unbounded">
<xs:alternative test="@current-time le '12:00:00'" type="MorningBeverage" />
<xs:alternative test="@current-time gt '12:00:00'" type="AfternoonBeverage" />
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="BeverageType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="current-time" type="xs:time" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="MorningBeverage">
<xs:simpleContent>
<xs:extension base="BeverageType">
<xs:attribute name="tea" type="xs:string" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="AfternoonBeverage">
<xs:simpleContent>
<xs:extension base="BeverageType">
<xs:attribute name="juice" type="xs:string" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com