Reputation: 956
I have the following schema
<xs:element name="a">
<xs:complexType>
<xs:choice>
<xs:element ref="b"/>
<xs:element ref="c"/>
<xs:choice>
</xs:complexType>
<xs:element/>
How can I achieve to a to be a simple element at the same time? I want to be able for handle all cases below:
<a>TEXT</a>
<a><b/></a>
<a><c/></a>
Is it possible?
Upvotes: 0
Views: 435
Reputation: 770
If I understand your question correctly, you want a to be a complex type with elements b or c, but also possible to be just TEXT. This can be achieved by using a choice element.
Take a look at this. With minOccurs you can specify how many times you at least want this element to occur. Put it to 0 to make the field optional.
EDIT: This is a solution, I tested it for the xml in the question and it works. You should use the mixed="true field"
<xs:element name="a">
<xs:complexType mixed="true">
<xs:choice>
<xs:element minOccurs="0" ref="b"/>
<xs:element minOccurs="0" ref="c"/>
</xs:choice>
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
Upvotes: 1