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 <[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
>
>
>

Reply via email to