You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Roger L. Costello" <co...@mitre.org> on 2000/06/21 12:43:07 UTC

What are the rules for using restriction?

Hi Folks,

Can anyone explain to me what the rules are for using restriction (i.e.,
derivedBy="restriction")?  In the XML Schema specs I see a lot of
discussion on restriction - what constitutes restriction, where
restriction is used, etc.  However, I don't see where it describes "how
to use" restriction.  Here's what I mean.  Suppose that I have this base
type:

<complexType name="Publication">
        <sequence>
            <element name="Title" type="string" maxOccurs="unbounded"/>
            <element name="Author" type="string" maxOccurs="unbounded"/>
            <element name="Date" type="year"/>
        </sequence>
</complexType>

Note that this type allows an unlimited number of Authors.  Suppose that
I would like to create a new type, SingleAuthorPublication, that is
based upon Publication and restricts the number of Authors to one.  My
question is: how do I do it?  In SingleAuthorPublication do I simply
need to show the changed element:

<complexType name= "SingleAuthorPublication" base="cat:Publication"
             derivedBy= "restriction">
        <sequence>
                <element name="Author" type="string" maxOccurs="1"/>
        </sequence>
</complexType>

Thus, this implies that the other elements (Title and Date) from the
base type are unchanged.  Is this how to do it?  

The examples that I have seen in the Primer and in the Structures spec
all repeat everything from the base type.  So, for my example I would
have:

<complexType name= "SingleAuthorPublication" base="cat:Publication" 
             derivedBy= "restriction">
        <sequence>
             <element name="Title" type="string" maxOccurs="unbounded"/>
             <element name="Author" type="string" maxOccurs="1"/>
             <element name="Date" type="year"/>
        </sequence>
</complexType>

Is this how to do it, i.e., repeat everything from the base type?  (If
this is the case, then, hey, what's the point in having a base type,
i.e., where's the reuse?)  

I vaguely recall reading somewhere that in restriction you have to
repeat all the element declarations in the base type up to the
restricted element, and then you don't have to repeat the remainder of
the base type elements. Is this how to do it? (If this is the case, then
again, I see little reuse, especially if the restricted element is the
last element.)

What about attributes in the base type?  Do they need to be repeated in
the restricted type?

So, what I am really asking is for someone to list the rules in using
restriction.

Thanks.  /Roger


Re: What are the rules for using restriction?

Posted by "Roger L. Costello" <co...@mitre.org>.
I have carefully examined section 5.10 and have received other private
email.  Based upon that, I have found that these are the rules for doing
restriction (using my Publication/SingleAuthorPublication example):

- In SingleAuthorPublication you must repeat everything from the base
type.  These repeat element declarations must be be the same as, or a
restricted form of the corresponding base element declaration.  Thus, in
my example, SingleAuthorPublication must be declared as:

<complexType name= "SingleAuthorPublication" base="cat:Publication"
             derivedBy= "restriction">
        <sequence>
             <element name="Title" type="string" maxOccurs="unbounded"/>
             <element name="Author" type="string" maxOccurs="1"/>
             <element name="Date" type="year"/>
        </sequence>
</complexType>

/Roger

 
> _____
> 
> Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org
> 
> ----- Original Message -----
> From: "Roger L. Costello" <co...@mitre.org>
> To: <xe...@xml.apache.org>
> Cc: <co...@mitre.org>
> Sent: Wednesday, June 21, 2000 3:43 AM
> Subject: What are the rules for using restriction?
> 
> > Hi Folks,
> >
> > Can anyone explain to me what the rules are for using restriction (i.e.,
> > derivedBy="restriction")?  In the XML Schema specs I see a lot of
> > discussion on restriction - what constitutes restriction, where
> > restriction is used, etc.  However, I don't see where it describes "how
> > to use" restriction.  Here's what I mean.  Suppose that I have this base
> > type:
> >
> > <complexType name="Publication">
> >         <sequence>
> >             <element name="Title" type="string" maxOccurs="unbounded"/>
> >             <element name="Author" type="string" maxOccurs="unbounded"/>
> >             <element name="Date" type="year"/>
> >         </sequence>
> > </complexType>
> >
> > Note that this type allows an unlimited number of Authors.  Suppose that
> > I would like to create a new type, SingleAuthorPublication, that is
> > based upon Publication and restricts the number of Authors to one.  My
> > question is: how do I do it?  In SingleAuthorPublication do I simply
> > need to show the changed element:
> >
> > <complexType name= "SingleAuthorPublication" base="cat:Publication"
> >              derivedBy= "restriction">
> >         <sequence>
> >                 <element name="Author" type="string" maxOccurs="1"/>
> >         </sequence>
> > </complexType>
> >
> > Thus, this implies that the other elements (Title and Date) from the
> > base type are unchanged.  Is this how to do it?
> >
> > The examples that I have seen in the Primer and in the Structures spec
> > all repeat everything from the base type.  So, for my example I would
> > have:
> >
> > <complexType name= "SingleAuthorPublication" base="cat:Publication"
> >              derivedBy= "restriction">
> >         <sequence>
> >              <element name="Title" type="string" maxOccurs="unbounded"/>
> >              <element name="Author" type="string" maxOccurs="1"/>
> >              <element name="Date" type="year"/>
> >         </sequence>
> > </complexType>
> >
> > Is this how to do it, i.e., repeat everything from the base type?  (If
> > this is the case, then, hey, what's the point in having a base type,
> > i.e., where's the reuse?)
> >
> > I vaguely recall reading somewhere that in restriction you have to
> > repeat all the element declarations in the base type up to the
> > restricted element, and then you don't have to repeat the remainder of
> > the base type elements. Is this how to do it? (If this is the case, then
> > again, I see little reuse, especially if the restricted element is the
> > last element.)
> >
> > What about attributes in the base type?  Do they need to be repeated in
> > the restricted type?
> >
> > So, what I am really asking is for someone to list the rules in using
> > restriction.
> >
> > Thanks.  /Roger
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: What are the rules for using restriction?

Posted by Eric Ye <er...@locus.apache.org>.
All the rules regarding restriction is in Schema Spec, 5.10, We have't
gotten time to implement all of them.

A simple rule of thumb is that , the content of a complexType derived from a
base type by restriction is whatever it defines by its own, it does not
include anything from its base type.  However the parser is supposed to
check whether the restictrion is a valid one.

As for your example, the "SingleAuthorPublication" will only have one
"Author" element in its content.
_____


Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org

----- Original Message -----
From: "Roger L. Costello" <co...@mitre.org>
To: <xe...@xml.apache.org>
Cc: <co...@mitre.org>
Sent: Wednesday, June 21, 2000 3:43 AM
Subject: What are the rules for using restriction?


> Hi Folks,
>
> Can anyone explain to me what the rules are for using restriction (i.e.,
> derivedBy="restriction")?  In the XML Schema specs I see a lot of
> discussion on restriction - what constitutes restriction, where
> restriction is used, etc.  However, I don't see where it describes "how
> to use" restriction.  Here's what I mean.  Suppose that I have this base
> type:
>
> <complexType name="Publication">
>         <sequence>
>             <element name="Title" type="string" maxOccurs="unbounded"/>
>             <element name="Author" type="string" maxOccurs="unbounded"/>
>             <element name="Date" type="year"/>
>         </sequence>
> </complexType>
>
> Note that this type allows an unlimited number of Authors.  Suppose that
> I would like to create a new type, SingleAuthorPublication, that is
> based upon Publication and restricts the number of Authors to one.  My
> question is: how do I do it?  In SingleAuthorPublication do I simply
> need to show the changed element:
>
> <complexType name= "SingleAuthorPublication" base="cat:Publication"
>              derivedBy= "restriction">
>         <sequence>
>                 <element name="Author" type="string" maxOccurs="1"/>
>         </sequence>
> </complexType>
>
> Thus, this implies that the other elements (Title and Date) from the
> base type are unchanged.  Is this how to do it?
>
> The examples that I have seen in the Primer and in the Structures spec
> all repeat everything from the base type.  So, for my example I would
> have:
>
> <complexType name= "SingleAuthorPublication" base="cat:Publication"
>              derivedBy= "restriction">
>         <sequence>
>              <element name="Title" type="string" maxOccurs="unbounded"/>
>              <element name="Author" type="string" maxOccurs="1"/>
>              <element name="Date" type="year"/>
>         </sequence>
> </complexType>
>
> Is this how to do it, i.e., repeat everything from the base type?  (If
> this is the case, then, hey, what's the point in having a base type,
> i.e., where's the reuse?)
>
> I vaguely recall reading somewhere that in restriction you have to
> repeat all the element declarations in the base type up to the
> restricted element, and then you don't have to repeat the remainder of
> the base type elements. Is this how to do it? (If this is the case, then
> again, I see little reuse, especially if the restricted element is the
> last element.)
>
> What about attributes in the base type?  Do they need to be repeated in
> the restricted type?
>
> So, what I am really asking is for someone to list the rules in using
> restriction.
>
> Thanks.  /Roger
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
>
>