If I have an extension, how can I assure that the derived elements are in front of the base class elements? The default is the other way around. I would have loved to use all
, but I know that is impossible.
<xs:complexType name="BaseClass">
<xs:sequence>
<xs:element name="foo" type="xs:string/>
<xs:element name="bar" type="xs:string/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="DerivedClass">
<xs:complexContent>
<xs:extension base="BaseClass">
<xs:sequence>
<!-- This makes the order foo, bar, cheese, tomato -->
<!-- But I need cheese, tomato, foo, bar -->
<xs:element name="cheese" type="xs:string/>
<xs:element name="tomato" type="xs:string/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="BaseClass" type="BaseClass"/>
<xs:element name="DerivedClass" type="DerivedClass" substitutionGroup="BaseClass"/>
The xml I would like to be accepted looks something like this:
<mylist>
<BaseClass>
<foo>lala</foo>
<bar>lala</bar>
</BaseClass>
<DerivedClass>
<cheese>cheddar</cheese>
<tomato>red</tomato>
<foo>lala</foo>
<bar>lala</bar>
</DerivedClass>
</mylist>
At the moment I'm thinking of just copying all elements of BaseClass
into DerivedClass
as well, but I don't know what happens with substitutiongroups and what not.