Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » True Support of XML Comments(EMF XMLComments)
True Support of XML Comments [message #728745] Fri, 23 September 2011 20:18 Go to next message
Erik Englund is currently offline Erik EnglundFriend
Messages: 49
Registered: July 2009
Member
So I've read several articles and new posts on this but I'm still stumped.

So far I realize to support the serialization of Comments and whitespace within EMF you need to mark all your Complex types as ecore:mixed="true".

You need also to enable the options XMLResource.OPTIONS_USE_LEXICAL_HANDLER.

This works in that comments are now correctly stored and saved in my model. Great!

Now lets add another element to the model.

The new model element is not formatted at all. Sad

Example:
Before:
<root>
</root>
After:
<root><new element><new subelement/><new element>
</root>

Ok, so I traced this to the XMLString class. Whenever, it sees that an element is mixed it basically throws it hands up and says it won't try to format the new element at all. Well, I was able to get around most of this by writing my own XMLString class to attempt to format the element anyway. It's not perfect but it is better than nothing.

Has anyone else had any luck with this?

Anyway, so I was pretty happy about this. Now lets add another element within this element.

Hmm, they didn't show up in the correct order and produced invalid xml. Mad

For instance:
xsd:
<root>
<sequence>
<element a>
<element b>
</sequence>
</root>

Before:
<root>
<b/>
</root>

After:
<root>
<b/>
<a/>
</root>

I believe this is due to the way the FeatureMap is used. That on save it basically iterates over the contents of the FeatureMap and adds them in the order they were added in. This works great for groups, but I have a strict sequence in my xsd.

Help?
Re: True Support of XML Comments [message #728787 is a reply to message #728745] Fri, 23 September 2011 22:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Erik,

Non-xml comments below. :-P

On 23/09/2011 1:18 PM, Erik Englund wrote:
> So I've read several articles and new posts on this but I'm still
> stumped.
>
> So far I realize to support the serialization of Comments and
> whitespace within EMF you need to mark all your Complex types as
> ecore:mixed="true".
Yes.
> You need also to enable the options
> XMLResource.OPTIONS_USE_LEXICAL_HANDLER.
Indeed.
>
> This works in that comments are now correctly stored and saved in my
> model. Great!
>
> Now lets add another element to the model.
>
> The new model element is not formatted at all. :(
No, you've taken control of the whitespace...
>
> Example:
> Before:
> <root>
> </root>
> After:
> <root><new element><new subelement/><new element>
> </root>
>
> Ok, so I traced this to the XMLString class. Whenever, it sees that
> an element is mixed it basically throws it hands up and says it won't
> try to format the new element at all.
Yes.
> Well, I was able to get around most of this by writing my own
> XMLString class to attempt to format the element anyway. It's not
> perfect but it is better than nothing.
> Has anyone else had any luck with this?
I've not tried.
>
> Anyway, so I was pretty happy about this. Now lets add another element
> within this element.
>
> Hmm, they didn't show up in the correct order and produced invalid
> xml. :x
> For instance:
> xsd:
> <root>
> <sequence>
> <element a>
> <element b>
> </sequence>
> </root>
>
> Before:
> <root>
> <b/>
> </root>
>
> After:
> <root>
> <b/>
> <a/>
> </root>
>
> I believe this is due to the way the FeatureMap is used. That on save
> it basically iterates over the contents of the FeatureMap and adds
> them in the order they were added in.
Yes, a feature map preserves the absolute order.
> This works great for groups, but I have a strict sequence in my xsd.
Yes, it even records an incorrect order.
>
> Help?
I suppose you could reprocess the feature map entries to change their
order to reflect the feature order in the EClass.

It's all kind of yucky and mostly works okay only when the original XML
is formatted and you want to preserve that. If you create from scratch,
it's far more difficult to set features in the right order, and add nice
whitespace for indentation. I'm not sure there's much I can suggest.
Suggesting you not use comments but rather define annotations as part of
the model isn't all that constructive...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: True Support of XML Comments [message #728831 is a reply to message #728787] Sat, 24 September 2011 02:10 Go to previous messageGo to next message
Erik Englund is currently offline Erik EnglundFriend
Messages: 49
Registered: July 2009
Member
Thanks for the quick response Ed.

Unfortunately, the scheme is an external scheme of which I have no control.

To make matters worse the users have in the past edited these XML files by hand, so they are used to inserting comments.

I suppose I could add a listener to the FeatureMap that automatically sorts it on changes. But that means adding a listener and sorter for EACH object type.
Re: True Support of XML Comments [message #728963 is a reply to message #728831] Sat, 24 September 2011 15:21 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Erik,

You could do some preprocessing of the model before/during Save. You
could use OPTION_RESOURCE_HANDLER for that. If the issue is mostly
about what happens in the editor, you could specialize the commands
(SetCommand/AddCommand) so that they create a feature map entry and
insert it in a correct location rather than calling eSet/eGet().add as
they do by default. No doubt you could implement the logic for it once
and reuse it for all these feature map cases...


On 23/09/2011 7:10 PM, Erik Englund wrote:
> Thanks for the quick response Ed.
>
> Unfortunately, the scheme is an external scheme of which I have no
> control.
> To make matters worse the users have in the past edited these XML
> files by hand, so they are used to inserting comments.
>
> I suppose I could add a listener to the FeatureMap that automatically
> sorts it on changes. But that means adding a listener and sorter for
> EACH object type.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:XMLResource mixes up attributes/elements eventhough there is a namespace
Next Topic:cross references & actual container
Goto Forum:
  


Current Time: Thu Apr 25 14:29:04 GMT 2024

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

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

Back to the top