Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » get min or max occurs
get min or max occurs [message #60210] Thu, 28 April 2005 15:21 Go to next message
Eclipse UserFriend
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 #60234 is a reply to message #60210] Thu, 28 April 2005 15:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

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 #60258 is a reply to message #60234] Thu, 28 April 2005 15:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aaudevart.genigraph.fr

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 #60280 is a reply to message #60258] Thu, 28 April 2005 16:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

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 #60304 is a reply to message #60280] Fri, 29 April 2005 07:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aaudevart.genigraph.fr

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 #60327 is a reply to message #60304] Fri, 29 April 2005 11:13 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

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 #60348 is a reply to message #60327] Mon, 02 May 2005 08:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: aaudevart.genigraph.fr

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 #60371 is a reply to message #60348] Mon, 02 May 2005 10:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

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 #60393 is a reply to message #60348] Mon, 02 May 2005 11:30 Go to previous message
Klaas Dellschaft is currently offline Klaas DellschaftFriend
Messages: 58
Registered: July 2009
Member
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 15:31 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
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.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: get min or max occurs [message #595225 is a reply to message #60234] Thu, 28 April 2005 15:59 Go to previous message
Alex is currently offline AlexFriend
Messages: 65
Registered: July 2009
Member
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 16:33 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
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.
>
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: get min or max occurs [message #595249 is a reply to message #60280] Fri, 29 April 2005 07:29 Go to previous message
Alex is currently offline AlexFriend
Messages: 65
Registered: July 2009
Member
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 11:13 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
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
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: get min or max occurs [message #595270 is a reply to message #60327] Mon, 02 May 2005 08:55 Go to previous message
Alex is currently offline AlexFriend
Messages: 65
Registered: July 2009
Member
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 10:29 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
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
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: get min or max occurs [message #595293 is a reply to message #60348] Mon, 02 May 2005 11:30 Go to previous message
Klaas Dellschaft is currently offline Klaas DellschaftFriend
Messages: 58
Registered: July 2009
Member
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
Previous Topic:get min or max occurs
Next Topic:How to extract values of maxOccurs and minOccurs ?
Goto Forum:
  


Current Time: Thu Mar 28 10:10:57 GMT 2024

Powered by FUDForum. Page generated in 0.03800 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top