This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes how to choose only one of the three existing elements in XSD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "how to choose only one of the three existing elements in XSD" Watch "how to choose only one of the three existing elements in XSD" New topic
Author

how to choose only one of the three existing elements in XSD

vamshidhar nimbagiri
Ranch Hand

Joined: Oct 04, 2004
Posts: 61
Hi

I have follwing XSD which contains three elements i.e., RID, BID and KID of which only one of
them should present and remaing are optional.
Could any body please tell me how to achieve this

<xs:element name="CustomerCode">
<xs:complexType>
<xs:sequence>
<xs:element name="RID">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z0-9]{15}" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="BID">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z0-9]{15}" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="KD">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z0-9]{15}" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>


Thanks in advance

Vamshi


Thanks,
Vamshidhar Nimbagiri
SCJP 5.0
vamshidhar nimbagiri
Ranch Hand

Joined: Oct 04, 2004
Posts: 61
Thanks guys i got the answer
by using <xs:choice
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to choose only one of the three existing elements in XSD
 
Similar Threads
in Schema Dynamic value for maxLength - help
Unique particle attribution rule bit me - why?
Customizing JAXB
XSD element validation
how to allow empty values in XML Schema elements