Jump to content
Sign in to follow this  
J.T.

Newbie Question: 3 Optional Elements, Yet One Of The Three Is Required

Recommended Posts

I've tried a number of scenarios, but can't seem to hit on the correct configuration.I need to modify the complextype below to adhere to the following requirements: 1. Although the NASD_CRD_Number, AlternateID & TaxID elements are optional, at least one of threee elements must be present on the request 2. Although one of the three elements must be present on the request, the remaining two elements can also be present. 3. An element can only be present once. <xsd:complexType name="AgentInformationListType"> <xsd:sequence> <xsd:element name="AgentInformation" minOccurs="1" maxOccurs="1"> <xsd:complexType> <xsd:all> <xsd:element name="CorrelationId" type="xsd:string" minOccurs="0" maxOccurs="1" /> <xsd:element name="NASD_CRD_Number" type="xsd:string" minOccurs="0" maxOccurs="1" /> <xsd:element name="AlternateID" type="xsd:string" minOccurs="0" maxOccurs="1" /> <xsd:element name="TaxID" type="xsd:string" minOccurs="0" maxOccurs="1" /> </xsd:all> </xsd:complexType> </xsd:element> </xsd:sequence></xsd:complexType>The closest I've come to a solution is below (please no snickering), but it has the following limitations: 1. a new element (XXX) is introduced into the structure 2. it doesn't prevent one of the three elements from repeating <xsd:complexType name="AgentInformationListType"> <xsd:sequence> <xsd:element name="AgentInformation" minOccurs="1" maxOccurs="1"> <xsd:complexType> <xsd:all> <xsd:element name="CorrelationId" type="xsd:string" minOccurs="0" maxOccurs="1" /> <xsd:element name="XXX" type="XXX" minOccurs="0" maxOccurs="1" /> </xsd:all> </xsd:complexType> </xsd:element> </xsd:sequence></xsd:complexType><xsd:complexType name="XXX"> <xsd:choice minOccurs="1" maxOccurs="3"> <xsd:element name="NASD_CRD_Number" type="xsd:string"/> <xsd:element name="AlternateID" type="xsd:string"/> <xsd:element name="TaxID" type="xsd:string"/> </xsd:choice></xsd:complexType>I also attempted to use xsd:group with the "ref" parameter, but couldn't get it to validate.Thanks !

Share this post


Link to post
Share on other sites

I'm still interested in finding a solution to my problem, however I am getting closer with the following configuration. One limitation still exists though, any of the items in the choice can repeat:<xsd:complexType name="AgentInformationListType"><xsd:sequence><xsd:element name="AgentInformation" minOccurs="1" maxOccurs="1"><xsd:complexType><xsd:sequence><xsd:element name="CorrelationId" type="xsd:string" minOccurs="0" maxOccurs="1" /><xsd:group ref="GroupChoice" minOccurs="1" maxOccurs="3" /></xsd:sequence></xsd:complexType></xsd:element></xsd:sequence></xsd:complexType><xsd:group name="GroupChoice"><xsd:choice><xsd:element name="NASD_CRD_Number" type="xsd:string" minOccurs="1" maxOccurs="1" /><xsd:element name="AlternateID" type="xsd:string" minOccurs="1" maxOccurs="1" /><xsd:element name="TaxID" type="xsd:string" minOccurs="1" maxOccurs="1" /></xsd:choice></xsd:group>Any thoughts?

Edited by J.T.

Share this post


Link to post
Share on other sites

Have you considered making those things attributes? Would it be feasable?Then, you can have a single choise of an element that has one of those attributes set to required and the others as optional.If that doesn't work, consider approaching the whole problem differently.Create an element that will hold the "name" (and/or value) of whatever you're trying to get, and set minOccurs="1" to this element, so that at least one of these things is specified. The exact possible "names" should (of course) be enumerated. They should also be xsd:key-ed, so that you don't have two occurances of the same "name".

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...