Jump to content

Schema modeling advice


Guest WitchKing
 Share

Recommended Posts

Guest WitchKing

I am currently facing a modeling issue with an existing XML Schema.The existing part is something like this:

    <xs:simpleType name="base">        <xs:restriction base="xs:string">            <xs:enumeration value="A"/>            <xs:enumeration value="B"/>            <xs:enumeration value="C"/>        </xs:restriction>    </xs:simpleType>        <xs:complexType name="baseType">        <xs:sequence>            <xs:element name="code" type="base"/>            <xs:element name="value" type="xs:string"/>            <xs:element name="type" type="xs:integer" minOccurs="0"/>        </xs:sequence>    </xs:complexType>        <xs:element name="quote" type="baseType"/>

I have to model a constraint like: "If code is A, then the 'type' element is mandatory".I tried already to split the simple type definition into 2 sets : contrained (A) and unconstrained (B and C). Then I wanted to use a choice inside the definition of baseType like this:

<xs:choice>   <xs:sequence>            <xs:element name="code" type="constrainedBase"/>            <xs:element name="value" type="xs:string"/>            <xs:element name="type" type="xs:integer" minOccurs="1"/>   </xs:sequence>   <xs:sequence>            <xs:element name="code" type="unconstrainedBase"/>            <xs:element name="value" type="xs:string"/>            <xs:element name="type" type="xs:integer" minOccurs="0"/>   </xs:sequence></xs:choice>

Obviously this kind of modelling is not valid in XML Schema.I also tried something like:

<xs:choice>   <xs:sequence>            <xs:element name="code" type="base" fixed="A"/>            <xs:element name="value" type="xs:string"/>            <xs:element name="type" type="xs:integer" minOccurs="1"/>   </xs:sequence>   <xs:sequence>            <xs:element name="code" type="base"/>            <xs:element name="value" type="xs:string"/>            <xs:element name="type" type="xs:integer" minOccurs="0"/>   </xs:sequence></xs:choice>

which still results in validation issues.Any better modelling ideas?Thanks in advance!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...