Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Neelima Mohan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic