Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » Attribute vs element in XML serialization
Attribute vs element in XML serialization [message #65419] Fri, 16 December 2005 18:23 Go to next message
Eclipse UserFriend
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 20:14 Go to previous message
Eclipse UserFriend
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 20:14 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
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
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Attribute vs element in XML serialization
Next Topic:Using ResourceSet with InputStream rather than URI
Goto Forum:
  


Current Time: Fri Apr 26 17:04:20 GMT 2024

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

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

Back to the top