Extending complex type - minOccurs

K

katis

Hi all :)

Is it posible in xsd to change only minOccurs value of element in
complex type by extending this type?

The problem I'm trying to solve is this: I have two complex types -
"TextField" and "FileChooser".
Here is definition of "TextField"

<xsd:complexType name="TextField">
<xsd:sequence>
<xsd:element name="paramName" type="xsd:string"/>
<!-- some other element's definitions here -->
<xsd:element name="file" minOccurs="0" type="file" />
</xsd:sequence>
</xsd:complexType>

"FileChooser"'s type is "TextFile", but I want to ensure that in
"FileChooser" element "file" will occur 1 time. How can it be done? Is
it possible?

Thx for yor time,
Katis
 
C

Chandru

Hi all :)

Is it posible in xsd to change only minOccurs value of element in
complex type by extending this type?

The problem I'm trying to solve is this: I have two complex types -
"TextField" and "FileChooser".
Here is definition of "TextField"

<xsd:complexType name="TextField">
<xsd:sequence>
<xsd:element name="paramName" type="xsd:string"/>
<!-- some other element's definitions here -->
<xsd:element name="file" minOccurs="0" type="file" />
</xsd:sequence>
</xsd:complexType>

"FileChooser"'s type is "TextFile", but I want to ensure that in
"FileChooser" element "file" will occur 1 time. How can it be done? Is
it possible?

Thx for yor time,
Katis

Hi Katis,
I think it is not possible. Once you define an element of a particular
complex type it will take the complex types defintion. So you have to
change minOccurs to 1 within "TextFile" type.
Thanks,
Chandra
 
K

katis

Thanks for your response, Chandru - I get your point. But it seems I
didn't make myselfe clear. I was thinking of defining another complex
type - let's say "FileChooserType" that would extend "TextField", and
defining "FileChooser" as a element of a "FileChooserType" type.

So my question - one more time - is: is it possible to change value of
minOccurs of some element when extending the complex type? In other
words - I have complex type "TextField" and "FileChooserType"
extending "TextField" type. In "TextField" I have <xsd:element
name="file" minOccurs="0" type="file" /> defined. I want to be able to
use "file" element also in "FileChooserType", but with minOccurs
changed from 0 to 1. Can it be done using extending mechanism or
should I define another type - let's say "SuperTextType" without
"file" element in it, and make "TextField" and "FileChooserType"
extending "SuperTextType", each of them defining "file" element with
different minOccurs count?

Katis

Chandru napisal(a):
 
U

usenet

Thanks for your response, Chandru - I get your point. But it seems I
didn't make myselfe clear. I was thinking of defining another complex
type - let's say "FileChooserType" that would extend "TextField", and
defining "FileChooser" as a element of a "FileChooserType" type.

So my question - one more time - is: is it possible to change value of
minOccurs of some element when extending the complex type? In other
words - I have complex type "TextField" and "FileChooserType"
extending "TextField" type. In "TextField" I have <xsd:element
name="file" minOccurs="0" type="file" /> defined. I want to be able to
use "file" element also in "FileChooserType", but with minOccurs
changed from 0 to 1. Can it be done using extending mechanism or
should I define another type - let's say "SuperTextType" without
"file" element in it, and make "TextField" and "FileChooserType"
extending "SuperTextType", each of them defining "file" element with
different minOccurs count?

Katis

Chandru napisal(a):





- Show quoted text -


I think what you could do is use schema's <restriction> option, e.g.
define FileChooser as:

<xsd:complexType name="FileChooser">
<xsd:complexContent>
<xsd:restriction base="TextField">
<xsd:sequence>
<xsd:element name="paramName" type="xsd:string"/>
<!-- some other element's definitions here -->
<xsd:element name="file" minOccurs="1" type="file" />
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

The down side of that is that you largely have to redefine
FileChooser. You can get around this to some degree by using a group
for the common stuff.

<xsd:complexType name="TextField">
<xsd:sequence>
<xsd:group ref="commonStuff"/>
<xsd:element name="file" minOccurs="0" type="file" />
</xsd:sequence>
</xsd:complexType>

<xsd:complexType name="FileChooser">
<xsd:complexContent>
<xsd:restriction base="TextField">
<xsd:sequence>
<xsd:group ref="commonStuff"/>
<xsd:element name="file" minOccurs="1" type="file" />
</xsd:sequence>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>

Consequently, your suggestions to use a super type is probably more
appealing.

HTH,

Pete.
--
=============================================
Pete Cordell
Tech-Know-Ware Ltd
for XML Schema to C++ data binding visit
http://www.tech-know-ware.com/lmx/
http://www.codalogic.com/lmx/
=============================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top