Reputation: 73
I have three elements A, B & C. I wanted to create an XSD for which the schema should be the choice of [A] or [B & C] or [A & B & C]
Can anyone please help me to create an xsd for the above option.
Thanks in Advance. MK
Upvotes: 2
Views: 2657
Reputation: 21638
This satisfies your request; thinking why you might have asked, it was probably related to the Unique particle attribution; the optional sequence below acts as a "virtual" choice.
<?xml version="1.0" encoding="utf-8" ?>
<!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)-->
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="root">
<xsd:complexType>
<xsd:choice>
<xsd:sequence>
<xsd:element name="A"/>
<xsd:sequence minOccurs="0">
<xsd:element name="B"/>
<xsd:element name="C"/>
</xsd:sequence>
</xsd:sequence>
<xsd:sequence>
<xsd:element name="B"/>
<xsd:element name="C"/>
</xsd:sequence>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Upvotes: 1
Reputation: 7234
You can create three separate groups of elements like [A], [B&C] and [A,B & C]. And define a compleType with choice between these groups something like the piece of XSD. Not sure if its validates. I dont have a XSD authoring tool to verify if it does.
<xs:group name="Group1">
<xs:sequence>
<xs:element name="A"/>
</xs:sequence>
</xs:group>
<xs:group name="Group2">
<xs:sequence>
<xs:element name="B"/>
<xs:element name="C"/>
</xs:sequence>
</xs:group>
<xs:group name="Group3">
<xs:sequence>
<xs:element name="A"/>
<xs:element name="B"/>
<xs:element name="C"/>
</xs:sequence>
</xs:group>
<xs:complexType name="choice1">
<xs:choice minOccurs="1" maxOccurs="1">
<xs:group ref="Group1" />
<xs:group ref="Group2"/>
<xs:group ref="Group3"/>
</xs:choice>
</xs:complexType>
Upvotes: 2