In XSD, when optional parent element occurs, are its children mandatory?

1.1k Views Asked by At

I have been wondering about a simple but very important question.

I have a parent element that is optional because of minOccurs="0" but its child elements do not have any minOccurs or maxOccures attributes defined.

Am I right that in case the parent element occurs, all its child elements are mandatory?

My example code looks like this:

name="FiscalRepresentativeInfo" minOccurs="0">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="FiscalRepresentativeTaxRegistrations" type="MandatoryTaxNumbersType"></xs:element>
            <xs:element name="FiscalRepresentativeName" type="LongStringType"></xs:element>
            <xs:element name="FiscalRepresentativeAddress" type="AddressType"></xs:element>
            <xs:element name="FiscalRepresentativeBankAccountNumber" type="BankAccountNumberType"></xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>

Now, my question in practical terms is this:

  1. The fiscal representative info is optional, the XML instance may or may not contain it.
  2. Here comes the point: in case there is a fiscal representative info in the XML, it MUST have all 4 elements. For example, it is not possible to miss the bank account number.

Please let me know whether my understanding above is correct.

1

There are 1 best solutions below

0
kjhughes On

Your understanding is correct: The optionality of children is independent of the optionality of present parents. That is, the mandatory children of an optional parent must be present if the parent is present.