Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » how to get ALL element declarations ?
how to get ALL element declarations ? [message #73198] Wed, 24 October 2007 06:28 Go to next message
Eclipse User
Originally posted by: t.agnoloni.gmail.com

Hi,

how can I get ALL and not only top-level element declarations from a
schema ?

Using XSDSchema.getElementDeclarations()

for the example below

only returns the element named "sizes"

and not the ones defined inside the following complex type definitions

Thanks.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="sizes" type="SizesType"/>

<xs:complexType name="SizesType">
<xs:choice maxOccurs="unbounded">
<xs:element name="dressSize" type="DressSizeType"/>
<xs:element name="mediumDressSize" type="MediumDressSizeType"/>
</xs:choice>
</xs:complexType>

<xs:simpleType name="DressSizeType">
<xs:restriction base="xs:integer">
<xs:minInclusive value="2"/>
<xs:maxInclusive value="18"/>
<xs:pattern value="\d{1,2}"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="MediumDressSizeType">
<xs:restriction base="DressSizeType">
<xs:minInclusive value="8"/>
<xs:maxInclusive value="12"/>
</xs:restriction>
</xs:simpleType>


</xs:schema>
Re: how to get ALL element declarations ? [message #73215 is a reply to message #73198] Wed, 24 October 2007 08:05 Go to previous messageGo to next message
Eclipse User
Originally posted by: merks.ca.ibm.com

Tomasso,

You'll need to walk the deep structure of all element declarations
(including their anonymous complex types), all complex type definitions
(in particular their particle contents and of course recursively the
anonymous complex types of the element declarations), and all model
group definitions (in particular, the model group's contents).


Tommaso wrote:
> Hi,
>
> how can I get ALL and not only top-level element declarations from a
> schema ?
>
> Using XSDSchema.getElementDeclarations()
>
> for the example below
>
> only returns the element named "sizes"
>
> and not the ones defined inside the following complex type definitions
>
> Thanks.
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>
> <xs:element name="sizes" type="SizesType"/>
>
> <xs:complexType name="SizesType">
> <xs:choice maxOccurs="unbounded">
> <xs:element name="dressSize" type="DressSizeType"/>
> <xs:element name="mediumDressSize" type="MediumDressSizeType"/>
> </xs:choice>
> </xs:complexType>
>
> <xs:simpleType name="DressSizeType">
> <xs:restriction base="xs:integer">
> <xs:minInclusive value="2"/>
> <xs:maxInclusive value="18"/>
> <xs:pattern value="\d{1,2}"/>
> </xs:restriction>
> </xs:simpleType>
>
> <xs:simpleType name="MediumDressSizeType">
> <xs:restriction base="DressSizeType">
> <xs:minInclusive value="8"/>
> <xs:maxInclusive value="12"/>
> </xs:restriction>
> </xs:simpleType>
>
>
> </xs:schema>
>
Re: how to get ALL element declarations ? [message #73529 is a reply to message #73215] Fri, 14 December 2007 12:39 Go to previous messageGo to next message
Eclipse User
Originally posted by: t.agnoloni.gmail.com

Ok, thanks. It works.

However I have a new question.

How can I discard top level elements (already gathered with
schema.getElementDeclarations() ) when looking for non top level elements
navigating into i.e. complexTypeDefinitions ?

I would use the condition
!elemDecl.isElementDeclarationReference()
to collect the not referred elements

but the ref="topLevelElement" attribute seems to be already resolved when
I get into a term of type XSDElementDeclaration in a complexTypeDefinition.

Any hint?

I'm using the following code. Thank you very much for your help.


private void getNonTopLevelElements(XSDTypeDefinition typedef){

if (typedef instanceof XSDSimpleTypeDefinition){
System.err.println("SIMPLE TYPE cannot contain element");
}
else if (typedef instanceof XSDComplexTypeDefinition){

if(typedef.getComplexType()!=null){
XSDComplexTypeDefinitionImpl typedefimpl=
(XSDComplexTypeDefinitionImpl)typedef;
System.err.println("---------> ANALYZING TYPEDEF
"+typedefimpl.getName());

if
(typedefimpl.getContentTypeCategory()==XSDContentTypeCategor y.ELEMENT_ONLY_LITERAL
||
typedefimpl.getContentTypeCategory()==XSDContentTypeCategory .MIXED_LITERAL){

XSDTerm term =
((XSDParticleImpl)typedefimpl.getContentType()).getTerm();
getNonTopLevelElementForTerm(term);
}
}
}
}





private void getNonTopLevelElementForTerm(XSDTerm term){

if(term instanceof XSDElementDeclaration){ // ELEMENT
XSDElementDeclaration elemDecl=(XSDElementDeclaration)term;
if(!elemDecl.isElementDeclarationReference()){
allElements.add(elemDecl);
System.err.println("found NON TOP LEVEL "+elemDecl.getQName()+" ref=
"+elemDecl.isElementDeclarationReference());

}
else
System.err.println("found REFERRED "+elemDecl.getQName());
}
else if(term instanceof XSDModelGroup){ // CHOICE,
SEQUENCE
XSDModelGroup modelGroup=(XSDModelGroup)term;
List list = modelGroup.getParticles();
for (Iterator i = list.iterator();i.hasNext();){
XSDParticleImpl particle=(XSDParticleImpl) i.next();
getNonTopLevelElementForTerm(particle.getTerm());
}
}else if(term instanceof XSDWildcard){
System.out.println("XSDWildcard");
}else{
System.out.println("XSDTermIMpl");
}
}
Re: how to get ALL element declarations ? [message #73547 is a reply to message #73529] Fri, 14 December 2007 14:10 Go to previous message
Eclipse User
Originally posted by: merks.ca.ibm.com

Tommaso,

Comments below.

Tommaso wrote:
> Ok, thanks. It works.
>
> However I have a new question.
>
> How can I discard top level elements (already gathered with
> schema.getElementDeclarations() ) when looking for non top level
> elements navigating into i.e. complexTypeDefinitions ?
> I would use the condition
> !elemDecl.isElementDeclarationReference()
> to collect the not referred elements
> but the ref="topLevelElement" attribute seems to be already resolved
> when I get into a term of type XSDElementDeclaration in a
> complexTypeDefinition.
In the code below I see that you are using things like getTerm which
does indeed resolve the reference so you'll already be looking at the
global element declaration directly. You can use
XSDFeature.getScope() or even XSDConcreteComponent.getContainer to see
if the element declaration is contained directly by an XSDSchema as
opposed to being contained by a particle in a complex type or model
group definition.
>
> Any hint?
>
> I'm using the following code. Thank you very much for your help.
>
>
> private void getNonTopLevelElements(XSDTypeDefinition typedef){
>
> if (typedef instanceof XSDSimpleTypeDefinition){
> System.err.println("SIMPLE TYPE cannot contain
> element");
> }
> else if (typedef instanceof XSDComplexTypeDefinition){
>
> if(typedef.getComplexType()!=null){
> XSDComplexTypeDefinitionImpl typedefimpl=
> (XSDComplexTypeDefinitionImpl)typedef;
> System.err.println("---------> ANALYZING
> TYPEDEF "+typedefimpl.getName());
>
> if
> (typedefimpl.getContentTypeCategory()==XSDContentTypeCategor y.ELEMENT_ONLY_LITERAL
>
> ||
> typedefimpl.getContentTypeCategory()==XSDContentTypeCategory .MIXED_LITERAL){
>
>
> XSDTerm term =
> ((XSDParticleImpl)typedefimpl.getContentType()).getTerm();
> getNonTopLevelElementForTerm(term);
> } }
> } }
>
>
>
>
>
> private void getNonTopLevelElementForTerm(XSDTerm term){
>
> if(term instanceof
> XSDElementDeclaration){ // ELEMENT
> XSDElementDeclaration
> elemDecl=(XSDElementDeclaration)term;
> if(!elemDecl.isElementDeclarationReference()){
> allElements.add(elemDecl);
> System.err.println("found NON TOP LEVEL
> "+elemDecl.getQName()+" ref= "+elemDecl.isElementDeclarationReference());
>
> }
> else
> System.err.println("found REFERRED
> "+elemDecl.getQName());
> }
> else if(term instanceof
> XSDModelGroup){ // CHOICE,
> SEQUENCE XSDModelGroup
> modelGroup=(XSDModelGroup)term;
> List list = modelGroup.getParticles();
> for (Iterator i = list.iterator();i.hasNext();){
> XSDParticleImpl particle=(XSDParticleImpl) i.next();
> getNonTopLevelElementForTerm(particle.getTerm());
> }
> }else if(term instanceof XSDWildcard){
> System.out.println("XSDWildcard");
> }else{
> System.out.println("XSDTermIMpl");
> }
> }
>
Re: how to get ALL element declarations ? [message #602676 is a reply to message #73198] Wed, 24 October 2007 08:05 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26011
Registered: July 2009
Senior Member
Tomasso,

You'll need to walk the deep structure of all element declarations
(including their anonymous complex types), all complex type definitions
(in particular their particle contents and of course recursively the
anonymous complex types of the element declarations), and all model
group definitions (in particular, the model group's contents).


Tommaso wrote:
> Hi,
>
> how can I get ALL and not only top-level element declarations from a
> schema ?
>
> Using XSDSchema.getElementDeclarations()
>
> for the example below
>
> only returns the element named "sizes"
>
> and not the ones defined inside the following complex type definitions
>
> Thanks.
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>
> <xs:element name="sizes" type="SizesType"/>
>
> <xs:complexType name="SizesType">
> <xs:choice maxOccurs="unbounded">
> <xs:element name="dressSize" type="DressSizeType"/>
> <xs:element name="mediumDressSize" type="MediumDressSizeType"/>
> </xs:choice>
> </xs:complexType>
>
> <xs:simpleType name="DressSizeType">
> <xs:restriction base="xs:integer">
> <xs:minInclusive value="2"/>
> <xs:maxInclusive value="18"/>
> <xs:pattern value="\d{1,2}"/>
> </xs:restriction>
> </xs:simpleType>
>
> <xs:simpleType name="MediumDressSizeType">
> <xs:restriction base="DressSizeType">
> <xs:minInclusive value="8"/>
> <xs:maxInclusive value="12"/>
> </xs:restriction>
> </xs:simpleType>
>
>
> </xs:schema>
>
Re: how to get ALL element declarations ? [message #602775 is a reply to message #73215] Fri, 14 December 2007 12:39 Go to previous message
Tommaso is currently offline Tommaso
Messages: 6
Registered: July 2009
Junior Member
Ok, thanks. It works.

However I have a new question.

How can I discard top level elements (already gathered with
schema.getElementDeclarations() ) when looking for non top level elements
navigating into i.e. complexTypeDefinitions ?

I would use the condition
!elemDecl.isElementDeclarationReference()
to collect the not referred elements

but the ref="topLevelElement" attribute seems to be already resolved when
I get into a term of type XSDElementDeclaration in a complexTypeDefinition.

Any hint?

I'm using the following code. Thank you very much for your help.


private void getNonTopLevelElements(XSDTypeDefinition typedef){

if (typedef instanceof XSDSimpleTypeDefinition){
System.err.println("SIMPLE TYPE cannot contain element");
}
else if (typedef instanceof XSDComplexTypeDefinition){

if(typedef.getComplexType()!=null){
XSDComplexTypeDefinitionImpl typedefimpl=
(XSDComplexTypeDefinitionImpl)typedef;
System.err.println("---------> ANALYZING TYPEDEF
"+typedefimpl.getName());

if
(typedefimpl.getContentTypeCategory()==XSDContentTypeCategor y.ELEMENT_ONLY_LITERAL
||
typedefimpl.getContentTypeCategory()==XSDContentTypeCategory .MIXED_LITERAL){

XSDTerm term =
((XSDParticleImpl)typedefimpl.getContentType()).getTerm();
getNonTopLevelElementForTerm(term);
}
}
}
}





private void getNonTopLevelElementForTerm(XSDTerm term){

if(term instanceof XSDElementDeclaration){ // ELEMENT
XSDElementDeclaration elemDecl=(XSDElementDeclaration)term;
if(!elemDecl.isElementDeclarationReference()){
allElements.add(elemDecl);
System.err.println("found NON TOP LEVEL "+elemDecl.getQName()+" ref=
"+elemDecl.isElementDeclarationReference());

}
else
System.err.println("found REFERRED "+elemDecl.getQName());
}
else if(term instanceof XSDModelGroup){ // CHOICE,
SEQUENCE
XSDModelGroup modelGroup=(XSDModelGroup)term;
List list = modelGroup.getParticles();
for (Iterator i = list.iterator();i.hasNext();){
XSDParticleImpl particle=(XSDParticleImpl) i.next();
getNonTopLevelElementForTerm(particle.getTerm());
}
}else if(term instanceof XSDWildcard){
System.out.println("XSDWildcard");
}else{
System.out.println("XSDTermIMpl");
}
}
Re: how to get ALL element declarations ? [message #602781 is a reply to message #73529] Fri, 14 December 2007 14:10 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26011
Registered: July 2009
Senior Member
Tommaso,

Comments below.

Tommaso wrote:
> Ok, thanks. It works.
>
> However I have a new question.
>
> How can I discard top level elements (already gathered with
> schema.getElementDeclarations() ) when looking for non top level
> elements navigating into i.e. complexTypeDefinitions ?
> I would use the condition
> !elemDecl.isElementDeclarationReference()
> to collect the not referred elements
> but the ref="topLevelElement" attribute seems to be already resolved
> when I get into a term of type XSDElementDeclaration in a
> complexTypeDefinition.
In the code below I see that you are using things like getTerm which
does indeed resolve the reference so you'll already be looking at the
global element declaration directly. You can use
XSDFeature.getScope() or even XSDConcreteComponent.getContainer to see
if the element declaration is contained directly by an XSDSchema as
opposed to being contained by a particle in a complex type or model
group definition.
>
> Any hint?
>
> I'm using the following code. Thank you very much for your help.
>
>
> private void getNonTopLevelElements(XSDTypeDefinition typedef){
>
> if (typedef instanceof XSDSimpleTypeDefinition){
> System.err.println("SIMPLE TYPE cannot contain
> element");
> }
> else if (typedef instanceof XSDComplexTypeDefinition){
>
> if(typedef.getComplexType()!=null){
> XSDComplexTypeDefinitionImpl typedefimpl=
> (XSDComplexTypeDefinitionImpl)typedef;
> System.err.println("---------> ANALYZING
> TYPEDEF "+typedefimpl.getName());
>
> if
> (typedefimpl.getContentTypeCategory()==XSDContentTypeCategor y.ELEMENT_ONLY_LITERAL
>
> ||
> typedefimpl.getContentTypeCategory()==XSDContentTypeCategory .MIXED_LITERAL){
>
>
> XSDTerm term =
> ((XSDParticleImpl)typedefimpl.getContentType()).getTerm();
> getNonTopLevelElementForTerm(term);
> } }
> } }
>
>
>
>
>
> private void getNonTopLevelElementForTerm(XSDTerm term){
>
> if(term instanceof
> XSDElementDeclaration){ // ELEMENT
> XSDElementDeclaration
> elemDecl=(XSDElementDeclaration)term;
> if(!elemDecl.isElementDeclarationReference()){
> allElements.add(elemDecl);
> System.err.println("found NON TOP LEVEL
> "+elemDecl.getQName()+" ref= "+elemDecl.isElementDeclarationReference());
>
> }
> else
> System.err.println("found REFERRED
> "+elemDecl.getQName());
> }
> else if(term instanceof
> XSDModelGroup){ // CHOICE,
> SEQUENCE XSDModelGroup
> modelGroup=(XSDModelGroup)term;
> List list = modelGroup.getParticles();
> for (Iterator i = list.iterator();i.hasNext();){
> XSDParticleImpl particle=(XSDParticleImpl) i.next();
> getNonTopLevelElementForTerm(particle.getTerm());
> }
> }else if(term instanceof XSDWildcard){
> System.out.println("XSDWildcard");
> }else{
> System.out.println("XSDTermIMpl");
> }
> }
>
Previous Topic:[Announce] Joint Eclipse/OMG Symposia
Next Topic:[Announce] IMM component proposal
Goto Forum:
  


Current Time: Thu Aug 28 03:29:39 EDT 2014

Powered by FUDForum. Page generated in 0.02308 seconds