Converting an XMI to XML Resource [message #849516] |
Thu, 19 April 2012 08:04 |
|
Hi everybody,
I have a model that uses XMIResource to be managed, but I need to export it like a XMLResource. That means to remove all references to xmi attributes: xmi:version, xmi:id...
Is this possible to be done? I know that to convert from XML to XMI Resource is easy and EMF does it by itself only by loading and saving the resource, but what about XMI to XML Resource?
Thanks!
Marc
|
|
|
|
Re: Converting an XMI to XML Resource [message #849566 is a reply to message #849535] |
Thu, 19 April 2012 09:03 |
|
Hi Ed,
I need to do that cause we're using an external xml validator that has no any knowledgement of XMI attributes, so I need to remove all xmi references.
I know that xmi:id's allows cross-references, but xml too using following syntax:
<compoundIUs>
<hasStates id="1">
<source targetOf="//@compoundIUs.0/@hasStates.1"/>
</hasStates>
<hasStates id="2" target="//@compoundIUs.0/@hasStates.0/@source.0"/>
</compoundIUs>
instead of the following one:
<compoundIUs xmi:id="_rJvIgYn8EeGDYJII_XY5ng">
<hasStates xmi:id="_rJvIgon8EeGDYJII_XY5ng" id="1">
<source xmi:id="_rJvIg4n8EeGDYJII_XY5ng" targetOf="_rJvIhIn8EeGDYJII_XY5ng"/>
</hasStates>
<hasStates xmi:id="_rJvIhIn8EeGDYJII_XY5ng" id="2" target="_rJvIg4n8EeGDYJII_XY5ng"/>
</compoundIUs>
My question is if there exist any way to do this conversion...
I get something by overwriting my XXXResourceImpl file (that extends from XMIResourceImpl):
@Override
protected XMLSave createXMLSave() {
return new XMLSaveImpl(new XMLHelperImpl(this));
}
@Override
protected boolean useUUIDs() {
return false;
}
@Override
protected boolean useIDs() {
return false;
}
But it doesn't work completely as I want, cause the file has the following content:
<compoundIUs id="_rJvIgYn8EeGDYJII_XY5ng">
<hasStates id="_rJvIgon8EeGDYJII_XY5ng" id="1">
<source id="_rJvIg4n8EeGDYJII_XY5ng" targetOf="_rJvIhIn8EeGDYJII_XY5ng"/>
</hasStates>
<hasStates id="_rJvIhIn8EeGDYJII_XY5ng" id="2" target="_rJvIg4n8EeGDYJII_XY5ng"/>
</compoundIUs>
As you can see, it has removed the xmi references, but has not removed the attribute id correctly, and there exists some cases where id is duplicated, due to I have my own id property in my metamodel. Although the references has not been recalculated correctly.
Any idea about if it's possible or not?
Thanks a lot,
Marc
|
|
|
Re: Converting an XMI to XML Resource [message #849614 is a reply to message #849566] |
Thu, 19 April 2012 09:51 |
|
I get it!
The steps are the following:
1. Create and load the old XMI resource (using my XXXResourceImpl that extends from XMIResourceImpl).
2. Create the new XML resource (using my YYYResourceImpl that extends from XMLResourceImpl).
3. Set as contents of the new XML Resource the contents of the old XMI Resource.
4. Save the new XML Resource.
With these steps I get what I need:
<compoundIUs>
<hasStates id="1">
<source targetOf="//@compoundIUs.0/@hasStates.1"/>
</hasStates>
<hasStates id="2" target="//@compoundIUs.0/@hasStates.0/@source.0"/>
</compoundIUs>
Thanks!
Marc
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03222 seconds