Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » Attribute vs element in XML serialization
Attribute vs element in XML serialization [message #65419] Fri, 16 December 2005 13:23 Go to next message
Eclipse User
Originally posted by: henryhhuang.yahoo.com

I started my EMF models using XSD, whose elements do not have any
attributes, but nested elements. When I use XMLResource to serialize the
models, the result XML instance document switchs all simple elements into
attributes. Is there any simple way to let the instance document confirm
to the original XSD, i.e, the simple nested element is serialized as
simple nested element? I did the following, but it does not help. I had to
find each attribute contained in the document (recursively), and set the
XML representation to ELEMENT using XMLInfo (for each simple attribute) to
make it work.

Is there any simpler and natural way to achieve this? Thanks!!!

XMLResource res = new XMLResourceImpl(uri);
XMLMap map = new XMLMapImpl();
res.getDefaultSaveOptions().put(XMLResource.OPTION_XML_MAP, map);
....
res.save();

Henry
Re: Attribute vs element in XML serialization [message #65442 is a reply to message #65419] Fri, 16 December 2005 15:14 Go to previous message
Eclipse User
Originally posted by: merks.ca.ibm.com

Henry,

The best thing to do is exactly what you see in the generated
XyxExample.java in the generated *.tests plugin. You can run that
example as a Java application and it can load or save instances. One of
the important things missing below is the setting of the options you'll
find in the generated XyzResourceFactoryImpl.


henry wrote:

> I started my EMF models using XSD, whose elements do not have any
> attributes, but nested elements. When I use XMLResource to serialize
> the models, the result XML instance document switchs all simple
> elements into attributes. Is there any simple way to let the instance
> document confirm to the original XSD, i.e, the simple nested element
> is serialized as simple nested element? I did the following, but it
> does not help. I had to find each attribute contained in the document
> (recursively), and set the XML representation to ELEMENT using XMLInfo
> (for each simple attribute) to make it work.
> Is there any simpler and natural way to achieve this? Thanks!!!
>
> XMLResource res = new XMLResourceImpl(uri);
> XMLMap map = new XMLMapImpl();
> res.getDefaultSaveOptions().put(XMLResource.OPTION_XML_MAP, map);
> ...
> res.save();
>
> Henry
>
>
Re: Attribute vs element in XML serialization [message #597360 is a reply to message #65419] Fri, 16 December 2005 15:14 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 25919
Registered: July 2009
Senior Member
Henry,

The best thing to do is exactly what you see in the generated
XyxExample.java in the generated *.tests plugin. You can run that
example as a Java application and it can load or save instances. One of
the important things missing below is the setting of the options you'll
find in the generated XyzResourceFactoryImpl.


henry wrote:

> I started my EMF models using XSD, whose elements do not have any
> attributes, but nested elements. When I use XMLResource to serialize
> the models, the result XML instance document switchs all simple
> elements into attributes. Is there any simple way to let the instance
> document confirm to the original XSD, i.e, the simple nested element
> is serialized as simple nested element? I did the following, but it
> does not help. I had to find each attribute contained in the document
> (recursively), and set the XML representation to ELEMENT using XMLInfo
> (for each simple attribute) to make it work.
> Is there any simpler and natural way to achieve this? Thanks!!!
>
> XMLResource res = new XMLResourceImpl(uri);
> XMLMap map = new XMLMapImpl();
> res.getDefaultSaveOptions().put(XMLResource.OPTION_XML_MAP, map);
> ...
> res.save();
>
> Henry
>
>
Previous Topic:Attribute vs element in XML serialization
Next Topic:Using ResourceSet with InputStream rather than URI
Goto Forum:
  


Current Time: Sat Jul 26 15:20:11 EDT 2014

Powered by FUDForum. Page generated in 0.01926 seconds