Skip to main content



      Home
Home » Modeling » EMF » Model serialization
Model serialization [message #402392] Wed, 12 July 2006 20:45 Go to next message
Eclipse UserFriend
Hi,
When I persist model data to a file all the element names start with a
lowercase letter. For example an object "Name" when persisted becomes
"name". What do I do to customize the serialization? Also incase of
deserialization can I do something like ignore case to import the model.

Say I have a simple model that looks like this

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
targetNamespace="http://www.example.com/Library"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:lib="http://www.example.com/Library"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<xsd:element name="library" type="lib:Library"/>
<xsd:complexType name="Library">
<xsd:sequence>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="books" type="string"/>
<xsd:element maxOccurs="unbounded" minOccurs="0"
name="Writer" type="string"/>
</xsd:sequence>
</xsd:complexType>

When I save the model I expect the data to be
<? xml version="1.0" ?>
<Library>
<Name>XYZ</Name><Writer>ABC</Writer>
</Library>

where as the persisted xml looks like this
<? xml version="1.0" ?>
<Library>
<name>XYZ</name><writer>ABC</writer>
</Library>
Re: Model serialization [message #402404 is a reply to message #402392] Thu, 13 July 2006 06:49 Go to previous message
Eclipse UserFriend
Guru,

The standard reason for this is not using the generated resource factory
to create the resource for serializing the result. Have a look at the
generated XyzExample.java in the generated *.tests project for how to
set things up so that the right resource, with the right options, is
used. This will also illustrate how to use a DocumentRoot instance to
ensure that the root element is specified correctly as well.


Guru Nagarajan wrote:
> Hi,
> When I persist model data to a file all the element names start with
> a lowercase letter. For example an object "Name" when persisted
> becomes "name". What do I do to customize the serialization? Also
> incase of deserialization can I do something like ignore case to
> import the model.
>
> Say I have a simple model that looks like this
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema
> targetNamespace="http://www.example.com/Library"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xmlns:lib="http://www.example.com/Library"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>
> <xsd:element name="library" type="lib:Library"/>
> <xsd:complexType name="Library">
> <xsd:sequence>
> <xsd:element name="Name" type="xsd:string"/>
> <xsd:element maxOccurs="unbounded" minOccurs="0"
> name="books" type="string"/>
> <xsd:element maxOccurs="unbounded" minOccurs="0"
> name="Writer" type="string"/>
> </xsd:sequence>
> </xsd:complexType>
>
> When I save the model I expect the data to be
> <? xml version="1.0" ?>
> <Library>
> <Name>XYZ</Name><Writer>ABC</Writer>
> </Library>
>
> where as the persisted xml looks like this
> <? xml version="1.0" ?>
> <Library>
> <name>XYZ</name><writer>ABC</writer>
> </Library>
Previous Topic:Conceptual Doubt about EFactory and Custom Implementations
Next Topic:IRS efile: Huge package. Breaks compiler!
Goto Forum:
  


Current Time: Sun Aug 03 17:56:05 EDT 2025

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

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

Back to the top