Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » XMLResource.OPTION_FORMATTED is not working(Trying to save a resource with the formatted option and I am getting all of the content on a single line)
XMLResource.OPTION_FORMATTED is not working [message #1398513] Fri, 11 July 2014 07:18 Go to next message
Jon Buck is currently offline Jon BuckFriend
Messages: 29
Registered: July 2009
Junior Member
Hi All, hopefully someone may have seen this before....

I have created an ecore and genmodel from an XSD which is all fine however when I create a model and try to save it using the generated resource factory along with the (XMLResource.OPTION_FORMATTED, Boolean.TRUE) option I am getting a single line of text in the file...

Any thoughts anyone?? What am I doing wrong??
Re: XMLResource.OPTION_FORMATTED is not working [message #1398522 is a reply to message #1398513] Fri, 11 July 2014 07:38 Go to previous messageGo to next message
Jon Buck is currently offline Jon BuckFriend
Messages: 29
Registered: July 2009
Junior Member
Apologies.. should have said this is under eclipse 3.8.2 with EMF 2.6.0
Re: XMLResource.OPTION_FORMATTED is not working [message #1398529 is a reply to message #1398513] Fri, 11 July 2014 07:42 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Jon,

You've not said much about your model, but if the XSD involves complex
types with mixed content, EMF will print out exactly the white space
that appears in the feature maps corresponding to that mixed content.
Serializing will not alter the model itself to introduce formatting. In
other words, the formatting option only applies for instances of
EClasses for which
org.eclipse.emf.ecore.util.ExtendedMetaData.getContentKind(EClass) is
UNSPECIFIED_CONTENT or ELEMENT_ONLY_CONTENT, i.e., only for the cases
where just white space is allowed and that white space is not meaningful
nor recorded in the model upon deserialization.


On 11/07/2014 9:18 AM, Jon Buck wrote:
> Hi All, hopefully someone may have seen this before....
>
> I have created an ecore and genmodel from an XSD which is all fine
> however when I create a model and try to save it using the generated
> resource factory along with the (XMLResource.OPTION_FORMATTED,
> Boolean.TRUE) option I am getting a single line of text in the file...
>
> Any thoughts anyone?? What am I doing wrong??


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XMLResource.OPTION_FORMATTED is not working [message #1398573 is a reply to message #1398529] Fri, 11 July 2014 09:01 Go to previous messageGo to next message
Jon Buck is currently offline Jon BuckFriend
Messages: 29
Registered: July 2009
Junior Member
Hey Ed,

Thanks for you reply... your right, looking at the ecore model the content kind is of type mixed so that may explain why this happening.. I realize at the end of the day nicely formatted code makes no difference to the ability for EMF to load or save the data but I would like it to be formatted nicely as the users will want to look at the files I produce so I guess my options now are to get EMF to serialize the model for me and to then look at something like the javax Transformer factory to pretty print the string before writing it to a file....
Re: XMLResource.OPTION_FORMATTED is not working [message #1398574 is a reply to message #1398573] Fri, 11 July 2014 09:04 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Jon,

I'm curious if these places that are marked mixed in the schema really
are intended to capture non-whitespace information that's somehow
meaningful and relevant to the end-user of this XML?


On 11/07/2014 11:01 AM, Jon Buck wrote:
> Hey Ed,
>
> Thanks for you reply... your right, looking at the ecore model the
> content kind is of type mixed so that may explain why this
> happening.. I realize at the end of the day nicely formatted code
> makes no difference to the ability for EMF to load or save the data
> but I would like it to be formatted nicely as the users will want to
> look at the files I produce so I guess my options now are to get EMF
> to serialize the model for me and to then look at something like the
> javax Transformer factory to pretty print the string before writing it
> to a file....


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: XMLResource.OPTION_FORMATTED is not working [message #1398606 is a reply to message #1398574] Fri, 11 July 2014 10:01 Go to previous messageGo to next message
Jon Buck is currently offline Jon BuckFriend
Messages: 29
Registered: July 2009
Junior Member
Hey Ed, I am using a model generated from Spring's Beans and Integration schemas, I haven't altered the generated ecore or genmodel in anyway nor do I fully understand that intracies of the schema and resulting ecore model... I just had a look at the model after your first reply to see what the metadata kind value was set to which as you said may be set to mixed which it is...

Apologies for slightly changing the subject here but I am also seeing in the serialization that EMF is including elements that are empty! is there anyway to tell EMF to omit empty elements in the resulting serialization??
Re: XMLResource.OPTION_FORMATTED is not working [message #1398697 is a reply to message #1398606] Fri, 11 July 2014 12:54 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Jon,

Comments below.

On 11/07/2014 12:01 PM, Jon Buck wrote:
> Hey Ed, I am using a model generated from Spring's Beans and
> Integration schemas, I haven't altered the generated ecore or genmodel
> in anyway nor do I fully understand that intracies of the schema and
> resulting ecore model...
Fortunately it's all automatic. :-P
> I just had a look at the model after your first reply to see what the
> metadata kind value was set to which as you said may be set to mixed
> which it is...
If you annotated the schema (ecore:mixed="false", you could turn mixed
off, but then non-whitespace mixed content would be ignored.
>
> Apologies for slightly changing the subject here but I am also seeing
> in the serialization that EMF is including elements that are empty!
I'd need more details. Perhaps you've set some feature's value to the
empty string?
> is there anyway to tell EMF to omit empty elements in the resulting
> serialization??
It won't serialize a feature if eIsSet is false, so this suggest you've
set something to the empty string.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[XCORE] Hide attribute getter/setter from interface
Next Topic:What happens to a "loaded resource" when the Ecore editor is closed?
Goto Forum:
  


Current Time: Fri Mar 29 06:52:05 GMT 2024

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

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

Back to the top