Skip to main content



      Home
Home » Modeling » EMF » EMF Serialization of collection
EMF Serialization of collection [message #1801561] Tue, 22 January 2019 09:59 Go to next message
Eclipse UserFriend
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 11:00 Go to previous messageGo to next message
Eclipse UserFriend
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 12:30 Go to previous messageGo to next message
Eclipse UserFriend
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?
Re: EMF Serialization of collection [message #1801568 is a reply to message #1801563] Tue, 22 January 2019 12:30 Go to previous messageGo to next message
Eclipse UserFriend
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 11:19 Go to previous message
Eclipse UserFriend
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 Jul 04 20:51:40 EDT 2025

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

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

Back to the top