XSD with "required" attribute option related query
Question asked by rajneesh shukla - 2/21/2020 at 11:33 AM
Hello All,

I am new to XSD and XML and need to explore if there is option to make sure that any one attribute in a set of attributes within same element is required.


  <xs:element name="where" maxOccurs="1" minOccurs="0">
              <xs:element name="condition" maxOccurs="unbounded" minOccurs="1">
                    <xs:extension base="xs:string">
                      <xs:attribute type="xs:string" name="alias1" use="required"/>
                      <xs:attribute type="xs:string" name="col1" use="required"/>
                      <xs:attribute type="xs:string" name="operator" use="required"/>
                      <xs:attribute type="xs:string" name="string" use="optional"/>
                      <xs:attribute type="xs:string" name="number" use="optional"/>
                      <xs:attribute type="xs:string" name="date" use="optional"/>

Here I want to ensure that minimum one  attribute  in a set of 3 attributes (mentioned as optional in above) are required. All can not be optional , however any one (can be more than one also) is required.


1 Reply

Reply to Thread
Liquid Support Replied
Employee Post Marked As Answer
I don't think that is possible, but you could do similar with elements using a choice...

<xs:element name="where">
        <xs:choice minOccurs="1" maxOccurs="unbounded">
            <xs:element name="s" type="xs:string" />
            <xs:element name="n" type="xs:string" />
            <xs:element name="d" type="xs:string" />

Reply to Thread