1

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.

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
Fonolit
  • 11
  • 2
  • You might want to add `minOccurs=1` in the subelements explicitly for added clarity, but that is the default anyway, and you would get your desired bahaviour even without it. – guido Dec 09 '17 at 11:11
  • Yes, actually this is not my XSD, this is an XSD published by the tax authority and I have to submit a complient XML from our ERP.I was wondering whether I can omit the bank account of the fiscal representative or not if the fiscal representative is relevant for my submission in general. I tend to think that I can submit my XML with or without a fiscal representative in it, however, once I decide that my submission has to contain a fiscal representative, I have to populate all 4 subelements. – Fonolit Dec 09 '17 at 11:13

1 Answers1

0

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.

kjhughes
  • 106,133
  • 27
  • 181
  • 240