XSD with "required" attribute option related query
Question asked by rajneesh shukla - 2/21/2020 at 11:33 AM
Answered
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.

Example:

  <xs:element name="where" maxOccurs="1" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="condition" maxOccurs="unbounded" minOccurs="1">
                <xs:complexType>
                  <xs:simpleContent>
                    <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"/>
                    </xs:extension>
                  </xs:simpleContent>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>

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.

Thanks,
Rajneesh


1 Reply

Reply to Thread
0
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:complexType>
        <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" />
        </xs:choice>
    </xs:complexType>
</xs:element>

Reply to Thread