Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is minOccurs="0" not allowing an element to be empty?

I’ve set the element "FURNITURE" to minOccurs="0" but it still comes back

Element ‘FURNITURE’ cannot be empty according to the DTD/Schema.

when I try to validate it

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<xsd:element name="FURNITURE" minOccurs="0" maxOccurs="6">
  <xsd:complexType>
    <xsd:sequence>
      <xsd:element name="ID" type="xsd:integer" />
      <xsd:element name="rNumber" type="xsd:string" /> 
      <xsd:element name="type" type="xsd:string" />
    </xsd:sequence>
  </xsd:complexType>
</xsd:element>

and

<FURNITURE />

>Solution :

By placing minOccurs="0" on FURNITURE, you’re specifying that FURNITURE need not be present, but that says nothing about the content model of FURNITURE. In fact, FURNITURE must consist of a sequence of ID, rNumber, and type elements which must all be present exactly once.

If you want FURNITURE to possibly be empty when present, then make each of those child elements optional individually by adding minOccurs="0" to each xsd:element or collectively by adding minOccurs="0" to the wrapping xsd:sequence.

See also

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading