Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL XSD EMF]: How to convert a xsd schema file to XMI formatted file
[ATL XSD EMF]: How to convert a xsd schema file to XMI formatted file [message #82986] Fri, 30 May 2008 14:15 Go to next message
Eclipse UserFriend
Originally posted by: David-392.Li.MorganStanley.com

Hi all,

We have requiremnets to do xml schema conversion between xsd and XMI
formatted. The following code shows how we try to convert a xsd schema to
a XMI formatted file (which conforms to the XSD.ecore model), but the
result file seems not right. I am wondering where the problem is? Maybe
the way I am doing this is wrong? Is there any good way to do such
conversion? What I know is that the XSD package does not use XMI
serialization.

The code:
---
private static void xsd2xmi() throws IOException
{
ResourceSet metaResourceSet = new ResourceSetImpl();

metaResourceSet.getResourceFactoryRegistry().getExtensionToF actoryMap().put(
"xmi", new XMIResourceFactoryImpl());

metaResourceSet.getResourceFactoryRegistry().getExtensionToF actoryMap().put(
"xsd", new XSDResourceFactoryImpl());

URI uriXsd = URI.createFileURI("C:/scheduleXsd.xsd");
Resource r = metaResourceSet.getResource(uriXsd, true);
r.load(null);
XSDSchema schema = null;
if ( r instanceof XSDResourceImpl) {
XSDResourceImpl rXSD = (XSDResourceImpl) r ;
schema = rXSD.getSchema();
}
URI uriXMI = URI.createFileURI("C:/scheduleXmi.xmi");
Resource rXMI = metaResourceSet.createResource(uriXMI);
rXMI.getContents().add(schema);
rXMI.save(null);
}

----

The scheduleXsd.xsd is;
--
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0"
targetNamespace=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:complexType name="schedule">
<xsd:sequence>
<xsd:element name="scheduleId" type="xsd:string" minOccurs="0"/>
<xsd:element name="price" type="xsd:double" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
-----

The output scheduleXmi.xmi is
---
<?xml version="1.0" encoding="ASCII"?>
<xsd:XSDSchema xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.eclipse.org/xsd/2002/XSD" element="[xsd:schema:
null]" document="[#document: null]"
schemaLocation=" file:/C:/p4shadow/m2m/atlPrototype-interop-v1_4-schedule-v2. xsd "
targetNamespace=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0"
attributeFormDefault="unqualified" elementFormDefault="qualified"
typeDefinitions="//schedule;XSDComplexTypeDefinition">
<contents xsi:type="xsd:XSDComplexTypeDefinition"
element="[xsd:complexType: null]" name="schedule"
targetNamespace=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0"
aliasName="schedule"
uRI=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0#schedule"
aliasURI=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0#schedule"
qName="tns:schedule" contentTypeCategory="elementOnly"
contentType="//schedule;XSDComplexTypeDefinition/XSDParticle ">
<baseTypeDefinition xsi:type="xsd:XSDComplexTypeDefinition"
href=" jar:file:/C:/dev/tools/eclipseide/3.3prod/eclipse/plugins/or g.eclipse.xsd_2.3.1.v200709252135.jar!/cache/www.w3.org/2001 /XMLSchema.xsd#//anyType;XSDComplexTypeDefinition=27 "/>
<content xsi:type="xsd:XSDParticle" element="[xsd:sequence: null]"
term=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p ">
<content xsi:type="xsd:XSDModelGroup" element="[xsd:sequence: null]"
compositor="sequence"
particles=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle
//schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle=1 ">
<contents element="[xsd:element: null]" minOccurs="0"
term=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle/scheduleId;XSDElementDeclaration ">
<content xsi:type="xsd:XSDElementDeclaration"
element="[xsd:element: null]" name="scheduleId"
targetNamespace=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0"
aliasName="scheduleId"
uRI=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0#scheduleId"
aliasURI=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0#scheduleId"
qName="tns:scheduleId"
resolvedElementDeclaration=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle/scheduleId;XSDElementDeclaration "
substitutionGroup=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle/scheduleId;XSDElementDeclaration ">
<typeDefinition xsi:type="xsd:XSDSimpleTypeDefinition"
href=" jar:file:/C:/dev/tools/eclipseide/3.3prod/eclipse/plugins/or g.eclipse.xsd_2.3.1.v200709252135.jar!/cache/www.w3.org/2001 /XMLSchema.xsd#//string;XSDSimpleTypeDefinition=7 "/>
</content>
</contents>
<contents element="[xsd:element: null]" minOccurs="0"
term=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle=1/price;XSDElementDeclaration ">
<content xsi:type="xsd:XSDElementDeclaration"
element="[xsd:element: null]" name="price"
targetNamespace=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0"
aliasName="price"
uRI=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0#price"
aliasURI=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0#price"
qName="tns:price"
resolvedElementDeclaration=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle=1/price;XSDElementDeclaration "
substitutionGroup=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle=1/price;XSDElementDeclaration ">
<typeDefinition xsi:type="xsd:XSDSimpleTypeDefinition"
href=" jar:file:/C:/dev/tools/eclipseide/3.3prod/eclipse/plugins/or g.eclipse.xsd_2.3.1.v200709252135.jar!/cache/www.w3.org/2001 /XMLSchema.xsd#//double;XSDSimpleTypeDefinition=10 "/>
</content>
</contents>
</content>
</content>
</contents>
<attributeDeclarations
href=" jar:file:/C:/dev/tools/eclipseide/3.3prod/eclipse/plugins/or g.eclipse.xsd_2.3.1.v200709252135.jar!/cache/www.w3.org/2001 /XMLSchema-instance.xsd#//nil;XSDAttributeDeclaration=1 "/>
<attributeDeclarations
href=" jar:file:/C:/dev/tools/eclipseide/3.3prod/eclipse/plugins/or g.eclipse.xsd_2.3.1.v200709252135.jar!/cache/www.w3.org/2001 /XMLSchema-instance.xsd#//noNamespaceSchemaLocation;XSDAttri buteDeclaration=3 "/>
<attributeDeclarations
href=" jar:file:/C:/dev/tools/eclipseide/3.3prod/eclipse/plugins/or g.eclipse.xsd_2.3.1.v200709252135.jar!/cache/www.w3.org/2001 /XMLSchema-instance.xsd#//schemaLocation;XSDAttributeDeclara tion=2 "/>
<attributeDeclarations
href=" jar:file:/C:/dev/tools/eclipseide/3.3prod/eclipse/plugins/or g.eclipse.xsd_2.3.1.v200709252135.jar!/cache/www.w3.org/2001 /XMLSchema-instance.xsd#//type;XSDAttributeDeclaration "/>
</xsd:XSDSchema>
----

Thanks for any help and suggestion.
Re: [ATL XSD EMF]: How to convert a xsd schema file to XMI formatted file [message #83016 is a reply to message #82986] Fri, 30 May 2008 14:42 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

David,

This is related to
https://bugs.eclipse.org/bugs/show_bug.cgi?id=166638. There are no
plans to support this because it's a hard problem to solve (and resource
is lacking). Things like includes (including Chameleon ones) and
imports drive the process of deriving the abstract model from the
concrete syntax of the standard serialization. We'd need to carefully
visit all the features defined in the XSD model to mark things that
shouldn't be serialized as transient and derived.


David wrote:
> Hi all,
>
> We have requiremnets to do xml schema conversion between xsd and XMI
> formatted. The following code shows how we try to convert a xsd schema
> to a XMI formatted file (which conforms to the XSD.ecore model), but
> the result file seems not right. I am wondering where the problem is?
> Maybe the way I am doing this is wrong? Is there any good way to do
> such conversion? What I know is that the XSD package does not use XMI
> serialization.
> The code:
> ---
> private static void xsd2xmi() throws IOException {
> ResourceSet metaResourceSet = new ResourceSetImpl();
>
> metaResourceSet.getResourceFactoryRegistry().getExtensionToF actoryMap().put(
>
> "xmi", new XMIResourceFactoryImpl());
> metaResourceSet.getResourceFactoryRegistry().getExtensionToF actoryMap().put(
>
> "xsd", new XSDResourceFactoryImpl());
> URI uriXsd = URI.createFileURI("C:/scheduleXsd.xsd");
> Resource r = metaResourceSet.getResource(uriXsd, true);
> r.load(null);
> XSDSchema schema = null;
> if ( r instanceof XSDResourceImpl) {
> XSDResourceImpl rXSD = (XSDResourceImpl) r ;
> schema = rXSD.getSchema();
> }
> URI uriXMI = URI.createFileURI("C:/scheduleXmi.xmi");
> Resource rXMI = metaResourceSet.createResource(uriXMI);
> rXMI.getContents().add(schema);
> rXMI.save(null);
> }
>
> ----
>
> The scheduleXsd.xsd is;
> --
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:tns=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0"
> targetNamespace=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
> <xsd:complexType name="schedule">
> <xsd:sequence>
> <xsd:element name="scheduleId" type="xsd:string"
> minOccurs="0"/>
> <xsd:element name="price" type="xsd:double" minOccurs="0"/>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:schema>
> -----
>
> The output scheduleXmi.xmi is ---
> <?xml version="1.0" encoding="ASCII"?>
> <xsd:XSDSchema xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:xsd="http://www.eclipse.org/xsd/2002/XSD" element="[xsd:schema:
> null]" document="[#document: null]"
> schemaLocation=" file:/C:/p4shadow/m2m/atlPrototype-interop-v1_4-schedule-v2. xsd "
> targetNamespace=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0"
> attributeFormDefault="unqualified" elementFormDefault="qualified"
> typeDefinitions="//schedule;XSDComplexTypeDefinition">
> <contents xsi:type="xsd:XSDComplexTypeDefinition"
> element="[xsd:complexType: null]" name="schedule"
> targetNamespace=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0"
> aliasName="schedule"
> uRI=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0#schedule"
> aliasURI=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0#schedule"
> qName="tns:schedule" contentTypeCategory="elementOnly"
> contentType="//schedule;XSDComplexTypeDefinition/XSDParticle ">
> <baseTypeDefinition xsi:type="xsd:XSDComplexTypeDefinition"
> href=" jar:file:/C:/dev/tools/eclipseide/3.3prod/eclipse/plugins/or g.eclipse.xsd_2.3.1.v200709252135.jar!/cache/www.w3.org/2001 /XMLSchema.xsd#//anyType;XSDComplexTypeDefinition=27 "/>
>
> <content xsi:type="xsd:XSDParticle" element="[xsd:sequence: null]"
> term=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p ">
> <content xsi:type="xsd:XSDModelGroup" element="[xsd:sequence:
> null]" compositor="sequence"
> particles=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle
> //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle=1 ">
>
> <contents element="[xsd:element: null]" minOccurs="0"
> term=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle/scheduleId;XSDElementDeclaration ">
>
> <content xsi:type="xsd:XSDElementDeclaration"
> element="[xsd:element: null]" name="scheduleId"
> targetNamespace=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0"
> aliasName="scheduleId"
> uRI=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0#scheduleId"
> aliasURI=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0#scheduleId"
> qName="tns:scheduleId"
> resolvedElementDeclaration=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle/scheduleId;XSDElementDeclaration "
> substitutionGroup=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle/scheduleId;XSDElementDeclaration ">
>
> <typeDefinition xsi:type="xsd:XSDSimpleTypeDefinition"
> href=" jar:file:/C:/dev/tools/eclipseide/3.3prod/eclipse/plugins/or g.eclipse.xsd_2.3.1.v200709252135.jar!/cache/www.w3.org/2001 /XMLSchema.xsd#//string;XSDSimpleTypeDefinition=7 "/>
>
> </content>
> </contents>
> <contents element="[xsd:element: null]" minOccurs="0"
> term=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle=1/price;XSDElementDeclaration ">
>
> <content xsi:type="xsd:XSDElementDeclaration"
> element="[xsd:element: null]" name="price"
> targetNamespace=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0"
> aliasName="price"
> uRI=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0#price"
> aliasURI=" http://xml.ms.com/ns/modex-models/atlPrototype-interop/v1_4/ schedule/v2_0#price"
> qName="tns:price"
> resolvedElementDeclaration=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle=1/price;XSDElementDeclaration "
> substitutionGroup=" //schedule;XSDComplexTypeDefinition/XSDParticle/XSDModelGrou p/XSDParticle=1/price;XSDElementDeclaration ">
>
> <typeDefinition xsi:type="xsd:XSDSimpleTypeDefinition"
> href=" jar:file:/C:/dev/tools/eclipseide/3.3prod/eclipse/plugins/or g.eclipse.xsd_2.3.1.v200709252135.jar!/cache/www.w3.org/2001 /XMLSchema.xsd#//double;XSDSimpleTypeDefinition=10 "/>
>
> </content>
> </contents>
> </content>
> </content>
> </contents>
> <attributeDeclarations
> href=" jar:file:/C:/dev/tools/eclipseide/3.3prod/eclipse/plugins/or g.eclipse.xsd_2.3.1.v200709252135.jar!/cache/www.w3.org/2001 /XMLSchema-instance.xsd#//nil;XSDAttributeDeclaration=1 "/>
>
> <attributeDeclarations
> href=" jar:file:/C:/dev/tools/eclipseide/3.3prod/eclipse/plugins/or g.eclipse.xsd_2.3.1.v200709252135.jar!/cache/www.w3.org/2001 /XMLSchema-instance.xsd#//noNamespaceSchemaLocation;XSDAttri buteDeclaration=3 "/>
>
> <attributeDeclarations
> href=" jar:file:/C:/dev/tools/eclipseide/3.3prod/eclipse/plugins/or g.eclipse.xsd_2.3.1.v200709252135.jar!/cache/www.w3.org/2001 /XMLSchema-instance.xsd#//schemaLocation;XSDAttributeDeclara tion=2 "/>
>
> <attributeDeclarations
> href=" jar:file:/C:/dev/tools/eclipseide/3.3prod/eclipse/plugins/or g.eclipse.xsd_2.3.1.v200709252135.jar!/cache/www.w3.org/2001 /XMLSchema-instance.xsd#//type;XSDAttributeDeclaration "/>
>
> </xsd:XSDSchema>
> ----
>
> Thanks for any help and suggestion.
>
>
>
Previous Topic:ATL: reserved keyword name clash
Next Topic:[QVTO] Iteration over collection
Goto Forum:
  


Current Time: Sun Sep 22 11:56:40 GMT 2019

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

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

Back to the top