Skip to main content



      Home
Home » Modeling » EMF » Ecore->XSD->Ecore roundtrip
Ecore->XSD->Ecore roundtrip [message #1072191] Mon, 22 July 2013 05:03 Go to next message
Eclipse UserFriend
Hi,

so after years of vanilla EMF modelling I'm finally forced to enter the world of XML Schema Neutral, meh.

What I currently do is: Take my models that are defined already in Ecore, and use the XSD Export function on the genmodel to get corresponding XSD models. The first question here:

What is the difference between "Export XSD for Ecore" and "Export XSD for XMI"?

Once I exported the ecore to schema, can I just use XML/XMI resources, and the serialized result will automatically be a valid according to the schemas? I guess if the original model is defined in Ecore, there's no need to use ExtendedMetadata in order to serialize?

Now, out of curiosity, I take the XSD files and re-create the Ecore models from them to do a full roundtrip. If I compare the original Ecore models against those created from the Schemas, I can see the following differences:

- The wrapper datatypes for nillable elements
- ExtendedMetadata annotations

So now I don't know If I should use the original Ecore models to serialize/deserialize, or the ones created from re-importing the corresponding XML schemas? My guts feeling is that I can skip the re-import, since the wrapper types are not used, and the annotations should represent some sort of "default" but maybe I miss something?

Once I'm done I'd be happy to contribute at least to the wiki or so Smile

Thanks for comments,
Felix.

[Updated on: Mon, 22 July 2013 05:04] by Moderator

Re: Ecore->XSD->Ecore roundtrip [message #1072206 is a reply to message #1072191] Mon, 22 July 2013 05:35 Go to previous messageGo to next message
Eclipse UserFriend
Felix,

Comments below.

On 22/07/2013 11:03 AM, Felix Dorner wrote:
> Hi,
>
> so after years of vanilla EMF modelling I'm finally forced to enter
> the world of XML Schema :|, meh.
>
> What I currently do is: Take my models that are defined already in
> Ecore, and use the XSD Export function on the genmodel to get
> corresponding XSD models. The first question here:
>
> What is the difference between "Export XSD for Ecore" and "Export XSD
> for XMI"?
XMI schemas are basically useless. They provide a schema that describes
an XMI serialization of your model, but that schema is of essentially no
value because you can't describe an XMI serialization with a schema that
does a reasonable amount of validation.
>
> Once I exported the schema, can I just use XML/XMI resources, and the
> serialized result will automatically be a valid according to the
> exported schema?
Yes, that's the idea. Another problem though is that XML Schema doesn't
support multiple inheritance so isn't general enough to describe all
Ecore models.
> I guess if the original model is defined in Ecore, there's no need to
> use ExtendedMetadata in order to serialize?
No.
>
> Now, out of curiosity, I take the XSD files and re-create the Ecore
> models from them to do a full roundtrip. If I compare the original
> Ecore models against those created from the Schemas, I can see the
> following differences:
>
> - The wrapper datatypes for nillable elements
I'd expect nillable elements only for things that already allow null,
i.e., for things that aren't primitives.
> - ExtendedMetadata annotations
>
> So now I don't know If I should use the original Ecore models to
> serialize/deserialize, or the ones created from re-importing the
> corresponding XML schemas?
The original.
> My guts feeling is that I can skip the re-import, since the wrapper
> types are not used, and the annotations should represent some sort of
> "default" but maybe I miss something?
You shouldn't need to reimport from the generated schema.
>
> Once I'm done I'd be happy to contribute at least to the wiki or so :)
>
> Thanks for comments,
> Felix.
>
Re: Ecore->XSD->Ecore roundtrip [message #1072227 is a reply to message #1072206] Mon, 22 July 2013 06:45 Go to previous messageGo to next message
Eclipse UserFriend
On 22/07/2013 11:35, Ed Merks wrote:

>> Once I exported the schema, can I just use XML/XMI resources, and the
>> serialized result will automatically be a valid according to the
>> exported schema?
> Yes, that's the idea. Another problem though is that XML Schema doesn't
> support multiple inheritance so isn't general enough to describe all
> Ecore models.

But the exporter can still create schemas for such models right? The
information that cannot be expressed in XSD is attached by using
ecore:... attributes in the schema.
Re: Ecore->XSD->Ecore roundtrip [message #1072240 is a reply to message #1072227] Mon, 22 July 2013 07:14 Go to previous messageGo to next message
Eclipse UserFriend
Felix,

Comments below.

On 22/07/2013 12:45 PM, Felix Dorner wrote:
> On 22/07/2013 11:35, Ed Merks wrote:
>
>>> Once I exported the schema, can I just use XML/XMI resources, and the
>>> serialized result will automatically be a valid according to the
>>> exported schema?
>> Yes, that's the idea. Another problem though is that XML Schema doesn't
>> support multiple inheritance so isn't general enough to describe all
>> Ecore models.
>
> But the exporter can still create schemas for such models right?
Yes.
> The information that cannot be expressed in XSD is attached by using
> ecore:... attributes in the schema.
That's right.
>
>
>
>
Re: Ecore->XSD->Ecore roundtrip [message #1073683 is a reply to message #1072240] Thu, 25 July 2013 05:47 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed,

On 22/07/2013 13:14, Ed Merks wrote:
>>>> Once I exported the schema, can I just use XML/XMI resources, and the
>>>> serialized result will automatically be a valid according to the
>>>> exported schema?
>>> Yes, that's the idea. Another problem though is that XML Schema doesn't
>>> support multiple inheritance so isn't general enough to describe all
>>> Ecore models.
>>
>> But the exporter can still create schemas for such models right?
> Yes.
>> The information that cannot be expressed in XSD is attached by using
>> ecore:... attributes in the schema.
> That's right.

But it looks like for example an EAttribute that comes from a
"secondary" superclass is lost in the schema representation, I give a
trivial example:

Airport
- runways: EInt

Trainstation
- platforms: EInt

TrafficHub -> Airport, Trainstation
- closedOnWeekends: EBoolean

The schema exporter generates a complex type TrafficHub like this:

<xsd:complexType ecore:implements="test1:Trainstation" name="TransportHub">
<xsd:complexContent>
<xsd:extension base="test1:Airport">
<xsd:attribute ecore:unsettable="false" name="closedOnWeekends"
type="ecore:EBoolean"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

Aha Effect: The "platforms" attribute is missing from the TransportHub type.

When I now serialize a TrafficHub it will contain an attribute
"platforms" which is not allowed on a TrafficHub type according
to the schema, so a pure xml validator that uses the schema will report
the document invalid, and someone who wants to build tools around the
schema definition will miss important bits unless the ecore: attributes
are taken into account.

I guess that's what you meant with "Another problem.." above.

Thanks,
Felix
Re: Ecore-&gt;XSD-&gt;Ecore roundtrip [message #1074131 is a reply to message #1073683] Fri, 26 July 2013 03:08 Go to previous messageGo to next message
Eclipse UserFriend
Felix,

Comments below.

On 25/07/2013 11:47 AM, Felix Dorner wrote:
> Hi Ed,
>
> On 22/07/2013 13:14, Ed Merks wrote:
>>>>> Once I exported the schema, can I just use XML/XMI resources, and the
>>>>> serialized result will automatically be a valid according to the
>>>>> exported schema?
>>>> Yes, that's the idea. Another problem though is that XML Schema
>>>> doesn't
>>>> support multiple inheritance so isn't general enough to describe all
>>>> Ecore models.
>>>
>>> But the exporter can still create schemas for such models right?
>> Yes.
>>> The information that cannot be expressed in XSD is attached by using
>>> ecore:... attributes in the schema.
>> That's right.
>
> But it looks like for example an EAttribute that comes from a
> "secondary" superclass is lost in the schema representation, I give a
> trivial example:
>
> Airport
> - runways: EInt
>
> Trainstation
> - platforms: EInt
>
> TrafficHub -> Airport, Trainstation
> - closedOnWeekends: EBoolean
XML Schema can't support multiple inheritance so in the end, it's
impossible for the schema to represent what you're serialize. Even if
we copied all the super class structure, a TrafficHub instance wouldn't
be allowed to appear where a Trainstation instance is allowed to appear,
so the serialization still can't generally conform to this schema.
>
> The schema exporter generates a complex type TrafficHub like this:
>
> <xsd:complexType ecore:implements="test1:Trainstation"
> name="TransportHub">
> <xsd:complexContent>
> <xsd:extension base="test1:Airport">
> <xsd:attribute ecore:unsettable="false"
> name="closedOnWeekends" type="ecore:EBoolean"/>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> Aha Effect: The "platforms" attribute is missing from the TransportHub
> type.
>
> When I now serialize a TrafficHub it will contain an attribute
> "platforms" which is not allowed on a TrafficHub type according
> to the schema, so a pure xml validator that uses the schema will
> report the document invalid, and someone who wants to build tools
> around the schema definition will miss important bits unless the
> ecore: attributes are taken into account.
So if you want something that works for pure XML Schema you have to
avoid things not supported by XML Schema, e.g., no multiple inheritance.
>
> I guess that's what you meant with "Another problem.." above.
Yes.
>
> Thanks,
> Felix
Re: Ecore-&gt;XSD-&gt;Ecore roundtrip [message #1074271 is a reply to message #1074131] Fri, 26 July 2013 08:02 Go to previous message
Eclipse UserFriend
have no idea about that buddy
Previous Topic:auto-split EMF model in several files
Next Topic:EMF operation call in ATL
Goto Forum:
  


Current Time: Sun Jul 13 19:26:53 EDT 2025

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

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

Back to the top