| 
| get min or max occurs [message #60210] | Thu, 28 April 2005 11:21  |  | 
| Eclipse User  |  |  |  |  | Originally posted by: aaudevart.genigraph.fr 
 Hi,
 
 I am trying to extract the min and max occurs but I don't know what
 interface i need use to get the max and min occurence.
 <xs:element name="child_name" type="xs:string" minOccurs="0"
 maxOccurs="5"/>
 
 Can somebody help me please?
 Thanks.
 |  |  |  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
|  | 
| 
| Re: get min or max occurs [message #60393 is a reply to message #60348] | Mon, 02 May 2005 07:30  |  | 
| Eclipse User  |  |  |  |  | Hi Alex, 
 starting with the element "toto" you get your desired information as
 follows:
 
 XSDComplexTypeDefinition ct =
 (XSDComplexTypeDefinition)element.getTypeDefinition();
 
 
 Now ct should be the complex type "Items". To get the particle you have to
 examine the content of the type. So you have to retrieve the complex
 content:
 
 XSDComplexTypeContent content = ct.getContentType();
 if (content instanceof XSDSimpleTypeDefinition) {
 // The content is a simple type. So the complexType describes a
 // text node with possiblly additional attributes
 ...
 } else if (content instanceof XSDParticle) {
 // The particle of the xs:sequence.
 processParticle((XSDParticle)content);
 }
 
 
 Now you should have the particle of the first xs:sequence. In
 processParticle you now further iterate over the hierarchy in the schema:
 
 public void processParticle(XSDParticle particle) {
 int minOccurs = particle.getMinOccurs();
 int maxOccurs = particle.getMaxOccurs();
 
 XSDParticleContent content = particle.getContent();
 if (content instanceof XSDElementDeclaration) {
 // The particle contains an element, i.e. your "item"-element or
 // "productName"-element
 processElement((XSDElementDeclaration)content);
 } else if (content instanceof XSDModelGroup) {
 // The particle contains a model group, i.e. a choice,
 // a sequence, ...
 processModelGroup((XSDModelGroup)content);
 } else if (...) {
 ...
 }
 }
 
 
 The first time you call processParticle you will pass a XSDModelGroup (the
 xs:sequence). There you have to iterate over all the particles contained in
 the sequence:
 
 public void processModelGroup(XSDModelGroup group) {
 EList particleList = group.getContents();
 for (Iterator i = particleList.iterator(); i.hasNext();) {
 XSDParticle particle = (XSDParticle)i.next();
 processParticle(particle);
 }
 }
 
 
 The first particle processed by processModelGroup will be your
 "item"-element. So if you call processParticle again you will now have the
 particle containing the "item"-element.
 
 
 Some advice on how to use the XSD JavaDoc and understanding the different
 interfaces of XSD:
 
 1) As it is in the schema file: an element is an element, a complex
 type is a complex type, ... And there is no way of converting between
 them. Instead you have to read the correct properties of the objects.
 
 2) At the top of each XSD interface description you will find "All Known
 Subinterfaces". For example you will see that an XSDParticleContent may
 be an element declaration or model group.
 
 3) The names of interfaces and functions are closeley related to the
 terminology used in the original W3C specification of XML Schema. Often
 the XSD JavaDoc links to the corresponding section in the W3C
 specification. So if it isn't obvious what the XSD JavaDoc tries to
 tell: Have a look at the W3C spec. You find the English version at
 http://www.w3.org/TR/xmlschema-1/ and a French version at
 http://xmlfr.org/w3c/TR/xmlschema-1/.
 
 
 Cheers
 Klaas
 |  |  |  | 
| 
| Re: get min or max occurs [message #595214 is a reply to message #60210] | Thu, 28 April 2005 11:31  |  | 
| Eclipse User  |  |  |  |  | Alex, 
 A local element declaration or element reference gives rise to both an
 XSDParticle and an XSDElementDeclaration and you should look for the min
 and max on the particle.
 
 
 Alex wrote:
 
 > Hi,
 >
 > I am trying to extract the min and max occurs but I don't know what
 > interface i need use to get the max and min occurence.
 > <xs:element name="child_name" type="xs:string" minOccurs="0"
 > maxOccurs="5"/>
 >
 > Can somebody help me please?
 > Thanks.
 >
 |  |  |  | 
| 
| Re: get min or max occurs [message #595225 is a reply to message #60234] | Thu, 28 April 2005 11:59  |  | 
| Eclipse User  |  |  |  |  | I find a method which return a XSDParticle : 
 XSDSimpleTypeDefinition aSimpleType
 XSDParticle particle = aSimpleType.getComplexType();
 
 but the particule is always null.
 May be it isn't the right method.
 
 Here is my xsd code:
 <?xml version="1.0" encoding="ISO-8859-1"?>
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 elementFormDefault="qualified">
 
 <xs:element name="persons">
 <xs:complexType>
 <xs:sequence>
 <xs:element name="person" maxOccurs="unbounded">
 <xs:complexType>
 <xs:sequence>
 <xs:element name="full_name" type="xs:string"/>
 <xs:element name="child_name" type="xs:string"
 minOccurs="0" maxOccurs="5"/>
 </xs:sequence>
 </xs:complexType>
 </xs:element>
 </xs:sequence>
 </xs:complexType>
 </xs:element>
 
 </xs:schema>
 
 Thanks.
 |  |  |  | 
| 
| Re: get min or max occurs [message #595235 is a reply to message #60258] | Thu, 28 April 2005 12:33  |  | 
| Eclipse User  |  |  |  |  | Alex, 
 This method applied to a simple type definition will return null; a
 simple type does not have complex content.  When applied to a complex
 type, it will return the particle, as long as the type doesn't have
 empty content or simple content, in which cases there is no particle.
 
 
 Alex wrote:
 
 > I find a method which return a XSDParticle :
 >
 > XSDSimpleTypeDefinition aSimpleType
 > XSDParticle particle = aSimpleType.getComplexType();
 >
 > but the particule is always null.
 > May be it isn't the right method.
 >
 > Here is my xsd code:
 > <?xml version="1.0" encoding="ISO-8859-1"?>
 > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 > elementFormDefault="qualified">
 >
 > <xs:element name="persons">
 >  <xs:complexType>
 >    <xs:sequence>
 >      <xs:element name="person" maxOccurs="unbounded">
 >        <xs:complexType>
 >          <xs:sequence>
 >            <xs:element name="full_name" type="xs:string"/>
 >            <xs:element name="child_name" type="xs:string"
 >            minOccurs="0" maxOccurs="5"/>
 >          </xs:sequence>
 >        </xs:complexType>
 >      </xs:element>
 >    </xs:sequence>
 >  </xs:complexType>
 > </xs:element>
 >
 > </xs:schema>
 >
 > Thanks.
 >
 >
 >
 >
 >
 |  |  |  | 
| 
| Re: get min or max occurs [message #595249 is a reply to message #60280] | Fri, 29 April 2005 03:29  |  | 
| Eclipse User  |  |  |  |  | Hi, 
 In my case, I've got a simple type so how can i extract the min and max
 occurs?
 
 I understand that this :  <xs:element name="full_name" type="xs:string"/>
 is a simple type and this is a complex type : <xs:element name="full_name"
 type="bobi"/>.
 
 Is it exact?
 Thanks
 |  |  |  | 
| 
| Re: get min or max occurs [message #595259 is a reply to message #60304] | Fri, 29 April 2005 07:13  |  | 
| Eclipse User  |  |  |  |  | Alex, 
 A simple type doesn't have min and max occurs.   Both things you show
 are element declarations.   So I'm quite confused...
 
 In your earlier example you had an element called "persons" with an
 anonymous complex type, so given the element declaration for "persons"
 you could do xsdElementDeclaration.getType().getComplexType() to get the
 root particular of the element's type; you'll get null unless it is a
 complex type with complex content.  Walking this particle tree will get
 you to the "person" element nested in that type.
 
 
 Alex wrote:
 
 > Hi,
 >
 > In my case, I've got a simple type so how can i extract the min and
 > max occurs?
 >
 > I understand that this :  <xs:element name="full_name"
 > type="xs:string"/> is a simple type and this is a complex type :
 > <xs:element name="full_name" type="bobi"/>.
 >
 > Is it exact?
 > Thanks
 >
 >
 |  |  |  | 
| 
| Re: get min or max occurs [message #595270 is a reply to message #60327] | Mon, 02 May 2005 04:55  |  | 
| Eclipse User  |  |  |  |  | Hi, 
 Two possibilities, may be i don't understand what you explain to me or it
 isn't working!
 
 So if i want to extract the cardinality of "item" which are 0 and 5.
 
 
 <?xml version="1.0" encoding="ISO-8859-1"?>
 
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 elementFormDefault="qualified">
 
 <xs:element name="toto" type="Items"/>
 
 <xs:complexType name="Items">
 <xs:sequence>
 <xs:element name="item" minOccurs="0" maxOccurs="5">
 <xs:complexType>
 <xs:sequence>
 <xs:element name="productName" type="xs:string"/>
 </xs:sequence>
 </xs:complexType>
 </xs:element>
 </xs:sequence>
 </xs:complexType>
 
 </xs:schema>
 
 I do that :
 
 aComplexType is a XSDComplexTypeDefinition
 So :
 XSDParticle particle = aComplexType.getComplexType();
 int min = particle.getMinOccurs()
 int max =  particle.getMaxOccurs()
 
 But the problem is that min and max are always equals to 1 and 1.
 
 Thanks for your help
 |  |  |  | 
| 
| Re: get min or max occurs [message #595283 is a reply to message #60348] | Mon, 02 May 2005 06:29  |  | 
| Eclipse User  |  |  |  |  | Alex, 
 You'll find the the top level particle of a complex type has a term that
 is a sequence and that this sequence contains the particles you are
 interested in.  I.e., stop and think about how it would work if you have
 two elements rather than just one in your complex type.
 
 
 Alex wrote:
 
 > Hi,
 >
 > Two possibilities, may be i don't understand what you explain to me or
 > it isn't working!
 >
 > So if i want to extract the cardinality of "item" which are 0 and 5.
 >
 >
 > <?xml version="1.0" encoding="ISO-8859-1"?>
 >
 >    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 > elementFormDefault="qualified">
 >     <xs:element name="toto" type="Items"/>
 >     <xs:complexType name="Items">
 >     <xs:sequence>
 >       <xs:element name="item" minOccurs="0" maxOccurs="5">
 >         <xs:complexType>
 >           <xs:sequence>
 >              <xs:element name="productName" type="xs:string"/>
 >           </xs:sequence>
 >         </xs:complexType>
 >       </xs:element>
 >     </xs:sequence>
 >   </xs:complexType>
 >
 > </xs:schema>
 >
 > I do that :
 >
 >      aComplexType is a XSDComplexTypeDefinition
 > So :
 >      XSDParticle particle = aComplexType.getComplexType();
 >      int min = particle.getMinOccurs()
 >      int max =  particle.getMaxOccurs()
 >
 > But the problem is that min and max are always equals to 1 and 1.
 >
 > Thanks for your help
 >
 >
 >
 >
 |  |  |  | 
| 
| Re: get min or max occurs [message #595293 is a reply to message #60348] | Mon, 02 May 2005 07:30  |  | 
| Eclipse User  |  |  |  |  | Hi Alex, 
 starting with the element "toto" you get your desired information as
 follows:
 
 XSDComplexTypeDefinition ct =
 (XSDComplexTypeDefinition)element.getTypeDefinition();
 
 
 Now ct should be the complex type "Items". To get the particle you have to
 examine the content of the type. So you have to retrieve the complex
 content:
 
 XSDComplexTypeContent content = ct.getContentType();
 if (content instanceof XSDSimpleTypeDefinition) {
 // The content is a simple type. So the complexType describes a
 // text node with possiblly additional attributes
 ...
 } else if (content instanceof XSDParticle) {
 // The particle of the xs:sequence.
 processParticle((XSDParticle)content);
 }
 
 
 Now you should have the particle of the first xs:sequence. In
 processParticle you now further iterate over the hierarchy in the schema:
 
 public void processParticle(XSDParticle particle) {
 int minOccurs = particle.getMinOccurs();
 int maxOccurs = particle.getMaxOccurs();
 
 XSDParticleContent content = particle.getContent();
 if (content instanceof XSDElementDeclaration) {
 // The particle contains an element, i.e. your "item"-element or
 // "productName"-element
 processElement((XSDElementDeclaration)content);
 } else if (content instanceof XSDModelGroup) {
 // The particle contains a model group, i.e. a choice,
 // a sequence, ...
 processModelGroup((XSDModelGroup)content);
 } else if (...) {
 ...
 }
 }
 
 
 The first time you call processParticle you will pass a XSDModelGroup (the
 xs:sequence). There you have to iterate over all the particles contained in
 the sequence:
 
 public void processModelGroup(XSDModelGroup group) {
 EList particleList = group.getContents();
 for (Iterator i = particleList.iterator(); i.hasNext();) {
 XSDParticle particle = (XSDParticle)i.next();
 processParticle(particle);
 }
 }
 
 
 The first particle processed by processModelGroup will be your
 "item"-element. So if you call processParticle again you will now have the
 particle containing the "item"-element.
 
 
 Some advice on how to use the XSD JavaDoc and understanding the different
 interfaces of XSD:
 
 1) As it is in the schema file: an element is an element, a complex
 type is a complex type, ... And there is no way of converting between
 them. Instead you have to read the correct properties of the objects.
 
 2) At the top of each XSD interface description you will find "All Known
 Subinterfaces". For example you will see that an XSDParticleContent may
 be an element declaration or model group.
 
 3) The names of interfaces and functions are closeley related to the
 terminology used in the original W3C specification of XML Schema. Often
 the XSD JavaDoc links to the corresponding section in the W3C
 specification. So if it isn't obvious what the XSD JavaDoc tries to
 tell: Have a look at the W3C spec. You find the English version at
 http://www.w3.org/TR/xmlschema-1/ and a French version at
 http://xmlfr.org/w3c/TR/xmlschema-1/
 
 
 Cheers
 Klaas
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.07367 seconds