Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF serialization - Each element on new line
EMF serialization - Each element on new line [message #468379] Wed, 05 August 2009 10:22 Go to next message
Karthik Srinivasan is currently offline Karthik SrinivasanFriend
Messages: 9
Registered: July 2009
Junior Member
Hi,

When I serialize my emf model into an xml, I'd like to have each element
on a new line. Say just like how it is when I right click on a xml editor
and say source -> format.

I used
options.put(XMLResource.OPTION_FORMATTED, Boolean.TRUE);
in the save options. That formats it alright but all elements are not on
new lines.

When I use
options.put(XMLResource.OPTION_LINE_WIDTH, 40);
the code is truncated and moved to the next line at the first opportunity
after 40 characters.

Any idea on how to achieve the formatting I'm looking for?
On searching the news groups, this is the only thread I found similar to
mine. I can understand how that works for attributes. But I need that
effect for elements.
http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg2 7419.html

Thanks,
Karthik
Re: EMF serialization - Each element on new line [message #468418 is a reply to message #468379] Wed, 05 August 2009 13:24 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Karthik,

Comments below.

Karthik Srinivasan wrote:
> Hi,
>
> When I serialize my emf model into an xml, I'd like to have each
> element on a new line. Say just like how it is when I right click on a
> xml editor and say source -> format.
>
> I used options.put(XMLResource.OPTION_FORMATTED, Boolean.TRUE);
> in the save options. That formats it alright but all elements are not
> on new lines.
>
> When I use
> options.put(XMLResource.OPTION_LINE_WIDTH, 40);
> the code is truncated and moved to the next line at the first
> opportunity after 40 characters.
>
> Any idea on how to achieve the formatting I'm looking for?
Not totally clear but if you set the width to 1 it should create new
lines at every available opportunity.
> On searching the news groups, this is the only thread I found similar
> to mine. I can understand how that works for attributes. But I need
> that effect for elements.
> http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg2 7419.html
Keep in mind that if your model is based on a mixed complex type schema,
the formatting of the output will depend precisely on the values in the
mixed text and no changes will be introduced by EMF in that case.
>
> Thanks,
> Karthik
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF serialization - Each element on new line [message #477599 is a reply to message #468418] Thu, 06 August 2009 05:37 Go to previous messageGo to next message
Karthik Srinivasan is currently offline Karthik SrinivasanFriend
Messages: 9
Registered: July 2009
Junior Member
Thank you for your response Ed. Yes, the problem is with elements that are
of mixed type. The contents of all mixed type elements are getting
displayed in a single line. I've tried to explain below with an example.
<elmam/> is of type mixed.

What happens Example -
<elmual src="Item">
<elmam name="ra" type="anim">
asdasdasd<elmle>dataar</elmle>aaaddddddddccccccccccc<elmframe
at="0.0">21.0</elmframe><elmation>0.35</elmation>asddddddd
</elmam>
<elmam name="ox" ref="vw">0.0</elmam>
<elmam name="oy" ref="vh">0.0</elmam>
<elmam name="ax">1</elmam>
</elmual>

What I'd like example -
<elmual src="Item">
<elmam name="ra" type="anim">
asdasdasd
<elmle>dataar</elmle>
aaaddddddddccccccccccc
<elmframe at="0.0">21.0</elmframe>
<elmation>0.35</elmation>
asddddddd
</elmam>
<elmam name="ox" ref="vw">0.0</elmam>
<elmam name="oy" ref="vh">0.0</elmam>
<elmam name="ax">1</elmam>
</elmual>
Re: EMF serialization - Each element on new line [message #477600 is a reply to message #468418] Thu, 06 August 2009 05:40 Go to previous messageGo to next message
Karthik Srinivasan is currently offline Karthik SrinivasanFriend
Messages: 9
Registered: July 2009
Junior Member
Sorry, the 'What I'd like' part got garbled when I posted. :-)
The formatting I'd like is the same as what is displayed (even for mixed
type) when the xml is opened in IE or any other browser.
Re: EMF serialization - Each element on new line [message #478691 is a reply to message #477600] Thu, 06 August 2009 12:29 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Karthik,

As I suggested, in the case of mixed content, the exact values in the
model are preserved character for character so if you want something
different, you have to modify the model itself, or format the
serialization and after that the format will be preserved.


Karthik Srinivasan wrote:
> Sorry, the 'What I'd like' part got garbled when I posted. :-)
> The formatting I'd like is the same as what is displayed (even for
> mixed type) when the xml is opened in IE or any other browser.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF serialization - Each element on new line [message #478864 is a reply to message #478691] Fri, 07 August 2009 09:59 Go to previous messageGo to next message
Karthik Srinivasan is currently offline Karthik SrinivasanFriend
Messages: 9
Registered: July 2009
Junior Member
Ok, I get your point. Trying to format the mixed type from emf will mean
it changes the character sequence which effectively changes the original
content. Can I customize the serializer in anyway to achieve this? Thank
you.
Re: EMF serialization - Each element on new line [message #478888 is a reply to message #478864] Fri, 07 August 2009 11:10 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Karthik,

The XMLString being used to buffer the result knows when it's processing
mixed text, so that could be specialized. Or you could preprocess the
instance...


Karthik Srinivasan wrote:
> Ok, I get your point. Trying to format the mixed type from emf will
> mean it changes the character sequence which effectively changes the
> original content. Can I customize the serializer in anyway to achieve
> this? Thank you.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[CDO] gmf in combination with cdo
Next Topic:Super types for model objects
Goto Forum:
  


Current Time: Wed Apr 24 23:56:31 GMT 2024

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

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

Back to the top