conditional processing for XSD elements?

P

Piper707

Hi,

I need to know if there is any way of achieving conditional processing
for XSD elements.

---------------------------------------------------------------
<criteria></criteria> = a complex element
<join_condition></join_condition> = a simple element
---------------------------------------------------------------
EX:

<criteria>....</criteria>
<join_condition>.....</join_condition>
<criteria> .....</criteria>
---------------------------------------------------------------

I need the 1st criteria block to be mandatory. But it makes sense to
have a second criteria block, only if a join condition block has been
provided.

so it would be illegal to have only:
---------------------------------------------------------------
<criteria>....</criteria>
<join_condition>.....</join_condition>
---------------------------------------------------------------
I'm trying to impose the restriction: "if join_condition occurs once, a
criteria block must occur once under it."

I was trying to use the "group" conditional, but it points out
xs:sequence to be illegal, i'm not sure why? -

<xs:group name="criteria_and_join" minOccurs="0">
<xs:sequence>
<xs:element name="join_condition">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="AND"/>
<xs:enumeration value="OR"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element ref="criteria"/> //defined elewhere as a
complex type
</xs:sequence>
</xs:group>

How can achieve the conditional restriction that a criteria block can
only appear provided a join_condition block precedes it (except for the
very first criteria block)?

Thanks
Rohit.
 
S

Stan Kitsis [MSFT]

<xs:sequence>
<xs:element name="criteria"/>
<xs:sequence minOccurs="0">
<xs:element name="join_condition"/>
<xs:element name="criteria"/>
</xs:sequence>
</xs:sequence>

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
H

Henry S. Thompson

The only bug in your example (which should do what you want) (assuming
there is a definition of 'criteria' somewhere), is the presence of the
'minOccurs' attribute, which is not allowed on xs:group (because it's
meaningless -- the min/max on the _reference_ to the group is what
matters).

ht
--
Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
Half-time member of W3C Team
2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
Fax: (44) 131 650-4587, e-mail: (e-mail address removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top