Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Read different kinds of xml files into ecore models
Read different kinds of xml files into ecore models [message #634409] Thu, 21 October 2010 15:20 Go to next message
Peter  is currently offline Peter Friend
Messages: 4
Registered: June 2010
Junior Member
Hi all,

I have some problems to read certain kind of xml constructions into an ecore model, for example read by the "Sample Reflective Ecore Model Editor".
When having an xml model that uses "only attibutes" or "only elements", I can read the information in the "Sample Reflective Ecore Model Editor" correctly. But if I combine the information in both xml attributes and elements, I can not read the information on "element level".

How do I acheive this?
- Change/update the xml schema with ecore annotations?
- Change/update the ecore model defintion in some way?
- Configure the reader how to read the source model?
- Update the source xml files in an other way?
- Change my process?
- any other way?

To better explain my problem, I have done three examples of a model containing a list of "students" with two (logical) attributes "name" and "age".

This could be done in xml in (at least) three different ways.

Case1: (with xml attributes)
[student1.xml]
<?xml version='1.0' encoding="UTF-8"?>

<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="student1.xsd">
<student name="Sarah" age="23"></student>
<student name="Joe" age="27"></student>
<student name="George" age="19"></student>
</doc>

Case2: (with xml elements)
<?xml version='1.0' encoding="UTF-8"?>
[student2.xml]
<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="student2.xsd">
<student>
<name>Sarah</name>
<age>23</age>
</student>
<student>
<name>Joe</name>
<age>27</age>
</student>
<student>
<name>George</name>
<age>19</age>
</student>
</doc>

Case3: (combined xml attributes and elements)
[student3.xml]
<?xml version='1.0' encoding="UTF-8"?>

<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="student3.xsd">
<student age="23">Sarah</student>
<student age="27">Joe</student>
<student age="19">George</student>
</doc>


After that I define an xml schema for each variant, and then I create an ecore meta model by following the "New EMF Project" wizard pointing to the applicable xml schema. This gives following xml schema and ecore model for each variant:

Case1: (with xml attributes)
[student1.xsd]
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="doc">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="student"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="student" type="studenttype"/>
<xs:complexType name="studenttype">
<xs:attribute name="age" use="required" type="xs:integer"/>
<xs:attribute name="name" use="required" type="xs:NCName"/>
</xs:complexType>
</xs:schema>

[Student1.ecore]
<?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="Student1"
nsURI="platform:/resource/students/model/student1.xsd" nsPrefix="Student1">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="qualified" value="false"/>
</eAnnotations>
<eClassifiers xsi:type="ecore:EClass" name="DocType">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="doc_._type"/>
<details key="kind" value="elementOnly"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EReference" name="student" lowerBound="1"
upperBound="-1" eType="#//Studenttype" containment="true" resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="student"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="DocumentRoot">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value=""/>
<details key="kind" value="mixed"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="mixed" unique="false" upperBound="-1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="elementWildcard"/>
<details key="name" value=":mixed"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="xMLNSPrefixMap" upperBound="-1"
eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"
transient="true" containment="true" resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="attribute"/>
<details key="name" value="xmlns:prefix"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="xSISchemaLocation" upperBound="-1"
eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"
transient="true" containment="true" resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="attribute"/>
<details key="name" value="xsi:schemaLocation"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="doc" upperBound="-2" eType="#//DocType"
volatile="true" transient="true" derived="true" containment="true" resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="doc"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="student" upperBound="-2"
eType="#//Studenttype" volatile="true" transient="true" derived="true" containment="true"
resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="student"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Studenttype">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="studenttype"/>
<details key="kind" value="empty"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="age" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Integer">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="attribute"/>
<details key="name" value="age"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//NCName">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="attribute"/>
<details key="name" value="name"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
</ecore:EPackage>


Case2: (with xml elements)
[student2.xsd]
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="doc">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="student"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="student" type="studenttype"/>
<xs:complexType name="studenttype">
<xs:sequence>
<xs:element ref="name"/>
<xs:element ref="age"/>
</xs:sequence>
</xs:complexType>
<xs:element name="name" type="xs:NCName"/>
<xs:element name="age" type="xs:integer"/>
</xs:schema>

[Student2.ecore]
<?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="Student2"
nsURI="platform:/resource/students/model/student2.xsd" nsPrefix="Student2">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="qualified" value="false"/>
</eAnnotations>
<eClassifiers xsi:type="ecore:EClass" name="DocType">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="doc_._type"/>
<details key="kind" value="elementOnly"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EReference" name="student" lowerBound="1"
upperBound="-1" eType="#//Studenttype" containment="true" resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="student"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="DocumentRoot">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value=""/>
<details key="kind" value="mixed"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="mixed" unique="false" upperBound="-1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="elementWildcard"/>
<details key="name" value=":mixed"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="xMLNSPrefixMap" upperBound="-1"
eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"
transient="true" containment="true" resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="attribute"/>
<details key="name" value="xmlns:prefix"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="xSISchemaLocation" upperBound="-1"
eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"
transient="true" containment="true" resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="attribute"/>
<details key="name" value="xsi:schemaLocation"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="age" unique="false" upperBound="-2"
eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Integer"
volatile="true" transient="true" derived="true">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="age"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="doc" upperBound="-2" eType="#//DocType"
volatile="true" transient="true" derived="true" containment="true" resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="doc"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" unique="false" upperBound="-2"
eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//NCName" volatile="true"
transient="true" derived="true">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="name"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="student" upperBound="-2"
eType="#//Studenttype" volatile="true" transient="true" derived="true" containment="true"
resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="student"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Studenttype">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="studenttype"/>
<details key="kind" value="elementOnly"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//NCName">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="name"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="age" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Integer">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="age"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
</ecore:EPackage>


Case3: (combined xml attributes and elements)
[student3.xsd]
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="doc">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="student"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="student" type="studenttype"/>
<xs:complexType name="studenttype">
<xs:simpleContent>
<xs:extension base="xs:NCName">
<xs:attribute name="age" use="required" type="xs:integer"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:schema>

[Student3.ecore]
<?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="Student3"
nsURI="platform:/resource/students/model/student3.xsd" nsPrefix="Student3">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="qualified" value="false"/>
</eAnnotations>
<eClassifiers xsi:type="ecore:EClass" name="DocType">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="doc_._type"/>
<details key="kind" value="elementOnly"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EReference" name="student" lowerBound="1"
upperBound="-1" eType="#//Studenttype" containment="true" resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="student"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="DocumentRoot">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value=""/>
<details key="kind" value="mixed"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="mixed" unique="false" upperBound="-1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="elementWildcard"/>
<details key="name" value=":mixed"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="xMLNSPrefixMap" upperBound="-1"
eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"
transient="true" containment="true" resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="attribute"/>
<details key="name" value="xmlns:prefix"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="xSISchemaLocation" upperBound="-1"
eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"
transient="true" containment="true" resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="attribute"/>
<details key="name" value="xsi:schemaLocation"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="doc" upperBound="-2" eType="#//DocType"
volatile="true" transient="true" derived="true" containment="true" resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="doc"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="student" upperBound="-2"
eType="#//Studenttype" volatile="true" transient="true" derived="true" containment="true"
resolveProxies="false">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="element"/>
<details key="name" value="student"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Studenttype">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value="studenttype"/>
<details key="kind" value="simple"/>
</eAnnotations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//NCName">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="name" value=":0"/>
<details key="kind" value="simple"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="age" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//Integer">
<eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
<details key="kind" value="attribute"/>
<details key="name" value="age"/>
<details key="namespace" value="##targetNamespace"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
</ecore:EPackage>

Then finally, I have changed the xml source files to xmi files...

Case1: (with xml attributes)
[student1.xmi]
<?xml version='1.0' encoding="UTF-8"?>
<Student1:DocumentRoot xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:Student1="platform:/resource/students/model/student1.xsd " xsi:schemaLocation="platform:/resource/students/model/student1.xsd Student1.ecore">
<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="student1.xsd">
<student name="Sarah" age="23"></student>
<student name="Joe" age="27"></student>
<student name="George" age="19"></student>
</doc>
</Student1:DocumentRoot>


Case2: (with xml elements)
<?xml version='1.0' encoding="UTF-8"?>
<Student2:DocumentRoot xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:Student2="platform:/resource/students/model/student2.xsd " xsi:schemaLocation="platform:/resource/students/model/student2.xsd Student2.ecore">

<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="student2.xsd">
<student>
<name>Sarah</name>
<age>23</age>
</student>
<student>
<name>Joe</name>
<age>27</age>
</student>
<student>
<name>George</name>
<age>19</age>
</student>
</doc>
</Student2:DocumentRoot>


Case3: (combined xml attributes and elements)
[student3.xmi]
<?xml version='1.0' encoding="UTF-8"?>
<Student3:DocumentRoot xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:Student3="platform:/resource/students/model/student3.xsd " xsi:schemaLocation="platform:/resource/students/model/student3.xsd Student3.ecore">

<doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="student3.xsd">
<student age="23">Sarah</student>
<student age="27">Joe</student>
<student age="19">George</student>
</doc>
</Student3:DocumentRoot>

And now, when reading these files with "Sample Reflective Ecore Model Editor" I can see the attributes "name" and "age" in case 1 and case 2.
But not in case 3!!
In case 3 I only get the value of the age attribute. (In case 3, the "name" attribute will in ecore get the name "value" that in the annotations points to ":0", see red marks above. But the value of the "value" attribute is empty in the "Sample Reflective Ecore Model Editor"...)

The question is why!

If someone could explain this for me and guide me how to proceed I would be very greatful.

Thanks,
Peter
Re: Read different kinds of xml files into ecore models [message #634420 is a reply to message #634409] Thu, 21 October 2010 15:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050306050106010006080503
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Peter,

Comments below.


Peter wrote:
> Hi all,
>
> I have some problems to read certain kind of xml constructions into an
> ecore model, for example read by the "Sample Reflective Ecore Model
> Editor".
> When having an xml model that uses "only attibutes" or "only
> elements", I can read the information in the "Sample Reflective Ecore
> Model Editor" correctly. But if I combine the information in both xml
> attributes and elements, I can not read the information on "element
> level".
You likely need to use Sample Reflective Ecore *XML *Model Editor if
you're relying on deserializing instances from models based on XML Schema.
>
> How do I acheive this?
> - Change/update the xml schema with ecore annotations?
> - Change/update the ecore model defintion in some way?
> - Configure the reader how to read the source model?
It's important the options you see in the generated
XyzResourceFactoryImpl be used.
> - Update the source xml files in an other way?
> - Change my process?
> - any other way?
>
> To better explain my problem, I have done three examples of a model
> containing a list of "students" with two (logical) attributes "name"
> and "age".
>
> This could be done in xml in (at least) three different ways.
>
> Case1: (with xml attributes)
> [student1.xml]
> <?xml version='1.0' encoding="UTF-8"?>
>
> <doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="student1.xsd">
> <student name="Sarah" age="23"></student>
> <student name="Joe" age="27"></student>
> <student name="George" age="19"></student>
> </doc>
>
> Case2: (with xml elements)
> <?xml version='1.0' encoding="UTF-8"?>
> [student2.xml]
> <doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="student2.xsd">
> <student>
> <name>Sarah</name>
> <age>23</age>
> </student>
> <student>
> <name>Joe</name>
> <age>27</age>
> </student>
> <student>
> <name>George</name>
> <age>19</age>
> </student>
> </doc>
>
> Case3: (combined xml attributes and elements)
> [student3.xml]
> <?xml version='1.0' encoding="UTF-8"?>
>
> <doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="student3.xsd">
> <student age="23">Sarah</student>
> <student age="27">Joe</student>
> <student age="19">George</student>
> </doc>
>
>
> After that I define an xml schema for each variant, and then I create
> an ecore meta model by following the "New EMF Project" wizard pointing
> to the applicable xml schema. This gives following xml schema and
> ecore model for each variant:
>
> Case1: (with xml attributes)
> [student1.xsd]
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified">
> <xs:element name="doc">
> <xs:complexType>
> <xs:sequence>
> <xs:element maxOccurs="unbounded" ref="student"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="student" type="studenttype"/>
> <xs:complexType name="studenttype">
> <xs:attribute name="age" use="required" type="xs:integer"/>
> <xs:attribute name="name" use="required" type="xs:NCName"/>
> </xs:complexType>
> </xs:schema>
>
> [Student1.ecore]
> <?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="Student1"
> nsURI="platform:/resource/students/model/student1.xsd"
> nsPrefix="Student1">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="qualified" value="false"/>
> </eAnnotations>
> <eClassifiers xsi:type="ecore:EClass" name="DocType">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="doc_._type"/>
> <details key="kind" value="elementOnly"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EReference" name="student"
> lowerBound="1"
> upperBound="-1" eType="#//Studenttype" containment="true"
> resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="student"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="DocumentRoot">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value=""/>
> <details key="kind" value="mixed"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="mixed"
> unique="false" upperBound="-1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="elementWildcard"/>
> <details key="name" value=":mixed"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference"
> name="xMLNSPrefixMap" upperBound="-1"
> eType="ecore:EClass
> http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"
> transient="true" containment="true" resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="attribute"/>
> <details key="name" value="xmlns:prefix"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference"
> name="xSISchemaLocation" upperBound="-1"
> eType="ecore:EClass
> http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"
> transient="true" containment="true" resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="attribute"/>
> <details key="name" value="xsi:schemaLocation"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference" name="doc"
> upperBound="-2" eType="#//DocType"
> volatile="true" transient="true" derived="true"
> containment="true" resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="doc"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference" name="student"
> upperBound="-2"
> eType="#//Studenttype" volatile="true" transient="true"
> derived="true" containment="true"
> resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="student"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Studenttype">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="studenttype"/>
> <details key="kind" value="empty"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="age"
> lowerBound="1" eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//Integer">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="attribute"/>
> <details key="name" value="age"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> lowerBound="1" eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//NCName">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="attribute"/>
> <details key="name" value="name"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
> </ecore:EPackage>
>
>
> Case2: (with xml elements)
> [student2.xsd]
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified">
> <xs:element name="doc">
> <xs:complexType>
> <xs:sequence>
> <xs:element maxOccurs="unbounded" ref="student"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="student" type="studenttype"/>
> <xs:complexType name="studenttype">
> <xs:sequence>
> <xs:element ref="name"/>
> <xs:element ref="age"/>
> </xs:sequence>
> </xs:complexType>
> <xs:element name="name" type="xs:NCName"/>
> <xs:element name="age" type="xs:integer"/>
> </xs:schema>
>
> [Student2.ecore]
> <?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="Student2"
> nsURI="platform:/resource/students/model/student2.xsd"
> nsPrefix="Student2">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="qualified" value="false"/>
> </eAnnotations>
> <eClassifiers xsi:type="ecore:EClass" name="DocType">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="doc_._type"/>
> <details key="kind" value="elementOnly"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EReference" name="student"
> lowerBound="1"
> upperBound="-1" eType="#//Studenttype" containment="true"
> resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="student"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="DocumentRoot">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value=""/>
> <details key="kind" value="mixed"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="mixed"
> unique="false" upperBound="-1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="elementWildcard"/>
> <details key="name" value=":mixed"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference"
> name="xMLNSPrefixMap" upperBound="-1"
> eType="ecore:EClass
> http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"
> transient="true" containment="true" resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="attribute"/>
> <details key="name" value="xmlns:prefix"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference"
> name="xSISchemaLocation" upperBound="-1"
> eType="ecore:EClass
> http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"
> transient="true" containment="true" resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="attribute"/>
> <details key="name" value="xsi:schemaLocation"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="age"
> unique="false" upperBound="-2"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//Integer"
> volatile="true" transient="true" derived="true">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="age"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference" name="doc"
> upperBound="-2" eType="#//DocType"
> volatile="true" transient="true" derived="true"
> containment="true" resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="doc"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> unique="false" upperBound="-2"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//NCName" volatile="true"
> transient="true" derived="true">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="name"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference" name="student"
> upperBound="-2"
> eType="#//Studenttype" volatile="true" transient="true"
> derived="true" containment="true"
> resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="student"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Studenttype">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="studenttype"/>
> <details key="kind" value="elementOnly"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="name"
> lowerBound="1" eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//NCName">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="name"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="age"
> lowerBound="1" eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//Integer">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="age"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
> </ecore:EPackage>
>
>
> Case3: (combined xml attributes and elements)
> [student3.xsd]
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified">
> <xs:element name="doc">
> <xs:complexType>
> <xs:sequence>
> <xs:element maxOccurs="unbounded" ref="student"/>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="student" type="studenttype"/>
> <xs:complexType name="studenttype">
> <xs:simpleContent>
> <xs:extension base="xs:NCName">
> <xs:attribute name="age" use="required" type="xs:integer"/>
> </xs:extension>
> </xs:simpleContent>
> </xs:complexType>
> </xs:schema>
>
> [Student3.ecore]
> <?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="Student3"
> nsURI="platform:/resource/students/model/student3.xsd"
> nsPrefix="Student3">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="qualified" value="false"/>
> </eAnnotations>
> <eClassifiers xsi:type="ecore:EClass" name="DocType">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="doc_._type"/>
> <details key="kind" value="elementOnly"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EReference" name="student"
> lowerBound="1"
> upperBound="-1" eType="#//Studenttype" containment="true"
> resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="student"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="DocumentRoot">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value=""/>
> <details key="kind" value="mixed"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="mixed"
> unique="false" upperBound="-1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="elementWildcard"/>
> <details key="name" value=":mixed"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference"
> name="xMLNSPrefixMap" upperBound="-1"
> eType="ecore:EClass
> http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"
> transient="true" containment="true" resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="attribute"/>
> <details key="name" value="xmlns:prefix"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference"
> name="xSISchemaLocation" upperBound="-1"
> eType="ecore:EClass
> http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"
> transient="true" containment="true" resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="attribute"/>
> <details key="name" value="xsi:schemaLocation"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference" name="doc"
> upperBound="-2" eType="#//DocType"
> volatile="true" transient="true" derived="true"
> containment="true" resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="doc"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference" name="student"
> upperBound="-2"
> eType="#//Studenttype" volatile="true" transient="true"
> derived="true" containment="true"
> resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="student"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="Studenttype">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="studenttype"/>
> <details key="kind" value="simple"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="value"
> eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//NCName">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value=":0"/>
> <details key="kind" value="simple"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="age"
> lowerBound="1" eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//Integer">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="attribute"/>
> <details key="name" value="age"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
> </ecore:EPackage>
>
> Then finally, I have changed the xml source files to xmi files...
>
> Case1: (with xml attributes)
> [student1.xmi]
> <?xml version='1.0' encoding="UTF-8"?>
> <Student1:DocumentRoot xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:Student1="platform:/resource/students/model/student1.xsd "
> xsi:schemaLocation="platform:/resource/students/model/student1.xsd
> Student1.ecore">
> <doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="student1.xsd">
> <student name="Sarah" age="23"></student>
> <student name="Joe" age="27"></student>
> <student name="George" age="19"></student>
> </doc>
> </Student1:DocumentRoot>
>
>
> Case2: (with xml elements)
> <?xml version='1.0' encoding="UTF-8"?>
> <Student2:DocumentRoot xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:Student2="platform:/resource/students/model/student2.xsd "
> xsi:schemaLocation="platform:/resource/students/model/student2.xsd
> Student2.ecore">
>
> <doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="student2.xsd">
> <student>
> <name>Sarah</name>
> <age>23</age>
> </student>
> <student>
> <name>Joe</name>
> <age>27</age>
> </student>
> <student>
> <name>George</name>
> <age>19</age>
> </student>
> </doc>
> </Student2:DocumentRoot>
>
>
> Case3: (combined xml attributes and elements)
> [student3.xmi]
> <?xml version='1.0' encoding="UTF-8"?>
> <Student3:DocumentRoot xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:Student3="platform:/resource/students/model/student3.xsd "
> xsi:schemaLocation="platform:/resource/students/model/student3.xsd
> Student3.ecore">
>
> <doc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="student3.xsd">
> <student age="23">Sarah</student>
> <student age="27">Joe</student>
> <student age="19">George</student>
> </doc>
> </Student3:DocumentRoot>
>
> And now, when reading these files with "Sample Reflective Ecore Model
> Editor" I can see the attributes "name" and "age" in case 1 and case 2.
> But not in case 3!! In case 3 I only get the value of the age
> attribute. (In case 3, the "name" attribute will in ecore get the name
> "value" that in the annotations points to ":0", see red marks above.
> But the value of the "value" attribute is empty in the "Sample
> Reflective Ecore Model Editor"...)
>
> The question is why!
>
> If someone could explain this for me and guide me how to proceed I
> would be very greatful.
>
> Thanks,
> Peter
>

--------------050306050106010006080503
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Peter,<br>
<br>
Comments below.<br>
<br>
<br>
Peter wrote:
<blockquote cite="mid:i9plhg$cpr$1@news.eclipse.org" type="cite">Hi
all,
<br>
<br>
I have some problems to read certain kind of xml constructions into an
ecore model, for example read by the "Sample Reflective Ecore Model
Editor".
<br>
When having an xml model that uses "only attibutes" or "only elements",
I can read the information in the "Sample Reflective Ecore Model
Editor" correctly. But if I combine the information in both xml
attributes and elements, I can not read the information on "element
level".
<br>
</blockquote>
You likely need to use Sample Reflective Ecore <b>XML </b>Model
Editor if you're relying on deserializing instances from models based
on XML Schema.<br>
<blockquote cite="mid:i9plhg$cpr$1@news.eclipse.org" type="cite"><br>
How do I acheive this?
<br>
- Change/update the xml schema with ecore annotations?
<br>
- Change/update the ecore model defintion in some way?
<br>
- Configure the reader how to read the source model?
<br>
</blockquote>
It's important the options you see in the generated
XyzResourceFactoryImpl be used.<br>
<blockquote cite="mid:i9plhg$cpr$1@news.eclipse.org" type="cite">-
Update the source xml files in an other way?
<br>
- Change my process?
<br>
- any other way?
<br>
<br>
To better explain my problem, I have done three examples of a model
containing a list of "students" with two (logical) attributes "name"
and "age".
<br>
<br>
This could be done in xml in (at least) three different ways.
<br>
<br>
Case1: (with xml attributes)
<br>
[student1.xml]
<br>
&lt;?xml version='1.0' encoding="UTF-8"?&gt;
<br>
<br>
&lt;doc xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xsi:noNamespaceSchemaLocation="student1.xsd"&gt;
<br>
 &lt;student name="Sarah" age="23"&gt;&lt;/student&gt;
<br>
 &lt;student name="Joe" age="27"&gt;&lt;/student&gt;
<br>
 &lt;student name="George" age="19"&gt;&lt;/student&gt;
<br>
&lt;/doc&gt;
<br>
<br>
Case2: (with xml elements)
<br>
&lt;?xml version='1.0' encoding="UTF-8"?&gt;
<br>
[student2.xml]
<br>
&lt;doc xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xsi:noNamespaceSchemaLocation="student2.xsd"&gt;
<br>
 &lt;student&gt;
<br>
   &lt;name&gt;Sarah&lt;/name&gt;
<br>
   &lt;age&gt;23&lt;/age&gt;
<br>
 &lt;/student&gt;
<br>
 &lt;student&gt;
<br>
   &lt;name&gt;Joe&lt;/name&gt;
<br>
   &lt;age&gt;27&lt;/age&gt;
<br>
 &lt;/student&gt;
<br>
 &lt;student&gt;
<br>
   &lt;name&gt;George&lt;/name&gt;
<br>
   &lt;age&gt;19&lt;/age&gt;
<br>
 &lt;/student&gt;
<br>
&lt;/doc&gt;
<br>
<br>
Case3: (combined xml attributes and elements)
<br>
[student3.xml]
<br>
&lt;?xml version='1.0' encoding="UTF-8"?&gt;
<br>
<br>
&lt;doc xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xsi:noNamespaceSchemaLocation="student3.xsd"&gt;
<br>
 &lt;student age="23"&gt;Sarah&lt;/student&gt;
<br>
 &lt;student age="27"&gt;Joe&lt;/student&gt;
<br>
 &lt;student age="19"&gt;George&lt;/student&gt;
<br>
&lt;/doc&gt;
<br>
<br>
<br>
After that I define an xml schema for each variant, and then I create
an ecore meta model by following the "New EMF Project" wizard pointing
to the applicable xml schema. This gives following xml schema and ecore
model for each variant:
<br>
<br>
Case1: (with xml attributes)
<br>
[student1.xsd]
<br>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<br>
&lt;xs:schema xmlns:xs=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>
elementFormDefault="qualified"&gt;
<br>
 &lt;xs:element name="doc"&gt;
<br>
   &lt;xs:complexType&gt;
<br>
     &lt;xs:sequence&gt;
<br>
       &lt;xs:element maxOccurs="unbounded" ref="student"/&gt;
<br>
     &lt;/xs:sequence&gt;
<br>
   &lt;/xs:complexType&gt;
<br>
 &lt;/xs:element&gt;
<br>
 &lt;xs:element name="student" type="studenttype"/&gt;
<br>
 &lt;xs:complexType name="studenttype"&gt;
<br>
   &lt;xs:attribute name="age" use="required" type="xs:integer"/&gt;
<br>
   &lt;xs:attribute name="name" use="required" type="xs:NCName"/&gt;
<br>
 &lt;/xs:complexType&gt;
<br>
&lt;/xs:schema&gt;
<br>
<br>
[Student1.ecore]
<br>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<br>
&lt;ecore:EPackage xmi:version="2.0"
<br>
   xmlns:xmi=<a class="moz-txt-link-rfc2396E" href="http://www.omg.org/XMI">"http://www.omg.org/XMI"</a>
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
<br>
   xmlns:ecore=<a class="moz-txt-link-rfc2396E" href="http://www.eclipse.org/emf/2002/Ecore">"http://www.eclipse.org/emf/2002/Ecore"</a> name="Student1"
<br>
   nsURI="platform:/resource/students/model/student1.xsd"
nsPrefix="Student1"&gt;
<br>
 &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
   &lt;details key="qualified" value="false"/&gt;
<br>
 &lt;/eAnnotations&gt;
<br>
 &lt;eClassifiers xsi:type="ecore:EClass" name="DocType"&gt;
<br>
   &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
     &lt;details key="name" value="doc_._type"/&gt;
<br>
     &lt;details key="kind" value="elementOnly"/&gt;
<br>
   &lt;/eAnnotations&gt;
<br>
   &lt;eStructuralFeatures xsi:type="ecore:EReference" name="student"
lowerBound="1"
<br>
       upperBound="-1" eType="#//Studenttype" containment="true"
resolveProxies="false"&gt;
<br>
     &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
       &lt;details key="kind" value="element"/&gt;
<br>
       &lt;details key="name" value="student"/&gt;
<br>
       &lt;details key="namespace" value="##targetNamespace"/&gt;
<br>
     &lt;/eAnnotations&gt;
<br>
   &lt;/eStructuralFeatures&gt;
<br>
 &lt;/eClassifiers&gt;
<br>
 &lt;eClassifiers xsi:type="ecore:EClass" name="DocumentRoot"&gt;
<br>
   &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
     &lt;details key="name" value=""/&gt;
<br>
     &lt;details key="kind" value="mixed"/&gt;
<br>
   &lt;/eAnnotations&gt;
<br>
   &lt;eStructuralFeatures xsi:type="ecore:EAttribute" name="mixed"
unique="false" upperBound="-1"
<br>
       eType="ecore:EDataType
<a class="moz-txt-link-freetext" href="http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry</a>"&gt;
<br>
     &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
       &lt;details key="kind" value="elementWildcard"/&gt;
<br>
       &lt;details key="name" value=":mixed"/&gt;
<br>
     &lt;/eAnnotations&gt;
<br>
   &lt;/eStructuralFeatures&gt;
<br>
   &lt;eStructuralFeatures xsi:type="ecore:EReference"
name="xMLNSPrefixMap" upperBound="-1"
<br>
       eType="ecore:EClass
<a class="moz-txt-link-freetext" href=" http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"> http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try</a>"
<br>
       transient="true" containment="true" resolveProxies="false"&gt;
<br>
     &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
       &lt;details key="kind" value="attribute"/&gt;
<br>
       &lt;details key="name" value="xmlns:prefix"/&gt;
<br>
     &lt;/eAnnotations&gt;
<br>
   &lt;/eStructuralFeatures&gt;
<br>
   &lt;eStructuralFeatures xsi:type="ecore:EReference"
name="xSISchemaLocation" upperBound="-1"
<br>
       eType="ecore:EClass
<a class="moz-txt-link-freetext" href=" http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"> http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try</a>"
<br>
       transient="true" containment="true" resolveProxies="false"&gt;
<br>
     &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
       &lt;details key="kind" value="attribute"/&gt;
<br>
       &lt;details key="name" value="xsi:schemaLocation"/&gt;
<br>
     &lt;/eAnnotations&gt;
<br>
   &lt;/eStructuralFeatures&gt;
<br>
   &lt;eStructuralFeatures xsi:type="ecore:EReference" name="doc"
upperBound="-2" eType="#//DocType"
<br>
       volatile="true" transient="true" derived="true"
containment="true" resolveProxies="false"&gt;
<br>
     &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
       &lt;details key="kind" value="element"/&gt;
<br>
       &lt;details key="name" value="doc"/&gt;
<br>
       &lt;details key="namespace" value="##targetNamespace"/&gt;
<br>
     &lt;/eAnnotations&gt;
<br>
   &lt;/eStructuralFeatures&gt;
<br>
   &lt;eStructuralFeatures xsi:type="ecore:EReference" name="student"
upperBound="-2"
<br>
       eType="#//Studenttype" volatile="true" transient="true"
derived="true" containment="true"
<br>
       resolveProxies="false"&gt;
<br>
     &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
       &lt;details key="kind" value="element"/&gt;
<br>
       &lt;details key="name" value="student"/&gt;
<br>
       &lt;details key="namespace" value="##targetNamespace"/&gt;
<br>
     &lt;/eAnnotations&gt;
<br>
   &lt;/eStructuralFeatures&gt;
<br>
 &lt;/eClassifiers&gt;
<br>
 &lt;eClassifiers xsi:type="ecore:EClass" name="Studenttype"&gt;
<br>
   &lt;eAnnotations
source=<a class="moz-txt-link-rfc2396E" href="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">"http:///org/eclipse/emf/ecore/util/ExtendedMetaData"</a>&gt;
<br>
     &lt;details key="name" value="studenttype"/&gt;
<br>
     &lt;details key="kind" value="empty"/&am


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Read different kinds of xml files into ecore models [message #634547 is a reply to message #634409] Fri, 22 October 2010 07:33 Go to previous messageGo to next message
Peter  is currently offline Peter Friend
Messages: 4
Registered: June 2010
Junior Member
Thanks Ed,
for your rapid reply.

The "Sample Reflective Ecore Xml Model Editor" worked fine also for the third case.

I suppose the options you talk about is
OPTION_EXTENDED_META_DATA
OPTION_SCHEMA_LOCATION
OPTION_USE_ENCODED_ATTRIBUTE_STYLE
OPTION_USE_LEXICAL_HANDLER

My question is then, how do I configure the reader with these options?

To get this in the context what I really want to acheive:

We have a number of source models that we want to transform to code (mostly C code).
At the moment, the transformations are done with QVTo and Xpand/Xtend.

The source models are in different formats, such as UML (ecore) and xml schema based xml.
As long as the xml schema based xml files are constructed as case 1 and 2 in my examples, this works fine (more or less following the same procedure as described in my examples.)

When attributes and elements are "combined" as in case 3, it doesn't...

(The symptoms in QVTo are exactly the same as for the "Sample Reflective Ecore Model Editor", which is the reason I got from the QVTo context to the emf/ecore/xsd context when trying to figure out the root cause of the problem...)

So basically, to summarize, I suppose (??) the core is to configure the reader. And then the question is, how do I do that?

Thanks again,
Peter
Re: Read different kinds of xml files into ecore models [message #634696 is a reply to message #634547] Fri, 22 October 2010 18:01 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Peter,

Comments below.

Peter wrote:
> Thanks Ed,
> for your rapid reply.
>
> The "Sample Reflective Ecore Xml Model Editor" worked fine also for
> the third case.
>
> I suppose the options you talk about is
> OPTION_EXTENDED_META_DATA
> OPTION_SCHEMA_LOCATION
> OPTION_USE_ENCODED_ATTRIBUTE_STYLE
> OPTION_USE_LEXICAL_HANDLER
Yes.
>
> My question is then, how do I configure the reader with these options?
The generated resource factory configures the resource properly.
>
> To get this in the context what I really want to acheive:
>
> We have a number of source models that we want to transform to code
> (mostly C code). At the moment, the transformations are done with QVTo
> and Xpand/Xtend.
>
> The source models are in different formats, such as UML (ecore) and
> xml schema based xml.
> As long as the xml schema based xml files are constructed as case 1
> and 2 in my examples, this works fine (more or less following the same
> procedure as described in my examples.)
>
> When attributes and elements are "combined" as in case 3, it doesn't...
I'm not sure I follow.
>
> (The symptoms in QVTo are exactly the same as for the "Sample
> Reflective Ecore Model Editor", which is the reason I got from the
> QVTo context to the emf/ecore/xsd context when trying to figure out
> the root cause of the problem...)
It all comes down to using the right resource factory to create the
resource used to load the content. Generally that's done by
registering against the file extension.
>
> So basically, to summarize, I suppose (??) the core is to configure
> the reader. And then the question is, how do I do that?
Look at the generated XyzExample.java when you invoke Generate Test Code
for an example.
>
> Thanks again,
> Peter
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:modify the semantic model in the table viewer
Next Topic:Saving two eResource
Goto Forum:
  


Current Time: Thu Mar 28 21:15:55 GMT 2024

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

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

Back to the top