|Re: Customize XML serialization with EMF [message #953777 is a reply to message #953733]
||Mon, 22 October 2012 14:19
| Ed Merks
Registered: July 2009
On 22/10/2012 3:45 PM, Philippe Favrais wrote:
> In fact, i have many XML files which match all different XSD files.
> Here is one example of XML file
> <ADC_SETTINGS_UNIT1 AdcClockOff="No" AdcOverWrite="No"/>
> and the corresponding XSD :
> <xs:element name="ADC_SETTINGS_UNIT1">
> <xs:attribute name="AdcClockOff" type="Type_Boolean" use="optional" default="No"/>
> <xs:attribute name="AdcOverWrite" type="Type_Boolean" use="optional" default="No"/>
> As i have many different XML and different XSD, my intention is to load all my different XML in a same Emf MetaModel. (Below, i copied below my ecore MetaModel)
> So I have defined a mapping between my XML/XSD and my Emf MetaModel, now i need to implement a specific load and save so that my XML files get loaded/saved in Emf.
As I said, you'll have to do that by hand.
In the end, this all seems kind of pointless though. What value do you
get from your approach? Given you have a bunch of different models for
all the different schemas, and you load some resource that
automatically uses the right model, you can always traverse that data
generically via EMF's reflective APIs, e.g., Resource.getAllContents().
Also, things like ExtendedMetaData.INSTANCE.getName(eObject.eClass())
will give you the XML names in the instance data. After all, all the
information in the original XML is recoverable, otherwise EMF wouldn't
be able to serialize it back out to conforming XML.
> The Mapping is :
> An XML Element is a Container or SubContainer (in my Ecore) where LocalName contains the XML Element Name
> An XML Attribute is a Parameter (in my Ecore) where LocalName is the XML attribute Name and Value is the XML attribute value
Why do this?
|Re: Customize XML serialization with EMF [message #955927 is a reply to message #955017]
||Wed, 24 October 2012 05:30
| Ed Merks
Registered: July 2009
On 23/10/2012 2:39 PM, Philippe Favrais wrote:
> I need to compare XML files which correspond to the same XSD. As i
> have many different XSD files (depending on what i model), i need a
> generic tool able to compare all kinds of XML files (corresponding to
> the same XSD)
EMF compare and EMF diff both work generically.
> e.g.: i need to compare Adc_0.xml against Adc_1.xml which both match
> i need to compare Pwm_0.xml against Pwm_1.xml which both match Pwm.Xsd
> i need to compare Irq_0.xml against Irq_1.xml which both match Irq.Xsd
> All my XSD are done with the same simple "design rule": when an
> element is not a singleton (max cardinality > 1), it has an attribute
> @Name which allow me to identify it uniquely. In that case, i compare
> the element having the same element name and the same attribute @Name
> value (independently of their order in the XML file)
> when an element is a singleton, i use only the element name to match
> and compare the element
> <Channel Name="abc"/>
> <Channel Name="def"/> --> (<Channel> is not a singleton because it has
> an attribute @Name: so in my compare engine, i compare the element if
> they haevthe same element name and atribute name)
> <Properties Default="Off" Clock="8"> --> (<Properties> is a singleton
> because it do not have @Name: so it will be compared against another
> element <Properties/>)
> So far, to experiment Emf Compare, i implemented a transformer to
> convert my XML(compliant to XSD) files to XMI(Ecore) and then in a 2nd
> step, i compare these Ecore model instances.
> For the next step i would like to automatically transfrom my xml file
> while loading and saving from the Compare tool.
> Do you think this approach is the rigth one ?
It sounds unnecessary. The rules you describe sound like something you
could characterize generically. EMF compare has mechanisms for
determining identity and you could specialize those rules in a generic
way. You might, for example, put annotations on the Ecore models you
produce from these schemas (i.e., via XML Schema annotations that are
mapped to Ecore) to mark the features (@Name) to be used for
establishing identity. The element name doesn't matter because it will
only compare objects contained by the same feature and that feature is
determined by the element name.
Powered by FUDForum
. Page generated in 0.02389 seconds