How to represent a sequence of element for complexTypes [message #71245] |
Wed, 10 January 2007 13:33 |
Eclipse User |
|
|
|
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 #71285 is a reply to message #71245] |
Wed, 10 January 2007 22:30 |
David Steinberg 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 #599439 is a reply to message #71245] |
Wed, 10 January 2007 22:30 |
David Steinberg 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.
>
|
|
|
Powered by
FUDForum. Page generated in 0.03264 seconds