You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Stella Lok <oi...@gmail.com> on 2007/11/29 13:25:14 UTC

How to get minOccurs and maxOccurs values from Element Declarations

Hi,

I would like to ask how one can retrieve the minOccurs and maxOccurs values
from an element declaration (whether it is is a simple type or is referring
to a simpleType/complexType).
>From what I've found in the Xerces API, getMinOccurs() and getMaxOccurs()
are only defined in XSParticle.

Would greatly appreciate if someone could point me in the right direction!

Thanks,
Stella

Re: How to get minOccurs and maxOccurs values from Element Declarations

Posted by Stella Lok <oi...@gmail.com>.
I understand now, thanks a lot for your kind help! I had been stumped by
this.

Sincerely,
Stella

On Nov 30, 2007 2:37 AM, Michael Glavassevich <mr...@ca.ibm.com> wrote:

> Hi Stella,
>
> "Stella Lok" <oi...@gmail.com> wrote on 11/29/2007 12:42:13 PM:
>
> > Hi Ed and Michael,
> >
> > Thank you very much for taking the time to explain the structure to
> > me! I am still unclear on 2 specific cases though, and that is when
> > an element declaration is a simple type.
> >
> > Case 1:
> >
> > <xs:element name="simpleElement" minOccurs="0" and maxOccurs="2">
> >    <xs:simpleType>
> >         ....
> >    </xs:simpleType>
> > </xs:element>
> >
> > I can't figure out how to obtain the minOccurs and maxOccurs values
> > for simpleElement, since there is no particle for a simpleType?
>
> That element declaration is only legal if its enclosed in a complex type,
> in other words a local element declaration. You need to walk the enclosing
> complex type (XSElementDeclaration.getEnclosingCTDefinition() will get you
> that) and find the particle containing this element declaration. The code
> which Ed posted shows how to do that.
>
> > Case 2:
> >
> > <xs:element name="simpleElement">
> >    <xs:simpleType>
> >        <xs:restriction base="xs:integer">
> >             <xs:minInclusive value="0"/>
> >         </xs:restriction>
> >     </xs:simpleType>
> > </xs:element>
> >
> > <xs:element name="element2" ref="simpleElement" minOccurs="0" and
> > maxOccurs="2">
> > </xs:element>
> >
> > I suspect that the use of ref means that the full definition of
> > element2 becomes (pardon my lack of proper terms):
> > <xs:element name="element2" minOccurs="0" and maxOccurs="2">
> >       <xs:complexType>
> >             <xs:element type="simpleElement"/>
> >       </xs:complexType>
> > </xs:element>
>
> It doesn't mean anything because it's not legal anywhere in a schema
> document. You can never specify both "name" and "ref" on xs:element.
>
> > i.e, there is an anonymous complexType and it contains the particle
> > that defines the occurrences.
> >
> >
> > I would really like to find out about Case 1, and also seek
> > confirmation on Case 2.
> > Thanks very much!
> >
> > Sincerely,
> > Stella
> >
> >
>
> > On Nov 30, 2007 1:15 AM, Wax, Ed < Ed_Wax@csgsystems.com> wrote:
> > Stella,
> > It is not as straight forward as one might image.  Assuming you have
> > navigated to a complex type:
> >
> > XSComplexTypeDefinition complex;   // is set to the current complex
> type.
> >
> > XSParticle p = complex.getParticle();
> > XSTerm term = p.getTerm();
> > XSModelGroup xm = (XSModelGroup)term;
> > XSObjectList xobj = xm.getParticles();
> >
> > for (int i = 0; i < xobj.getLength(); ++i) {
> >     XSParticle xp = (XSParticle)xobj.item(i);
> >     XSTerm t = xp.getTerm();
> >     if (t instanceof XSElementDeclaration) {
> >         XSElementDeclaration elem = (XSElementDeclaration)t;
> >
> >         // At this point we know the particle is an element.
> >         // Here we can query for optionality info from the partical.
> >         if ( xp != null ) {
> >             isOptional = xp.getMinOccurs() == 0;
> >             // Check here for MaxOccurs as well.
> >         }
> >     }
> > }
> >
> > Hope this helps.
> >
> > Ed
> >
> > From: Stella Lok [mailto:oinvertedworld@gmail.com]
> > Sent: Thursday, November 29, 2007 5:25 AM
> > To: j-users@xerces.apache.org
> > Subject: How to get minOccurs and maxOccurs values from Element
> Declarations
> >
> > Hi,
> >
> > I would like to ask how one can retrieve the minOccurs and maxOccurs
> > values from an element declaration (whether it is is a simple type
> > or is referring to a simpleType/complexType).
> > From what I've found in the Xerces API, getMinOccurs() and
> > getMaxOccurs() are only defined in XSParticle.
> >
> > Would greatly appreciate if someone could point me in the right
> direction!
> >
> > Thanks,
> > Stella
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
>
>

Re: How to get minOccurs and maxOccurs values from Element Declarations

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Stella,

"Stella Lok" <oi...@gmail.com> wrote on 11/29/2007 12:42:13 PM:

> Hi Ed and Michael,
>
> Thank you very much for taking the time to explain the structure to
> me! I am still unclear on 2 specific cases though, and that is when
> an element declaration is a simple type.
>
> Case 1:
>
> <xs:element name="simpleElement" minOccurs="0" and maxOccurs="2">
>    <xs:simpleType>
>         ....
>    </xs:simpleType>
> </xs:element>
>
> I can't figure out how to obtain the minOccurs and maxOccurs values
> for simpleElement, since there is no particle for a simpleType?

That element declaration is only legal if its enclosed in a complex type,
in other words a local element declaration. You need to walk the enclosing
complex type (XSElementDeclaration.getEnclosingCTDefinition() will get you
that) and find the particle containing this element declaration. The code
which Ed posted shows how to do that.

> Case 2:
>
> <xs:element name="simpleElement">
>    <xs:simpleType>
>        <xs:restriction base="xs:integer">
>             <xs:minInclusive value="0"/>
>         </xs:restriction>
>     </xs:simpleType>
> </xs:element>
>
> <xs:element name="element2" ref="simpleElement" minOccurs="0" and
> maxOccurs="2">
> </xs:element>
>
> I suspect that the use of ref means that the full definition of
> element2 becomes (pardon my lack of proper terms):
> <xs:element name="element2" minOccurs="0" and maxOccurs="2">
>       <xs:complexType>
>             <xs:element type="simpleElement"/>
>       </xs:complexType>
> </xs:element>

It doesn't mean anything because it's not legal anywhere in a schema
document. You can never specify both "name" and "ref" on xs:element.

> i.e, there is an anonymous complexType and it contains the particle
> that defines the occurrences.
>
>
> I would really like to find out about Case 1, and also seek
> confirmation on Case 2.
> Thanks very much!
>
> Sincerely,
> Stella
>
>

> On Nov 30, 2007 1:15 AM, Wax, Ed < Ed_Wax@csgsystems.com> wrote:
> Stella,
> It is not as straight forward as one might image.  Assuming you have
> navigated to a complex type:
>
> XSComplexTypeDefinition complex;   // is set to the current complex type.
>
> XSParticle p = complex.getParticle();
> XSTerm term = p.getTerm();
> XSModelGroup xm = (XSModelGroup)term;
> XSObjectList xobj = xm.getParticles();
>
> for (int i = 0; i < xobj.getLength(); ++i) {
>     XSParticle xp = (XSParticle)xobj.item(i);
>     XSTerm t = xp.getTerm();
>     if (t instanceof XSElementDeclaration) {
>         XSElementDeclaration elem = (XSElementDeclaration)t;
>
>         // At this point we know the particle is an element.
>         // Here we can query for optionality info from the partical.
>         if ( xp != null ) {
>             isOptional = xp.getMinOccurs() == 0;
>             // Check here for MaxOccurs as well.
>         }
>     }
> }
>
> Hope this helps.
>
> Ed
>
> From: Stella Lok [mailto:oinvertedworld@gmail.com]
> Sent: Thursday, November 29, 2007 5:25 AM
> To: j-users@xerces.apache.org
> Subject: How to get minOccurs and maxOccurs values from Element
Declarations
>
> Hi,
>
> I would like to ask how one can retrieve the minOccurs and maxOccurs
> values from an element declaration (whether it is is a simple type
> or is referring to a simpleType/complexType).
> From what I've found in the Xerces API, getMinOccurs() and
> getMaxOccurs() are only defined in XSParticle.
>
> Would greatly appreciate if someone could point me in the right
direction!
>
> Thanks,
> Stella

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: How to get minOccurs and maxOccurs values from Element Declarations

Posted by Stella Lok <oi...@gmail.com>.
Hi Ed and Michael,

Thank you very much for taking the time to explain the structure to me! I am
still unclear on 2 specific cases though, and that is when an element
declaration is a simple type.

Case 1:

<xs:element name="simpleElement" minOccurs="0" and maxOccurs="2">
   <xs:simpleType>
        ....
   </xs:simpleType>
</xs:element>

I can't figure out how to obtain the minOccurs and maxOccurs values for
simpleElement, since there is no particle for a simpleType?


Case 2:

<xs:element name="simpleElement">
   <xs:simpleType>
       <xs:restriction base="xs:integer">
            <xs:minInclusive value="0"/>
        </xs:restriction>
    </xs:simpleType>
</xs:element>

<xs:element name="element2" ref="simpleElement" minOccurs="0" and
maxOccurs="2">
</xs:element>

I suspect that the use of ref means that the full definition of element2
becomes (pardon my lack of proper terms):
<xs:element name="element2" minOccurs="0" and maxOccurs="2">
      <xs:complexType>
            <xs:element type="simpleElement"/>
      </xs:complexType>
</xs:element>

i.e, there is an anonymous complexType and it contains the particle that
defines the occurrences.


I would really like to find out about Case 1, and also seek confirmation on
Case 2.
Thanks very much!

Sincerely,
Stella



On Nov 30, 2007 1:15 AM, Wax, Ed <Ed...@csgsystems.com> wrote:

>  Stella,
>
> It is not as straight forward as one might image.  Assuming you have
> navigated to a complex type:
>
>
>
> XSComplexTypeDefinition complex;   // is set to the current complex type.
>
>
>
> XSParticle p = complex.getParticle();
>
> XSTerm term = p.getTerm();
>
> XSModelGroup xm = (XSModelGroup)term;
>
> XSObjectList xobj = xm.getParticles();
>
>
>
> for (int i = 0; i < xobj.getLength(); ++i) {
>
>     XSParticle xp = (XSParticle)xobj.item(i);
>
>     XSTerm t = xp.getTerm();
>
>     if (t instanceof XSElementDeclaration) {
>
>         XSElementDeclaration elem = (XSElementDeclaration)t;
>
>
>
>         // At this point we know the particle is an element.
>
>         // Here we can query for optionality info from the partical.
>
>         if ( xp != null ) {
>
>             isOptional = xp.getMinOccurs() == 0;
>
>             // Check here for MaxOccurs as well.
>
>         }
>
>     }
>
> }
>
>
>
> Hope this helps.
>
>
>
> Ed
>
>
>
> *From:* Stella Lok [mailto:oinvertedworld@gmail.com]
> *Sent:* Thursday, November 29, 2007 5:25 AM
> *To:* j-users@xerces.apache.org
> *Subject:* How to get minOccurs and maxOccurs values from Element
> Declarations
>
>
>
> Hi,
>
> I would like to ask how one can retrieve the minOccurs and maxOccurs
> values from an element declaration (whether it is is a simple type or is
> referring to a simpleType/complexType).
> From what I've found in the Xerces API, getMinOccurs() and getMaxOccurs()
> are only defined in XSParticle.
>
> Would greatly appreciate if someone could point me in the right direction!
>
> Thanks,
> Stella
>
>
>

RE: How to get minOccurs and maxOccurs values from Element Declarations

Posted by "Wax, Ed" <Ed...@csgsystems.com>.
Stella,

It is not as straight forward as one might image.  Assuming you have
navigated to a complex type:

 

XSComplexTypeDefinition complex;   // is set to the current complex
type.

 

XSParticle p = complex.getParticle();

XSTerm term = p.getTerm();

XSModelGroup xm = (XSModelGroup)term;

XSObjectList xobj = xm.getParticles();

 

for (int i = 0; i < xobj.getLength(); ++i) {

    XSParticle xp = (XSParticle)xobj.item(i);

    XSTerm t = xp.getTerm();

    if (t instanceof XSElementDeclaration) {

        XSElementDeclaration elem = (XSElementDeclaration)t;

 

        // At this point we know the particle is an element.

        // Here we can query for optionality info from the partical.

        if ( xp != null ) {

            isOptional = xp.getMinOccurs() == 0;

            // Check here for MaxOccurs as well.

        }

    }

}

 

Hope this helps.

 

Ed

 

From: Stella Lok [mailto:oinvertedworld@gmail.com] 
Sent: Thursday, November 29, 2007 5:25 AM
To: j-users@xerces.apache.org
Subject: How to get minOccurs and maxOccurs values from Element
Declarations

 

Hi,

I would like to ask how one can retrieve the minOccurs and maxOccurs
values from an element declaration (whether it is is a simple type or is
referring to a simpleType/complexType).
>From what I've found in the Xerces API, getMinOccurs() and
getMaxOccurs() are only defined in XSParticle. 

Would greatly appreciate if someone could point me in the right
direction!

Thanks,
Stella





Re: How to get minOccurs and maxOccurs values from Element Declarations

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Stella,

You're asking for something you can't get.

Consider that one element declaration could be used in multiple places:

<xs:element name="foo" type="xs:string"/>
<xs:complexType name="bar">
 <xs:sequence>
  ...
  <xs:element ref="foo" minOccurs="2" maxOccurs="4"/>
 </xs:sequence>
</xs:complexType>
<xs:complexType name="baz">
 <xs:sequence>
  ...
  <xs:element ref="foo" minOccurs="3" maxOccurs="5"/>
 </xs:sequence>
</xs:complexType>

It's the particle (i.e. the usage of the element declaration) [1] which
holds the occurrence information not the element declaration itself.

Thanks.

[1] http://www.w3.org/TR/xmlschema-1/#cParticles

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

"Stella Lok" <oi...@gmail.com> wrote on 11/29/2007 07:25:14 AM:

> Hi,
>
> I would like to ask how one can retrieve the minOccurs and maxOccurs
> values from an element declaration (whether it is is a simple type
> or is referring to a simpleType/complexType).
> From what I've found in the Xerces API, getMinOccurs() and
> getMaxOccurs() are only defined in XSParticle.
>
> Would greatly appreciate if someone could point me in the right
direction!
>
> Thanks,
> Stella


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org