Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF Serialization of collection
EMF Serialization of collection [message #1801561] Tue, 22 January 2019 14:59 Go to next message
The Spoutnik is currently offline The SpoutnikFriend
Messages: 7
Registered: July 2018
Junior Member
Hi,

I am starting from an xText grammar like

Parent :
'children' '{'
(children+=Child)+
'}'

This generates, as expected, an EMF metamodel with a Parent & a Child class plus a [0...*] relationship called children between the Parent & the Child class.

When generating a XML representation of a model instance I got the following:
<children/>
<children/>
...
where I was expecting:
<children>
<child/>
<child/>
</children>

Is there any option to customize the XML generation to achieve the above?

Thanks.
Re: EMF Serialization of collection [message #1801563 is a reply to message #1801561] Tue, 22 January 2019 16:00 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Your expectation is wrong.

Just imagine. The XML serializer would need to know that the singular of children is child. Else you need some metadata to specify the extra information that is not modelled.

If you really want both children and child, you can very easily create an extra class accessed by a children property that has many elements accessed by a child property. But why bloat your model just to make XML, that should not normally be read by humans, cosmetically more pleasing?

(Ed Merks may give a better reply that explains how the ExtendedMetaData can be used to provide the extra metadata for your expectation.)

Regards

Ed Willink

Re: EMF Serialization of collection [message #1801567 is a reply to message #1801563] Tue, 22 January 2019 17:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
With extended metadata annotations on the Ecore model you can direct the serialization to produce "child" elements instead of "children" elements not but to introduce "fake" nesting level to group "child" elements under a "children element". Surely if you have an Xtext grammar the XML serialization is someone irrelevant?

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Serialization of collection [message #1801568 is a reply to message #1801563] Tue, 22 January 2019 17:30 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
With an ExtendedMetaData annotation you can control what XML element name should be used for a feature. Here's an example:

  <eClassifiers xsi:type="ecore:EClass" name="SetupTaskContainer" abstract="true"
      eSuperTypes="../../org.eclipse.oomph.base/model/Base.ecore#//ModelElement">
    <eStructuralFeatures xsi:type="ecore:EReference" name="setupTasks" upperBound="-1"
        eType="#//SetupTask" containment="true">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="name" value="setupTask"/>
      </eAnnotations>
    </eStructuralFeatures>
  </eClassifiers>


I doubt that there's a declarative way to create the intermediate <children> node.


Re: EMF Serialization of collection [message #1801620 is a reply to message #1801568] Wed, 23 January 2019 16:19 Go to previous message
The Spoutnik is currently offline The SpoutnikFriend
Messages: 7
Registered: July 2018
Junior Member
Got it, thanks for the valuable & quick feedback.

Cheers,
L.
Previous Topic:VSand: a game with Vulkan, EMF and JLink.
Next Topic:MagicDraw reading UML Profiles
Goto Forum:
  


Current Time: Fri Apr 26 18:06:48 GMT 2024

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

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

Back to the top