Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF reference and referenced entities as elements in XML
EMF reference and referenced entities as elements in XML [message #1213717] Wed, 27 November 2013 11:06 Go to next message
Markus Franz is currently offline Markus FranzFriend
Messages: 38
Registered: July 2009
Member
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 #1213796 is a reply to message #1213717] Wed, 27 November 2013 11:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
Markus,

You're trying to insert an additional level of XML tag nesting but no
annotation will do that for you.


On 27/11/2013 12:06 PM, Markus Franz wrote:
> 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


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF reference and referenced entities as elements in XML [message #1213807 is a reply to message #1213796] Wed, 27 November 2013 12:01 Go to previous messageGo to next message
Markus Franz is currently offline Markus FranzFriend
Messages: 38
Registered: July 2009
Member
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?
Re: EMF reference and referenced entities as elements in XML [message #1214427 is a reply to message #1213807] Wed, 27 November 2013 17:50 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33133
Registered: July 2009
Senior Member
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?


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Code Generation Error for Meta Model Element named Enumeration
Next Topic:[xcore] IndexOutOfBoundsException
Goto Forum:
  


Current Time: Tue Apr 16 13:05:06 GMT 2024

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

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

Back to the top