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 <[EMAIL PROTECTED]> wrote:

> Hi Stella,
>
> "Stella Lok" <[EMAIL PROTECTED]> 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 < [EMAIL PROTECTED]> 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:[EMAIL PROTECTED]
> > 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: [EMAIL PROTECTED]
> E-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to