Get your CodeRanch badge!*
The moose likes XML and Related Technologies and the fly likes To specify one of the value within XSD enumeration tag as mandatory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "To specify one of the value within XSD enumeration tag as mandatory" Watch "To specify one of the value within XSD enumeration tag as mandatory" New topic
Author

To specify one of the value within XSD enumeration tag as mandatory

Neelima Mohan
Greenhorn

Joined: May 23, 2010
Posts: 27
Hi,

How do I specify that some of the values within enumeration of a simpleType is mandatory?
Please see the following element declaration within my XSD.
<xs:element name="events" maxOccurs = "1">
<xs:complexType>
<xs:sequence>
<xs:element name="event" minOccurs = "1"/>
<xs:simpleType >
<xs:restriction base="xs:string">
<xs:enumeration value="click"/>
<xs:enumeration value="tabOut"/>
<xs:enumeration value="tabIn"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>


Now out of the 3 values click, tabOut and tabIn , I want to ensure that the xml file contains an event tag with tabOut as a value. The other 2 (click, tabIn) are optional.
How do I do this?

Sample XML file which will be using my XSD.
<events>
<event>tabOut</event>
<event>click</event>
</events>

Thanks,
Neelima
Neelima Mohan
Greenhorn

Joined: May 23, 2010
Posts: 27
Hi,

In the snippet mentioned above is it that all the events click, tabOut, tabIn are all mandatory, if I am giving those within the restriction tag?
From what I read from one site all the 3 are optional values.
Is there an alternate way to specify 1 as mandatory and 2 events as optional?

Thanks,
Neelima
Neelima Mohan
Greenhorn

Joined: May 23, 2010
Posts: 27
Alternatively I have written it using the pattern tag.

<xs:element name="events" maxOccurs = "1">
<xs:complexType>
<xs:sequence>
<xs:element name="event" minOccurs = "1" maxOccurs = "1" >
<xs:simpleType >
<xs:restriction base="xs:string">
<xs:pattern value="(tabOut)? | (tabIn)? | (click)" />
</xs:restriction>
</xs:simpleType >
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>


will this suffice?

Thanks,
Neelima
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To specify one of the value within XSD enumeration tag as mandatory
 
Similar Threads
MS Exchange web service: If the 'nillable' attribute is false in the schema, the 'xsi:nil' attribute
unble to validate xml against schema
XSD element validation
XSL and Enumeration Query
Axis 1.4 throwing org.xml.sax.SAXException: Invalid element