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




Reply via email to