Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Serializing with schema metadata (but no schema)
Serializing with schema metadata (but no schema) [message #418469] Wed, 16 April 2008 21:12 Go to next message
Will Horn is currently offline Will HornFriend
Messages: 265
Registered: July 2009
Senior Member
I have two models (one is aware of the other) that were generated from
XML Schema. I would like to be able to serialize a collection of
objects from both models into a single XML file (so there are no more
cross-document references) and I am wondering what is the best way to
accomplish this.

I can do it using XMIResourceImpl, combining all the objects under an
<xmi> tag. However, this does not respect the schema extended metadata
so the serialized objects do not look the same as when they are
serialized individually (as a child of the DocumentRoot). For example,
names of elements are different, attributes are sometimes used instead
of elements.

I know I could create a new schema with a type that has containment
references for each eClass in the two models. Then there would be a new
feature on the DocumentRoot which I could use. However, maintaining
this new type would be cumbersome as the models change.

I realize this is a fairly strange scenario - trying to serialize with
the schema metadata without actually making a schema. But is there a
way to do it, to generically serialize EObjects that respects the schema
metadata?
Re: Serializing with schema metadata (but no schema) [message #418475 is a reply to message #418469] Wed, 16 April 2008 23:26 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33217
Registered: July 2009
Senior Member
Will,

You really need to define a root element of a complex type that can
contain the multiple children. You could just define a global element
of type "xsd:anyType" for that purpose, or a global element with a
complex type that as <xsd:any maxOccurs="unbounded"/> as it's content
type...


Will Horn wrote:
> I have two models (one is aware of the other) that were generated from
> XML Schema. I would like to be able to serialize a collection of
> objects from both models into a single XML file (so there are no more
> cross-document references) and I am wondering what is the best way to
> accomplish this.
>
> I can do it using XMIResourceImpl, combining all the objects under an
> <xmi> tag. However, this does not respect the schema extended
> metadata so the serialized objects do not look the same as when they
> are serialized individually (as a child of the DocumentRoot). For
> example, names of elements are different, attributes are sometimes
> used instead of elements.
>
> I know I could create a new schema with a type that has containment
> references for each eClass in the two models. Then there would be a
> new feature on the DocumentRoot which I could use. However,
> maintaining this new type would be cumbersome as the models change.
>
> I realize this is a fairly strange scenario - trying to serialize with
> the schema metadata without actually making a schema. But is there a
> way to do it, to generically serialize EObjects that respects the
> schema metadata?


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Serializing with schema metadata (but no schema) [message #418524 is a reply to message #418475] Thu, 17 April 2008 15:48 Go to previous messageGo to next message
Will Horn is currently offline Will HornFriend
Messages: 265
Registered: July 2009
Senior Member
Thanks Ed,

That is a great solution! I think <xsd:any maxOccurs="unbounded"/> is
what I would need, so I could create something like:

<myRoot>
<ObjectA .../>
<ObjectA .../>
<ObjectB .../>
</myRoot>

However, that creates a FeatureMap, and I am not sure what features
should be used.

-Will

Ed Merks wrote:
> Will,
>
> You really need to define a root element of a complex type that can
> contain the multiple children. You could just define a global element
> of type "xsd:anyType" for that purpose, or a global element with a
> complex type that as <xsd:any maxOccurs="unbounded"/> as it's content
> type...
>
>
> Will Horn wrote:
>> I have two models (one is aware of the other) that were generated from
>> XML Schema. I would like to be able to serialize a collection of
>> objects from both models into a single XML file (so there are no more
>> cross-document references) and I am wondering what is the best way to
>> accomplish this.
>>
>> I can do it using XMIResourceImpl, combining all the objects under an
>> <xmi> tag. However, this does not respect the schema extended
>> metadata so the serialized objects do not look the same as when they
>> are serialized individually (as a child of the DocumentRoot). For
>> example, names of elements are different, attributes are sometimes
>> used instead of elements.
>>
>> I know I could create a new schema with a type that has containment
>> references for each eClass in the two models. Then there would be a
>> new feature on the DocumentRoot which I could use. However,
>> maintaining this new type would be cumbersome as the models change.
>>
>> I realize this is a fairly strange scenario - trying to serialize with
>> the schema metadata without actually making a schema. But is there a
>> way to do it, to generically serialize EObjects that respects the
>> schema metadata?
Re: Serializing with schema metadata (but no schema) [message #418526 is a reply to message #418524] Thu, 17 April 2008 16:00 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33217
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070300090500080509080201
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Will,

The joys of feature maps. You can use features from the document root
of any other model.

myRoot.getAny().add(XyzPackage.Literals.DOCUMENT_ROOT__ABC,
<object-of-ABC's-type>).

This article might be helpful for gory details:

Binding XML to Java
< http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava>


Will Horn wrote:
> Thanks Ed,
>
> That is a great solution! I think <xsd:any maxOccurs="unbounded"/> is
> what I would need, so I could create something like:
>
> <myRoot>
> <ObjectA .../>
> <ObjectA .../>
> <ObjectB .../>
> </myRoot>
>
> However, that creates a FeatureMap, and I am not sure what features
> should be used.
>
> -Will
>
> Ed Merks wrote:
>> Will,
>>
>> You really need to define a root element of a complex type that can
>> contain the multiple children. You could just define a global
>> element of type "xsd:anyType" for that purpose, or a global element
>> with a complex type that as <xsd:any maxOccurs="unbounded"/> as it's
>> content type...
>>
>>
>> Will Horn wrote:
>>> I have two models (one is aware of the other) that were generated
>>> from XML Schema. I would like to be able to serialize a collection
>>> of objects from both models into a single XML file (so there are no
>>> more cross-document references) and I am wondering what is the best
>>> way to accomplish this.
>>>
>>> I can do it using XMIResourceImpl, combining all the objects under
>>> an <xmi> tag. However, this does not respect the schema extended
>>> metadata so the serialized objects do not look the same as when they
>>> are serialized individually (as a child of the DocumentRoot). For
>>> example, names of elements are different, attributes are sometimes
>>> used instead of elements.
>>>
>>> I know I could create a new schema with a type that has containment
>>> references for each eClass in the two models. Then there would be a
>>> new feature on the DocumentRoot which I could use. However,
>>> maintaining this new type would be cumbersome as the models change.
>>>
>>> I realize this is a fairly strange scenario - trying to serialize
>>> with the schema metadata without actually making a schema. But is
>>> there a way to do it, to generically serialize EObjects that
>>> respects the schema metadata?


--------------070300090500080509080201
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Will,<br>
<br>
The joys of feature maps.&nbsp; You can use features from the document root
of any other model.&nbsp;&nbsp; <br>
<blockquote>myRoot.getAny().add(XyzPackage.Literals.DOCUMENT_ROOT__ABC,
&lt;object-of-ABC's-type&gt;).<br>
</blockquote>
This article might be helpful for gory details:<br>
<blockquote><a target="_out"
href=" http://www.theserverside.com/tt/articles/article.tss?l=Bindi ngXMLJava">Binding
XML to Java</a><br>
</blockquote>
<br>
Will Horn wrote:
<blockquote cite="mid:fu7ri3$jpd$1@build.eclipse.org" type="cite">Thanks
Ed,
<br>
<br>
That is a great solution! I think &lt;xsd:any
maxOccurs="unbounded"/&gt; is what I would need, so I could create
something like:
<br>
<br>
&lt;myRoot&gt;
<br>
&nbsp;&lt;ObjectA .../&gt;
<br>
&nbsp;&lt;ObjectA .../&gt;
<br>
&nbsp;&lt;ObjectB .../&gt;
<br>
&lt;/myRoot&gt;
<br>
<br>
However, that creates a FeatureMap, and I am not sure what features
should be used.
<br>
<br>
-Will
<br>
<br>
Ed Merks wrote:
<br>
<blockquote type="cite">Will,
<br>
<br>
You really need to define a root element of a complex type that can
contain the multiple children.&nbsp;&nbsp; You could just define a global element
of type "xsd:anyType" for that purpose, or a global element with a
complex type that as &lt;xsd:any maxOccurs="unbounded"/&gt; as it's
content type...
<br>
<br>
<br>
Will Horn wrote:
<br>
<blockquote type="cite">I have two models (one is aware of the
other) that were generated from XML Schema.&nbsp; I would like to be able to
serialize a collection of objects from both models into a single XML
file (so there are no more cross-document references) and I am
wondering what is the best way to accomplish this.
<br>
<br>
I can do it using XMIResourceImpl, combining all the objects under an
&lt;xmi&gt; tag.&nbsp; However, this does not respect the schema extended
metadata so the serialized objects do not look the same as when they
are serialized individually (as a child of the DocumentRoot).&nbsp; For
example, names of elements are different, attributes are sometimes used
instead of elements.
<br>
<br>
I know I could create a new schema with a type that has containment
references for each eClass in the two models.&nbsp; Then there would be a
new feature on the DocumentRoot which I could use.&nbsp; However,
maintaining this new type would be cumbersome as the models change.
<br>
<br>
I realize this is a fairly strange scenario - trying to serialize with
the schema metadata without actually making a schema.&nbsp; But is there a
way to do it, to generically serialize EObjects that respects the
schema metadata?
<br>
</blockquote>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------070300090500080509080201--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Serializing with schema metadata (but no schema) [message #418527 is a reply to message #418524] Thu, 17 April 2008 16:03 Go to previous message
Will Horn is currently offline Will HornFriend
Messages: 265
Registered: July 2009
Senior Member
I think I answered my own question. Using the appropriate EReference
from the DocumentRoot class does what I need.

Thanks again for the assistance.

Will Horn wrote:
> Thanks Ed,
>
> That is a great solution! I think <xsd:any maxOccurs="unbounded"/> is
> what I would need, so I could create something like:
>
> <myRoot>
> <ObjectA .../>
> <ObjectA .../>
> <ObjectB .../>
> </myRoot>
>
> However, that creates a FeatureMap, and I am not sure what features
> should be used.
>
> -Will
>
> Ed Merks wrote:
>> Will,
>>
>> You really need to define a root element of a complex type that can
>> contain the multiple children. You could just define a global
>> element of type "xsd:anyType" for that purpose, or a global element
>> with a complex type that as <xsd:any maxOccurs="unbounded"/> as it's
>> content type...
>>
>>
>> Will Horn wrote:
>>> I have two models (one is aware of the other) that were generated
>>> from XML Schema. I would like to be able to serialize a collection
>>> of objects from both models into a single XML file (so there are no
>>> more cross-document references) and I am wondering what is the best
>>> way to accomplish this.
>>>
>>> I can do it using XMIResourceImpl, combining all the objects under an
>>> <xmi> tag. However, this does not respect the schema extended
>>> metadata so the serialized objects do not look the same as when they
>>> are serialized individually (as a child of the DocumentRoot). For
>>> example, names of elements are different, attributes are sometimes
>>> used instead of elements.
>>>
>>> I know I could create a new schema with a type that has containment
>>> references for each eClass in the two models. Then there would be a
>>> new feature on the DocumentRoot which I could use. However,
>>> maintaining this new type would be cumbersome as the models change.
>>>
>>> I realize this is a fairly strange scenario - trying to serialize
>>> with the schema metadata without actually making a schema. But is
>>> there a way to do it, to generically serialize EObjects that respects
>>> the schema metadata?
Previous Topic:[newbie] editor and data relation
Next Topic:Dynamic instance of deployed metamodel
Goto Forum:
  


Current Time: Tue Sep 24 05:31:19 GMT 2024

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

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

Back to the top