Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » Processing complexTypes derived by extension
Processing complexTypes derived by extension [message #41942] Tue, 20 April 2004 20:03 Go to next message
Eclipse UserFriend
Originally posted by: adam.premasys.com

Hi,

I'm wanting to use the XSD API in building an application that allows a user
to build the messages
for a WSDL operation using a simple wizard-style interface. The initial
version of this application
doesn't need to validate the message created, it just needs to present to
the user text fields for entering
values for elements that have simpleTypes and selection lists for elements
with complexTypes where the
complexType is a base type with extended types. An example of such a base
type is shown below.

<xsd:complexType xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="Organisation">
<xsd:complexContent>
<xsd:extension base="Party">
<xsd:sequence>
<xsd:element name="numberOfEmployees" type="xsd:double"
minOccurs="0"/>
<xsd:element name="businessOrganisation" type="xsd:string"
minOccurs="0"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

The code below is based upon an example posted to this group previously. I'm
uncertain how I should extend this to handle the
extension case. An example of how to do this would be great.

Regards,
Adam
public void processType() {

XSDTypeDefinition definition = getTypeDefinition();

if (definition instanceof XSDSimpleTypeDefinition) {
XSDSimpleTypeDefinition xsdSimpleTypeDefinition =
(XSDSimpleTypeDefinition) definition;
// create element
} else {
XSDComplexTypeDefinition xsdComplexTypeDefinition =
(XSDComplexTypeDefinition) definition;
// create element
switch (xsdComplexTypeDefinition.getContentTypeCategory().getValue( )) {
case XSDContentTypeCategory.EMPTY :
break;
case XSDContentTypeCategory.SIMPLE :
XSDSimpleTypeDefinition xsdSimpleTypeDefinition =
(XSDSimpleTypeDefinition)
xsdComplexTypeDefinition.getContentType();
// create data
break;
case XSDContentTypeCategory.ELEMENT_ONLY :
case XSDContentTypeCategory.MIXED :
XSDParticle xsdParticle = (XSDParticle)
xsdComplexTypeDefinition.getContentType();
XSDTerm xsdTerm = xsdParticle.getTerm();
if (xsdTerm instanceof XSDModelGroup) {
XSDModelGroup xsdModelGroup = (XSDModelGroup) xsdTerm;
for (Iterator i = xsdModelGroup.getParticles().iterator();
i.hasNext();) {
XSDParticle childXSDParticle = (XSDParticle) i.next();
XSDTerm childTerm = childXSDParticle.getTerm();
if (childTerm instanceof XSDElementDeclaration) {
XSDElementDeclaration elDeclaration =
(XSDElementDeclaration) childTerm;
// create element, call back into function
}
}
} else if (xsdTerm instanceof XSDElementDeclaration) {
XSDElementDeclaration elDeclaration = (XSDElementDeclaration)
xsdTerm;
// create element, call back into function
} else if (xsdTerm instanceof XSDWildcard) {
}
break;
}
// process attributes
EList attrs = xsdComplexTypeDefinition.getAttributeUses();
Iterator it = attrs.iterator();
while(it.hasNext()) {
XSDAttributeUse attrUse = (XSDAttributeUse)it.next();
XSDAttributeDeclaration attr = attrUse.getAttributeDeclaration()
// create attribute
}
}
}
Re: Processing complexTypes derived by extension [message #41973 is a reply to message #41942] Tue, 20 April 2004 20:14 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Adam,

You shouldn't need to extend the code below to handle complex types with
extensions because getting the content type of a complex type will yield a
particle tree that already includes that of the base type. The code for handling
particles should be recursive though, because model groups can refer to model
groups, which can refer to model groups...

FYI, If you follow the EMF tutorial for generating a model from an XML Schema:

http://download.eclipse.org/tools/emf/scripts/docs.php?doc=t utorials/xlibmod/xlibmod.html

using your own schema, you'll generate a Eclipse-based editor that does exactly
what you say you are building...


Adam Ratcliffe wrote:

> Hi,
>
> I'm wanting to use the XSD API in building an application that allows a user
> to build the messages
> for a WSDL operation using a simple wizard-style interface. The initial
> version of this application
> doesn't need to validate the message created, it just needs to present to
> the user text fields for entering
> values for elements that have simpleTypes and selection lists for elements
> with complexTypes where the
> complexType is a base type with extended types. An example of such a base
> type is shown below.
>
> <xsd:complexType xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> name="Organisation">
> <xsd:complexContent>
> <xsd:extension base="Party">
> <xsd:sequence>
> <xsd:element name="numberOfEmployees" type="xsd:double"
> minOccurs="0"/>
> <xsd:element name="businessOrganisation" type="xsd:string"
> minOccurs="0"/>
> </xsd:sequence>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> The code below is based upon an example posted to this group previously. I'm
> uncertain how I should extend this to handle the
> extension case. An example of how to do this would be great.
>
> Regards,
> Adam
> public void processType() {
>
> XSDTypeDefinition definition = getTypeDefinition();
>
> if (definition instanceof XSDSimpleTypeDefinition) {
> XSDSimpleTypeDefinition xsdSimpleTypeDefinition =
> (XSDSimpleTypeDefinition) definition;
> // create element
> } else {
> XSDComplexTypeDefinition xsdComplexTypeDefinition =
> (XSDComplexTypeDefinition) definition;
> // create element
> switch (xsdComplexTypeDefinition.getContentTypeCategory().getValue( )) {
> case XSDContentTypeCategory.EMPTY :
> break;
> case XSDContentTypeCategory.SIMPLE :
> XSDSimpleTypeDefinition xsdSimpleTypeDefinition =
> (XSDSimpleTypeDefinition)
> xsdComplexTypeDefinition.getContentType();
> // create data
> break;
> case XSDContentTypeCategory.ELEMENT_ONLY :
> case XSDContentTypeCategory.MIXED :
> XSDParticle xsdParticle = (XSDParticle)
> xsdComplexTypeDefinition.getContentType();
> XSDTerm xsdTerm = xsdParticle.getTerm();
> if (xsdTerm instanceof XSDModelGroup) {
> XSDModelGroup xsdModelGroup = (XSDModelGroup) xsdTerm;
> for (Iterator i = xsdModelGroup.getParticles().iterator();
> i.hasNext();) {
> XSDParticle childXSDParticle = (XSDParticle) i.next();
> XSDTerm childTerm = childXSDParticle.getTerm();
> if (childTerm instanceof XSDElementDeclaration) {
> XSDElementDeclaration elDeclaration =
> (XSDElementDeclaration) childTerm;
> // create element, call back into function
> }
> }
> } else if (xsdTerm instanceof XSDElementDeclaration) {
> XSDElementDeclaration elDeclaration = (XSDElementDeclaration)
> xsdTerm;
> // create element, call back into function
> } else if (xsdTerm instanceof XSDWildcard) {
> }
> break;
> }
> // process attributes
> EList attrs = xsdComplexTypeDefinition.getAttributeUses();
> Iterator it = attrs.iterator();
> while(it.hasNext()) {
> XSDAttributeUse attrUse = (XSDAttributeUse)it.next();
> XSDAttributeDeclaration attr = attrUse.getAttributeDeclaration()
> // create attribute
> }
> }
> }
Re: Processing complexTypes derived by extension [message #585887 is a reply to message #41942] Tue, 20 April 2004 20:14 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 31562
Registered: July 2009
Senior Member
Adam,

You shouldn't need to extend the code below to handle complex types with
extensions because getting the content type of a complex type will yield a
particle tree that already includes that of the base type. The code for handling
particles should be recursive though, because model groups can refer to model
groups, which can refer to model groups...

FYI, If you follow the EMF tutorial for generating a model from an XML Schema:

http://download.eclipse.org/tools/emf/scripts/docs.php?doc=t utorials/xlibmod/xlibmod.html

using your own schema, you'll generate a Eclipse-based editor that does exactly
what you say you are building...


Adam Ratcliffe wrote:

> Hi,
>
> I'm wanting to use the XSD API in building an application that allows a user
> to build the messages
> for a WSDL operation using a simple wizard-style interface. The initial
> version of this application
> doesn't need to validate the message created, it just needs to present to
> the user text fields for entering
> values for elements that have simpleTypes and selection lists for elements
> with complexTypes where the
> complexType is a base type with extended types. An example of such a base
> type is shown below.
>
> <xsd:complexType xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> name="Organisation">
> <xsd:complexContent>
> <xsd:extension base="Party">
> <xsd:sequence>
> <xsd:element name="numberOfEmployees" type="xsd:double"
> minOccurs="0"/>
> <xsd:element name="businessOrganisation" type="xsd:string"
> minOccurs="0"/>
> </xsd:sequence>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> The code below is based upon an example posted to this group previously. I'm
> uncertain how I should extend this to handle the
> extension case. An example of how to do this would be great.
>
> Regards,
> Adam
> public void processType() {
>
> XSDTypeDefinition definition = getTypeDefinition();
>
> if (definition instanceof XSDSimpleTypeDefinition) {
> XSDSimpleTypeDefinition xsdSimpleTypeDefinition =
> (XSDSimpleTypeDefinition) definition;
> // create element
> } else {
> XSDComplexTypeDefinition xsdComplexTypeDefinition =
> (XSDComplexTypeDefinition) definition;
> // create element
> switch (xsdComplexTypeDefinition.getContentTypeCategory().getValue( )) {
> case XSDContentTypeCategory.EMPTY :
> break;
> case XSDContentTypeCategory.SIMPLE :
> XSDSimpleTypeDefinition xsdSimpleTypeDefinition =
> (XSDSimpleTypeDefinition)
> xsdComplexTypeDefinition.getContentType();
> // create data
> break;
> case XSDContentTypeCategory.ELEMENT_ONLY :
> case XSDContentTypeCategory.MIXED :
> XSDParticle xsdParticle = (XSDParticle)
> xsdComplexTypeDefinition.getContentType();
> XSDTerm xsdTerm = xsdParticle.getTerm();
> if (xsdTerm instanceof XSDModelGroup) {
> XSDModelGroup xsdModelGroup = (XSDModelGroup) xsdTerm;
> for (Iterator i = xsdModelGroup.getParticles().iterator();
> i.hasNext();) {
> XSDParticle childXSDParticle = (XSDParticle) i.next();
> XSDTerm childTerm = childXSDParticle.getTerm();
> if (childTerm instanceof XSDElementDeclaration) {
> XSDElementDeclaration elDeclaration =
> (XSDElementDeclaration) childTerm;
> // create element, call back into function
> }
> }
> } else if (xsdTerm instanceof XSDElementDeclaration) {
> XSDElementDeclaration elDeclaration = (XSDElementDeclaration)
> xsdTerm;
> // create element, call back into function
> } else if (xsdTerm instanceof XSDWildcard) {
> }
> break;
> }
> // process attributes
> EList attrs = xsdComplexTypeDefinition.getAttributeUses();
> Iterator it = attrs.iterator();
> while(it.hasNext()) {
> XSDAttributeUse attrUse = (XSDAttributeUse)it.next();
> XSDAttributeDeclaration attr = attrUse.getAttributeDeclaration()
> // create attribute
> }
> }
> }


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Processing complexTypes derived by extension
Next Topic:short question on minOccurs and maxOccurs on XSDElementDeclaration
Goto Forum:
  


Current Time: Sat Oct 31 04:30:58 GMT 2020

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

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

Back to the top