Page 1 of 1

Schema minOccurs

Posted: Mon Mar 15, 2004 6:25 pm
by Jh
Hi,

When I generate an xml from a schema, it seems that elements with minOccurs="0" are not generated. If I do want them in the generated xml, were do I have to set that feature on?

Kind Regards,
Jan

Posted: Tue Mar 16, 2004 5:29 pm
by sorin_ristache
Hello,

Optional elements are not included in the generated document. Otherwise the generation will be infinitely recursive. For example what document should be generated for the following schema ?

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
<xs:element name="child">
<xs:complexType>
<xs:sequence>
<xs:element ref="name"/>
<xs:element ref="child" minOccurs='0' maxOccurs='unbounded'/>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="name" type='xs:string'/>
</xs:schema>
This is also true for choice elements. You can enable and disable the generation of elements having the minOccurs attribute at least 1 from Options -> Preferences -> Editor -> Tag Insight -> Features : Add required elements.

Best regards,
Sorin

Posted: Mon Mar 22, 2004 11:41 am
by jh@schaubroeck.be
Hi,

You're absolutely right about that recursive stuff. However, I want to be able to say to oxygen that it must create one occurence when minOccurs=0. Something like: If no boundaries are present(like your example), try to generate x times. Otherwise I need to replace all minOccurs=0, set them to X generate the xml, set everything back. Notice the latter isn't save to just replace, so I'm stuck with replacing by hand, or copying every schema and deleting afterwards.

The thing is that the minOccurs=0 is needed, but it does not occur frequently that every element with that attribute isn't there. On the contrary, I want to start from every element being there and delete the few that aren't required.

Kind Regards,
Jan