Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » How to represent a sequence of element for complexTypes
How to represent a sequence of element for complexTypes [message #71245] Wed, 10 January 2007 13:33 Go to next message
Eclipse UserFriend
Originally posted by: milanmilanovich.yahooo.com

Hi,

how I can represent sequence of elements for complexTypes with XSD
metamodel ?

E.g. for:

<xs:complexType name="tCheckAvailability">
<xs:sequence>
<xs:element name="checkInDate" type="xs:date" />
<xs:element name="checkOutDate" type="xs:date" />
<xs:element name="roomType" type="xs:string" />
</xs:sequence>
</xs:complexType>

I don't see in XSDComplexTypeDefinition class how to represent sequence
of these elements ?

Thanks in advance.
Re: How to represent a sequence of element for complexTypes [message #71265 is a reply to message #71245] Wed, 10 January 2007 21:30 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: milanmilanovich.yahooo.com

I solved this using information in XML Schema Infoset Model Library
Diagrams. Sorry.
Re: How to represent a sequence of element for complexTypes [message #71285 is a reply to message #71245] Wed, 10 January 2007 22:30 Go to previous message
David Steinberg is currently offline David SteinbergFriend
Messages: 489
Registered: July 2009
Senior Member
Hi Milan,

The XSD metamodel corresponds very closely to the abstract model
described in the w3 spec at http://www.w3.org/TR/xmlschema-1/

This is a somewhat more complex than the concrete syntax. Your
particular example is represented as a model group with sequence
compositor that contains the element declarations. The model group and
element declarations are contained in particles.

Here's the code I would write to build a schema containing your complex
type:

XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
schema.setSchemaForSchemaQNamePrefix("xs");
schema.getQNamePrefixToNamespaceMap().put(
schema.getSchemaForSchemaQNamePrefix(),
XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);

XSDComplexTypeDefinition ct =
XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
ct.setName("tCheckAvailability");
schema.getContents().add(ct);

XSDParticle mgp = XSDFactory.eINSTANCE.createXSDParticle();
ct.setContent(mgp);

XSDModelGroup mg = XSDFactory.eINSTANCE.createXSDModelGroup();
mg.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
mgp.setContent(mg);

String[][] elements =
{
{ "checkInDate", "date" },
{ "checkOutDate", "date" },
{ "roomType", "string" }
};

for (int i = 0; i < elements.length; i++)
{
XSDElementDeclaration e =
XSDFactory.eINSTANCE.createXSDElementDeclaration();
e.setName(elements[i][0]);
e.setTypeDefinition(
schema.getSchemaForSchema().resolveTypeDefinition(elements[i ][1]));

XSDParticle ep = XSDFactory.eINSTANCE.createXSDParticle();
ep.setContent(e);
mg.getContents().add(ep);
}

I would recommend looking at org.eclipse.xsd.util.XSDPrototypicalSchema,
which illustrates the API in great detail. Here's the Javadoc for the
XSD model package:

http://download.eclipse.org/tools/emf/xsd/javadoc/2.3.0/

Finally, you can always write a schema, load it, and then debug to
discover how it was represented using the XSD model.

Cheers,
Dave


Milan Milanovic wrote:
> Hi,
>
> how I can represent sequence of elements for complexTypes with XSD
> metamodel ?
>
> E.g. for:
>
> <xs:complexType name="tCheckAvailability">
> <xs:sequence>
> <xs:element name="checkInDate" type="xs:date" />
> <xs:element name="checkOutDate" type="xs:date" />
> <xs:element name="roomType" type="xs:string" />
> </xs:sequence>
> </xs:complexType>
>
> I don't see in XSDComplexTypeDefinition class how to represent sequence
> of these elements ?
>
> Thanks in advance.
>
Re: How to represent a sequence of element for complexTypes [message #599435 is a reply to message #71245] Wed, 10 January 2007 21:30 Go to previous message
Eclipse UserFriend
Originally posted by: milanmilanovich.yahooo.com

I solved this using information in XML Schema Infoset Model Library
Diagrams. Sorry.
Re: How to represent a sequence of element for complexTypes [message #599439 is a reply to message #71245] Wed, 10 January 2007 22:30 Go to previous message
David Steinberg is currently offline David SteinbergFriend
Messages: 489
Registered: July 2009
Senior Member
Hi Milan,

The XSD metamodel corresponds very closely to the abstract model
described in the w3 spec at http://www.w3.org/TR/xmlschema-1/

This is a somewhat more complex than the concrete syntax. Your
particular example is represented as a model group with sequence
compositor that contains the element declarations. The model group and
element declarations are contained in particles.

Here's the code I would write to build a schema containing your complex
type:

XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();
schema.setSchemaForSchemaQNamePrefix("xs");
schema.getQNamePrefixToNamespaceMap().put(
schema.getSchemaForSchemaQNamePrefix(),
XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);

XSDComplexTypeDefinition ct =
XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
ct.setName("tCheckAvailability");
schema.getContents().add(ct);

XSDParticle mgp = XSDFactory.eINSTANCE.createXSDParticle();
ct.setContent(mgp);

XSDModelGroup mg = XSDFactory.eINSTANCE.createXSDModelGroup();
mg.setCompositor(XSDCompositor.SEQUENCE_LITERAL);
mgp.setContent(mg);

String[][] elements =
{
{ "checkInDate", "date" },
{ "checkOutDate", "date" },
{ "roomType", "string" }
};

for (int i = 0; i < elements.length; i++)
{
XSDElementDeclaration e =
XSDFactory.eINSTANCE.createXSDElementDeclaration();
e.setName(elements[i][0]);
e.setTypeDefinition(
schema.getSchemaForSchema().resolveTypeDefinition(elements[i ][1]));

XSDParticle ep = XSDFactory.eINSTANCE.createXSDParticle();
ep.setContent(e);
mg.getContents().add(ep);
}

I would recommend looking at org.eclipse.xsd.util.XSDPrototypicalSchema,
which illustrates the API in great detail. Here's the Javadoc for the
XSD model package:

http://download.eclipse.org/tools/emf/xsd/javadoc/2.3.0/

Finally, you can always write a schema, load it, and then debug to
discover how it was represented using the XSD model.

Cheers,
Dave


Milan Milanovic wrote:
> Hi,
>
> how I can represent sequence of elements for complexTypes with XSD
> metamodel ?
>
> E.g. for:
>
> <xs:complexType name="tCheckAvailability">
> <xs:sequence>
> <xs:element name="checkInDate" type="xs:date" />
> <xs:element name="checkOutDate" type="xs:date" />
> <xs:element name="roomType" type="xs:string" />
> </xs:sequence>
> </xs:complexType>
>
> I don't see in XSDComplexTypeDefinition class how to represent sequence
> of these elements ?
>
> Thanks in advance.
>
Previous Topic:How to represent a sequence of element for complexTypes
Next Topic:annotations of schema returning null
Goto Forum:
  


Current Time: Fri Mar 29 12:43:19 GMT 2024

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

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

Back to the top