Skip to main content



      Home
Home » Modeling » EMF » Converting an XMI to XML Resource
icon9.gif  Converting an XMI to XML Resource [message #849516] Thu, 19 April 2012 04:04 Go to next message
Eclipse UserFriend
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 #849535 is a reply to message #849516] Thu, 19 April 2012 04:30 Go to previous messageGo to next message
Eclipse UserFriend
Hi

XML supports tree structured data.
XMI supports graph structured data.

The xmi:id's are specifically to support the cross-references.

How do you plan to eliminate them?

Regards

Ed Willink

On 19/04/2012 09:04, Marc wrote:
> 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 05:03 Go to previous messageGo to next message
Eclipse UserFriend
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 05:51 Go to previous messageGo to next message
Eclipse UserFriend
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! Very Happy
Marc
Re: Converting an XMI to XML Resource [message #849737 is a reply to message #849614] Thu, 19 April 2012 08:05 Go to previous messageGo to next message
Eclipse UserFriend
Marc,

There's also XMIResource.OPTION_SUPPRESS_XMI.

On 19/04/2012 11:51 AM, Marc wrote:
> 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! :d
> Marc
Re: Converting an XMI to XML Resource [message #849779 is a reply to message #849737] Thu, 19 April 2012 08:52 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed,

I can't find XMIResource.OPTION_SUPPRESS_XMI in XMIResource file... I'm using EMF 2.5 with Galileo 3.5.2...

Thanks,
Marc
Re: Converting an XMI to XML Resource [message #850002 is a reply to message #849779] Thu, 19 April 2012 13:06 Go to previous messageGo to next message
Eclipse UserFriend
It's new for 2.7.

On 19/04/2012 2:52 PM, Marc wrote:
> Hi Ed,
>
> I can't find XMIResource.OPTION_SUPPRESS_XMI in XMIResource file...
> I'm using EMF 2.5 with Galileo 3.5.2...
>
> Thanks,
> Marc
Re: Converting an XMI to XML Resource [message #1246131 is a reply to message #850002] Fri, 14 February 2014 14:00 Go to previous messageGo to next message
Eclipse UserFriend
I'm with the same problem, so i try to do the four steps listing by Marc.

My code is:

1. URI uri = new URI("string_path_of_xmi_file");
2. XMIResourceImpl old = new XMIResourceImpl(uri);
3. XMLResourceImpl novo = old;
4. System.out.println(novo.getAllContents().toString());

so i have a problem on the line number 1, where the error is: The constructor URI(String) is undefined

but, how do i create an URI without using a String as a path?

Tks
Re: Converting an XMI to XML Resource [message #1246617 is a reply to message #1246131] Sat, 15 February 2014 03:13 Go to previous message
Eclipse UserFriend
Hi

You can learn to use a Java class by studying its JavaDoc. You will find
that URI has numerous ways to support creation.

Regards

Ed Willink


On 14/02/2014 19:00, Raphael Honda wrote:
> I'm with the same problem, so i try to do the four steps listing by Marc.
>
> My code is:
>
> 1. URI uri = new URI("string_path_of_xmi_file");
> 2. XMIResourceImpl old = new XMIResourceImpl(uri);
> 3. XMLResourceImpl novo = old;
> 4. System.out.println(novo.getAllContents().toString());
>
> so i have a problem on the line number 1, where the error is: The
> constructor URI(String) is undefined
>
> but, how do i create an URI without using a String as a path?
>
> Tks
Previous Topic:EditingDomain by EMF Data Binding
Next Topic:No exceptions when importing an XMI with abstract classes
Goto Forum:
  


Current Time: Mon Apr 28 16:25:13 EDT 2025

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

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

Back to the top