Schema minOccurs

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Jh

Schema minOccurs

Post 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
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post 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
jh@schaubroeck.be
Posts: 4
Joined: Tue Mar 09, 2004 7:26 pm

Post 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
Post Reply