EMF reference and referenced entities as elements in XML [message #1213717] |
Wed, 27 November 2013 06:06  |
Eclipse User |
|
|
|
Hi,
i am trying to find a way to annotate my model so that an EReference sturctural feature, as well as the referenced eClassifiers are serialized as XML elements.
To be clearer what i want is an XML that looks something like:
<?xml version="1.0" encoding="UTF-8"?>
<AUTOSAR xmlns="http://autosar.org/schema/r4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://autosar.org/schema/r4.0">
<AR-PACKAGES>
<AR-PACKAGE>
<SHORT-NAME>tl1</SHORT-NAME>
<AR-PACKAGES>
<AR-PACKAGE>
<SHORT-NAME>sub1</SHORT-NAME>
</AR-PACKAGE>
<AR-PACKAGE>
<SHORT-NAME>sub2</SHORT-NAME>
</AR-PACKAGE>
</AR-PACKAGES>
</AR-PACKAGE>
<AR-PACKAGE>
<SHORT-NAME>tl2</SHORT-NAME>
</AR-PACKAGE>
<AR-PACKAGES>
</AUTOSAR>
But what i get is something like this:
<?xml version="1.0" encoding="UTF-8"?>
<AUTOSAR xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="null http://autosar.org/schema/r4.0/autosar40/tl">
<AR-PACKAGES>
<SHORTNAME>tl1</SHORTNAME>
<AR-PACKAGES>
<SHORTNAME>sub1</SHORTNAME>
</AR-PACKAGES>
<AR-PACKAGES>
<SHORTNAME>sub2</SHORTNAME>
</AR-PACKAGES>
</AR-PACKAGES>
<AR-PACKAGES>
<SHORTNAME>tl2</SHORTNAME>
</AR-PACKAGES>
</AUTOSAR>
The ecore i created is the following:
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="autosar" nsURI="http://autosar.org/schema/r4.0/autosar40" nsPrefix="">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="qualified" value="false"/>
</eAnnotations>
<eSubpackages name="toplevel" nsURI="http://autosar.org/schema/r4.0/autosar40/tl"
nsPrefix="">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="qualified" value="false"/>
</eAnnotations>
<eClassifiers xsi:type="ecore:EClass" name="Autosar">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="mixed"/>
<details key="name" value="AUTOSAR"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="shortname" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="SHORTNAME"/>
<details key="kind" value="element"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="arPackages" upperBound="-1"
eType="#//templates/ArPackage" containment="true">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="AR-PACKAGES"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
</eSubpackages>
<eSubpackages name="templates" nsURI="http://autosar.org/schema/r4.0/autosar40/templ"
nsPrefix="">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="qualified" value="false"/>
</eAnnotations>
<eClassifiers xsi:type="ecore:EClass" name="ArPackage">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="AR-PACKAGE"/>
<details key="kind" value="element"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="shortname" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="SHORTNAME"/>
<details key="kind" value="element"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="arPackages" upperBound="-1"
eType="#//templates/ArPackage" containment="true">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="AR-PACKAGES"/>
<details key="kind" value="element"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
</eSubpackages>
</ecore:EPackage>
Any help would be much appreciated...
Markus
|
|
|
|
|
Re: EMF reference and referenced entities as elements in XML [message #1214427 is a reply to message #1213807] |
Wed, 27 November 2013 12:50  |
Eclipse User |
|
|
|
Markus,
Yes, those are pretty much your only options. Both XMLSaveImpl and
XMLHandler would need significant tweaking...
On 27/11/2013 1:01 PM, Markus Franz wrote:
> Hi Ed,
>
> that is what i feared. So i either have to insert additional model
> elements (which i don't want to do, because the model will be
> generated from a different source and i want to keep my additions
> there minimal, preferably only via annotations) or i have to implement
> the desired reading/writing behavior directly inside a custom
> XMLResourceImpl, am i correct?
|
|
|
Powered by
FUDForum. Page generated in 0.04378 seconds