Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make sure an XML Schema sequence contains at least one element

Tags:

xml

schema

xsd

My xml tag is given below

<ADCNT>
      <EM>
      <RUID>
</ADCNT>

I can make EM tag as mandatory also the same thing I can do with RUID by providing minOccurs = 1 (<EM minOccurs=1>). But I want if both of them are not present then do not validate the xml against schema. If any one of them is present then validate the xml against schema. Means if EM tag is not present then RUID tag must be present and vice versa.

So, how to solve this problem?

Thanks Sunil kumar Sahoo

like image 501
Sunil Kumar Sahoo Avatar asked Dec 18 '22 05:12

Sunil Kumar Sahoo


1 Answers

You need to make a choice:

<xs:element name="ADCNT">
  <xs:complexType>
    <xs:choice>
      <xs:sequence>
       <xs:element ref="EM" minOccurs="1"/>
       <xs:element ref="RUID" maxOccurs="0"/>
      </xs:sequence>
      <xs:sequence>
       <xs:element ref="RUID" minOccurs="1"/>
      </xs:sequence>
    </xs:choice>
  </xs:complexType>
</xs:element> 
like image 107
Martin v. Löwis Avatar answered Dec 23 '22 03:12

Martin v. Löwis