Can't do it as stated. You can't have the type of one element (empty or not)
depend on the type of another, or any other test that amounts to the same
thing.
What you can do is require that if field1 is specified then field2 must be
specified, and vice versa. Since you can require that field1 and field2 have
values, this amounts to the same thing. One such schema fragment is:
<element name="test">
<complexType>
<complexContent>
<sequence minOccurs="0">
<element name="field1" type="integer"/>
<element name="field2" type="integer"/>
</sequence>
</complexContent>
</complexType>
</element>
(You would have no problem writing a schema per your original problem
statement in RELAX NG.)
Bob Foster
"ranma79" <ra*****@comcast.net> wrote in message
news:31*************************@posting.google.co m...
Hi,
I was wondering if anyone knows if this is possible. I have the
following simple xml document as follows:
<test>
<field1>Value1</field1>
<field2>Value2</field2>
</test>
I would like to create an XSD which validates that if the "field1"
element contains a value, then "field2" must also contain a value. And
also the other way around, if "field2" contains a value, then "field1"
must contain a value. However, if both fields do not contain values
then no validation errors occur. Any ideas? Thanks!