Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » Choice within a sequence
Choice within a sequence [message #68927] Wed, 26 July 2006 15:58 Go to next message
Stuart Stephen is currently offline Stuart Stephen
Messages: 22
Registered: July 2009
Junior Member
Hi,

I am trying to work out how I can use emf xsd to create the following
snippet of XML. I just cannot work it out at the moment.

<xs:element name="itemName">
<xs:complexType>
<xs:sequence>
<xs:element name="ref"/>
<xs:choice>
<xs:element name="a"/>
<xs:element name="b"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>

Everything is fine until I try to create choice part. How can I add a
choice to the sequence using the Java API?

Thanks,
Stuart
Re: Choice within a sequence [message #68949 is a reply to message #68927] Wed, 26 July 2006 16:49 Go to previous messageGo to next message
Stuart Stephen is currently offline Stuart Stephen
Messages: 22
Registered: July 2009
Junior Member
I see that "choice within a sequence" should have been supported in EMF
2.0.

http://www.codegeneration.net/tiki-read_article.php?articleI d=38

The immortal words of Dave Steinberg were:

"Work on EMF 2.0 is progressing, and we should start making builds
available in the near future. The biggest improvement will be in the
Ecore representation of models described using XML Schema, which will be
able to represent mixed content and more complex model groups, like a
choice within a sequence. The goal is to fully support all features of
XML Schema."

I am assuming that since I am now using EMF 2.2.0 this should be available
to me?

I would be very thankful for any help on this matter.

Thanks,
Stuart
Re: Choice within a sequence [message #68970 is a reply to message #68927] Wed, 26 July 2006 17:21 Go to previous messageGo to next message
Eclipse User
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------070401030901040001060606
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Stuart,

If, after this line in
XSDPrototypicalSchema.initializeSimpleRecursiveModelGroupDef inition,

// Add the wildcard particle to the model group.
//
modelGroup.getContents().add(wildcardParticle);

I add the following:

XSDParticle choiceParticle = xsdFactory.createXSDParticle();
XSDModelGroup choiceGroup = xsdFactory.createXSDModelGroup();
choiceGroup.setCompositor(XSDCompositor.CHOICE_LITERAL);
choiceParticle.setContent(choiceGroup);
modelGroup.getContents().add(choiceParticle);

this result is produced:

<xsd:group name="simpleRecursiveModelGroupDefinition">
<xsd:annotation/>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0"
ref="PTS:simpleRecursiveElementDeclaration"/>
<xsd:any namespace="##other" processContents="lax"/>
<xsd:choice/>
</xsd:sequence>
</xsd:group>


Stuart Stephen wrote:

> Hi,
>
> I am trying to work out how I can use emf xsd to create the following
> snippet of XML. I just cannot work it out at the moment.
>
> <xs:element name="itemName">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="ref"/>
> <xs:choice>
> <xs:element name="a"/>
> <xs:element name="b"/>
> </xs:choice>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
> Everything is fine until I try to create choice part. How can I add a
> choice to the sequence using the Java API?
>
> Thanks,
> Stuart
>


--------------070401030901040001060606
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Stuart,<br>
<br>
If, after this line in
XSDPrototypicalSchema.initializeSimpleRecursiveModelGroupDef inition, <br>
<blockquote>
Re: Choice within a sequence [message #68991 is a reply to message #68949] Wed, 26 July 2006 17:37 Go to previous messageGo to next message
Eclipse User
Originally posted by: merks.ca.ibm.com

Stuart,

This discussion was related to mapping XML Schema to Ecore. The XSD
model has always supported being able to produce any syntactically valid
XML Schema instance.


Stuart Stephen wrote:

> I see that "choice within a sequence" should have been supported in
> EMF 2.0.
>
> http://www.codegeneration.net/tiki-read_article.php?articleI d=38
>
> The immortal words of Dave Steinberg were:
>
> "Work on EMF 2.0 is progressing, and we should start making builds
> available in the near future. The biggest improvement will be in the
> Ecore representation of models described using XML Schema, which will
> be able to represent mixed content and more complex model groups, like
> a choice within a sequence. The goal is to fully support all features
> of XML Schema."
>
> I am assuming that since I am now using EMF 2.2.0 this should be
> available to me?
>
> I would be very thankful for any help on this matter.
>
> Thanks,
> Stuart
>
Re: Choice within a sequence [message #69033 is a reply to message #68970] Thu, 27 July 2006 07:50 Go to previous messageGo to next message
Stuart Stephen is currently offline Stuart Stephen
Messages: 22
Registered: July 2009
Junior Member
Hi Ed,

Thanks for the response. I'm looking at the answer and I'm left somewhat
scratching my head. I've tried it and it worked fine, what I'm not sure
about is how I didn't end up with the same end result yesterday. I think
my problem must have been that was that I was assigning it to the
complexType and therefore the sequence was being substituted with the
choice.

Works a treat.

Thanks a lot,
Stuart
Re: Choice within a sequence [message #69053 is a reply to message #69033] Thu, 27 July 2006 08:08 Go to previous messageGo to next message
Stuart Stephen is currently offline Stuart Stephen
Messages: 22
Registered: July 2009
Junior Member
I originally tried to do the following where
nameAndAddressHdrAnonymousTypeModelGroup is of type XSDModelGroup:

XSDModelGroup choice =
XSDSchemaBuildingTools.addModelGroupDefinition(nameAndAddres sHdrAnonymousTypeModelGroup,
"subtypes", XSDCompositor.CHOICE_LITERAL, new Vector());

This came back to me with an IllegalArgumentException
"addModelGroupDefinition doesn't know how to add it to component:
org.eclipse.xsd.impl.XSDModelGroupImpl@3df3db (element: [xs:sequence:
null]) (compositor: sequence)"

Looking at the code that you provided it looks as though the
XSDSchemaBuildingTools method is incomplete.

// Add the group either to a type by adding it as a
// particle or to a schema by adding a definition
if (component instanceof XSDComplexTypeDefinition)
{
XSDParticle modelGroupParticle = xsdFactory.createXSDParticle();
modelGroupParticle.setContent(modelGroup);
((XSDComplexTypeDefinition)component).setContent(modelGroupP article);

}
else if (component instanceof XSDSchema)
{
XSDModelGroupDefinition modelGroupDef =
xsdFactory.createXSDModelGroupDefinition();
modelGroupDef.setName(localName);
modelGroupDef.setModelGroup(modelGroup);
((XSDSchema)component).getContents().add(modelGroupDef);
}
else
{
throw new IllegalArgumentException("addModelGroupDefinition doesn't
know how to add it to component: " + component);
}

Should this have an instanceof clause for XSDModelGroup too?

Thanks,
Stuart
Re: Choice within a sequence [message #69073 is a reply to message #69053] Thu, 27 July 2006 08:20 Go to previous messageGo to next message
Stuart Stephen is currently offline Stuart Stephen
Messages: 22
Registered: July 2009
Junior Member
In XSDSchemaBuildingTools.addModelGroupDefinition(..) I have put the code:

else if(component instanceof XSDModelGroup)
{
XSDParticle particle = xsdFactory.createXSDParticle();
particle.setContent(modelGroup);
((XSDModelGroup)component).getContents().add(particle);
}

This works fine. Perhaps I could suggest it as a change to
XSDSchemaBuildingTools.java.

Thanks,
Stuart
Re: Choice within a sequence [message #69116 is a reply to message #69073] Thu, 27 July 2006 10:53 Go to previous message
Eclipse User
Originally posted by: merks.ca.ibm.com

Stuart,

Please open a bugzilla and I'll make that change.


Stuart Stephen wrote:
> In XSDSchemaBuildingTools.addModelGroupDefinition(..) I have put the
> code:
>
> else if(component instanceof XSDModelGroup)
> {
> XSDParticle particle = xsdFactory.createXSDParticle();
> particle.setContent(modelGroup);
> ((XSDModelGroup)component).getContents().add(particle);
> }
>
> This works fine. Perhaps I could suggest it as a change to
> XSDSchemaBuildingTools.java.
>
> Thanks,
> Stuart
>
Re: Choice within a sequence [message #598467 is a reply to message #68927] Wed, 26 July 2006 16:49 Go to previous message
Stuart Stephen is currently offline Stuart Stephen
Messages: 22
Registered: July 2009
Junior Member
I see that "choice within a sequence" should have been supported in EMF
2.0.

http://www.codegeneration.net/tiki-read_article.php?articleI d=38

The immortal words of Dave Steinberg were:

"Work on EMF 2.0 is progressing, and we should start making builds
available in the near future. The biggest improvement will be in the
Ecore representation of models described using XML Schema, which will be
able to represent mixed content and more complex model groups, like a
choice within a sequence. The goal is to fully support all features of
XML Schema."

I am assuming that since I am now using EMF 2.2.0 this should be available
to me?

I would be very thankful for any help on this matter.

Thanks,
Stuart
Re: Choice within a sequence [message #598473 is a reply to message #68927] Wed, 26 July 2006 17:21 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26137
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070401030901040001060606
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit

Stuart,

If, after this line in
XSDPrototypicalSchema.initializeSimpleRecursiveModelGroupDef inition,

// Add the wildcard particle to the model group.
//
modelGroup.getContents().add(wildcardParticle);

I add the following:

XSDParticle choiceParticle = xsdFactory.createXSDParticle();
XSDModelGroup choiceGroup = xsdFactory.createXSDModelGroup();
choiceGroup.setCompositor(XSDCompositor.CHOICE_LITERAL);
choiceParticle.setContent(choiceGroup);
modelGroup.getContents().add(choiceParticle);

this result is produced:

<xsd:group name="simpleRecursiveModelGroupDefinition">
<xsd:annotation/>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0"
ref="PTS:simpleRecursiveElementDeclaration"/>
<xsd:any namespace="##other" processContents="lax"/>
<xsd:choice/>
</xsd:sequence>
</xsd:group>


Stuart Stephen wrote:

> Hi,
>
> I am trying to work out how I can use emf xsd to create the following
> snippet of XML. I just cannot work it out at the moment.
>
> <xs:element name="itemName">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="ref"/>
> <xs:choice>
> <xs:element name="a"/>
> <xs:element name="b"/>
> </xs:choice>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
> Everything is fine until I try to create choice part. How can I add a
> choice to the sequence using the Java API?
>
> Thanks,
> Stuart
>


--------------070401030901040001060606
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-15"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Stuart,<br>
<br>
If, after this line in
XSDPrototypicalSchema.initializeSimpleRecursiveModelGroupDef inition, <br>
<blockquote>
Re: Choice within a sequence [message #598480 is a reply to message #68949] Wed, 26 July 2006 17:37 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26137
Registered: July 2009
Senior Member
Stuart,

This discussion was related to mapping XML Schema to Ecore. The XSD
model has always supported being able to produce any syntactically valid
XML Schema instance.


Stuart Stephen wrote:

> I see that "choice within a sequence" should have been supported in
> EMF 2.0.
>
> http://www.codegeneration.net/tiki-read_article.php?articleI d=38
>
> The immortal words of Dave Steinberg were:
>
> "Work on EMF 2.0 is progressing, and we should start making builds
> available in the near future. The biggest improvement will be in the
> Ecore representation of models described using XML Schema, which will
> be able to represent mixed content and more complex model groups, like
> a choice within a sequence. The goal is to fully support all features
> of XML Schema."
>
> I am assuming that since I am now using EMF 2.2.0 this should be
> available to me?
>
> I would be very thankful for any help on this matter.
>
> Thanks,
> Stuart
>
Re: Choice within a sequence [message #598492 is a reply to message #68970] Thu, 27 July 2006 07:50 Go to previous message
Stuart Stephen is currently offline Stuart Stephen
Messages: 22
Registered: July 2009
Junior Member
Hi Ed,

Thanks for the response. I'm looking at the answer and I'm left somewhat
scratching my head. I've tried it and it worked fine, what I'm not sure
about is how I didn't end up with the same end result yesterday. I think
my problem must have been that was that I was assigning it to the
complexType and therefore the sequence was being substituted with the
choice.

Works a treat.

Thanks a lot,
Stuart
Re: Choice within a sequence [message #598499 is a reply to message #69033] Thu, 27 July 2006 08:08 Go to previous message
Stuart Stephen is currently offline Stuart Stephen
Messages: 22
Registered: July 2009
Junior Member
I originally tried to do the following where
nameAndAddressHdrAnonymousTypeModelGroup is of type XSDModelGroup:

XSDModelGroup choice =
XSDSchemaBuildingTools.addModelGroupDefinition(nameAndAddres sHdrAnonymousTypeModelGroup,
"subtypes", XSDCompositor.CHOICE_LITERAL, new Vector());

This came back to me with an IllegalArgumentException
"addModelGroupDefinition doesn't know how to add it to component:
org.eclipse.xsd.impl.XSDModelGroupImpl@3df3db (element: [xs:sequence:
null]) (compositor: sequence)"

Looking at the code that you provided it looks as though the
XSDSchemaBuildingTools method is incomplete.

// Add the group either to a type by adding it as a
// particle or to a schema by adding a definition
if (component instanceof XSDComplexTypeDefinition)
{
XSDParticle modelGroupParticle = xsdFactory.createXSDParticle();
modelGroupParticle.setContent(modelGroup);
((XSDComplexTypeDefinition)component).setContent(modelGroupP article);

}
else if (component instanceof XSDSchema)
{
XSDModelGroupDefinition modelGroupDef =
xsdFactory.createXSDModelGroupDefinition();
modelGroupDef.setName(localName);
modelGroupDef.setModelGroup(modelGroup);
((XSDSchema)component).getContents().add(modelGroupDef);
}
else
{
throw new IllegalArgumentException("addModelGroupDefinition doesn't
know how to add it to component: " + component);
}

Should this have an instanceof clause for XSDModelGroup too?

Thanks,
Stuart
Re: Choice within a sequence [message #598505 is a reply to message #69053] Thu, 27 July 2006 08:20 Go to previous message
Stuart Stephen is currently offline Stuart Stephen
Messages: 22
Registered: July 2009
Junior Member
In XSDSchemaBuildingTools.addModelGroupDefinition(..) I have put the code:

else if(component instanceof XSDModelGroup)
{
XSDParticle particle = xsdFactory.createXSDParticle();
particle.setContent(modelGroup);
((XSDModelGroup)component).getContents().add(particle);
}

This works fine. Perhaps I could suggest it as a change to
XSDSchemaBuildingTools.java.

Thanks,
Stuart
Re: Choice within a sequence [message #598517 is a reply to message #69073] Thu, 27 July 2006 10:53 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26137
Registered: July 2009
Senior Member
Stuart,

Please open a bugzilla and I'll make that change.


Stuart Stephen wrote:
> In XSDSchemaBuildingTools.addModelGroupDefinition(..) I have put the
> code:
>
> else if(component instanceof XSDModelGroup)
> {
> XSDParticle particle = xsdFactory.createXSDParticle();
> particle.setContent(modelGroup);
> ((XSDModelGroup)component).getContents().add(particle);
> }
>
> This works fine. Perhaps I could suggest it as a change to
> XSDSchemaBuildingTools.java.
>
> Thanks,
> Stuart
>
Previous Topic:Choice within a sequence
Next Topic:how to create a xml schema for ecore metamodel
Goto Forum:
  


Current Time: Thu Oct 23 12:42:13 GMT 2014

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

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