Hi Nicolas,

Particles are not part of the PSVI in XML Schema 1.0. You would have to
walk back up to the complex type definition (see getEnclosingCTDefinition()
on XSElementDeclaration) then search for the particle which points to the
element declaration within that complex type definition. Note that this
doesn't always work (could have multiple particles pointing to the same
global element declaration) but is about the best you can do unless you're
willing to build a state machine to keep track of where you are in the
schema grammar.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [email protected]
E-mail: [email protected]

"Zeitlin, Nicolas" <[email protected]> wrote on 03/30/2010
05:30:49 PM:

> Hi guys,
>
> I have read the past threads regarding minimum and maximum
> occurrences? attributes, but I think I?ve stumbled with a new
> troublesome scenario.
>
> I?m working with a schema that allows multiple instances
> (maxOccurs=?unbounded?) of different elements. The following snippet
> should be enough to illustrate:
>
>         <xs:element name="bag" maxOccurs="unbounded">
>           <xs:complexType>
>             <xs:sequence>>
>               <xs:element name="pocket" maxOccurs="unbounded">
>                 <xs:complexType>
>                     <xs:sequence>
>                       <xs:element name="item" maxOccurs="unbounded">
>                         <xs:complexType>
>                           <xs:attribute name="name" type="xs:string"/>
>                         </xs:complexType>
>                       </xs:element>
>                     </xs:sequence>>
>                   <xs:attribute name="name" type="xs:string"/>
>                 </xs:complexType>
>               </xs:element>
>             </xs:sequence>>
>             <xs:attribute name="name" type="xs:string"/>
>           </xs:complexType>
>         </xs:element>
>
>
> As you can see from the code above, all three elements, the bag, the
> pocket, and the item are allowed to repeat themselves indefinitely.
> However, when retrieving the Element Type Information from within
> the xerces code, I am not being able to retrieve the item particle
> information. Indeed, if I rewrite the pocket so that it has no
> embedded sub-element, then it is the pocket element the one with no
> particle. For all I can tell from the tests I have done, the last
> element in the hierarchy (i.e. the element with no further nested
> sub-elements) has no particles, and therefore no available
> maxOccurs/minOccurs information.
>
> I?m retrieving the occurrence information form within my own content
> handler, from where I have overridden the startElement() and
> included the following snippet:
>
> XSParticle p = ((XSComplexTypeDefinition)provider.getElementTypeInfo
> ()).getParticle();
> int maxOccurs = ((XSParticleDecl)p).maxEffectiveTotalRange();
>
> As I was saying earlier, the particle itself is not available in the
> last element of the hierarchy, so the maxOccurs is unavailable. Has
> anyone stumbled with this before? Is there another way to retrieve
> the attribute, whether it?s through the particle or not?
> Thanks in advance,
> Nicolas Zeitlin

Reply via email to