Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Resource.save output is invalid XMI file(Unresolved Reference Exception in the output file of save method even though the item exists and in the correct index)
Resource.save output is invalid XMI file [message #1006462] Thu, 31 January 2013 11:58 Go to next message
Houssam Abdoullah is currently offline Houssam AbdoullahFriend
Messages: 1
Registered: January 2013
Junior Member
Hello all,
I'm using org.eclipse.emf.ecore.resource.Resource.save(OutputStream outputStream, Map<?, ?> options) to seliaze XMI resource
When opening the output file, I'm getting Unresolved Reference Exception

org.eclipse.emf.ecore.xmi.UnresolvedReferenceException: Unresolved reference '//@elements.13'. (platform:/resource/my.generator.project.TestAllWithnewModel/src/metamodel/t.xmi, 7, 138)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleForwardReferences(XMLHandler.java:1154)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.endDocument(XMLHandler.java:1228)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endDocument(AbstractSAXParser.java:737)
for the elements from 9 to 14 (Which are the last elements of the file). Evernthough they are present in the file.
The main difference between the output of save method and the original XMI scheme is that the original scheme uses structured elements when referring to a list while save method doesn't.

Any information about how to solve this problem? Another question please how can I add the schema location to the output file before calling save function?
I provided the original working XMI file, the output file (I highlighted the difference in red here) and the code I'm using.
Thanks for your help.
Houssam

The code to call the serializer
Resource xmiresource = resSet.createResource(URI.createURI("test.xmi"));
xmiresource.getContents().add(model);
xmiresource.save(xmi, Collections.EMPTY_MAP);

The output file
The output file in in this format and it's correct accourding to the input:
<?xml version="1.0" encoding="ASCII"?>
<domainmodel:Domainmodel xmi:version="2.0" xmlns:xmi="" xmlns:xsi="" xmlns:domainmodel="" xsi:schemaLocation="http://www.eclipse.org/xtext/example/Domainmodel metamodel.ecore">
<elements xsi:type="domainmodel:PackageDeclaration" name="java.lang" elements="//@elements.3"/>
<elements xsi:type="domainmodel:PackageDeclaration" name="my.company.blog" elements="//@elements.2 //@elements.6 //@elements.7 //@elements.4 //@elements.5"/>
<elements xsi:type="domainmodel:Import" importedNamespace="java.lang.*"/>
<elements xsi:type="domainmodel:DataType" name="String"/>
<elements xsi:type="domainmodel:Entity" name="Post" superType="//@elements.7" features="//@elements.13 //@elements.11 //@elements.12"/>
<elements xsi:type="domainmodel:Entity" name="Comment" superType="//@elements.7" features="//@elements.10"/>
<elements xsi:type="domainmodel:Entity" name="Blog" features="//@elements.9"/>
<elements xsi:type="domainmodel:Entity" name="HasAuthor" features="//@elements.8"/>
<elements xsi:type="domainmodel:Feature" many="false" name="author" type="//@elements.3"/>
<elements xsi:type="domainmodel:Feature" many="false" name="title" type="//@elements.3"/>
<elements xsi:type="domainmodel:Feature" many="false" name="content" type="//@elements.3"/>
<elements xsi:type="domainmodel:Feature" many="false" name="content" type="//@elements.3"/>
<elements xsi:type="domainmodel:Feature" many="true" name="comments" type="//@elements.5"/>
<elements xsi:type="domainmodel:Feature" many="false" name="title" type="//@elements.3"/>
<elements xsi:type="domainmodel:Feature" many="true" name="posts" type="//@elements.4"/>
</domainmodel:Domainmodel>

The original file
<?xml version="1.0" encoding="ASCII"?>
<domainmodel:Domainmodel xmi:version="2.0" xmlns:xmi="" xmlns:xsi="" xmlns:domainmodel="http://www.eclipse.org/xtext/example/Domainmodel" xsi:schemaLocation="http://www.eclipse.org/xtext/example/Domainmodel metamodel.ecore">
<elements xsi:type="domainmodel:PackageDeclaration" name="java.lang">
<elements xsi:type="domainmodel:DataType" name="String"/>
</elements>
<elements xsi:type="domainmodel:PackageDeclaration" name="my.company.blog">
<elements xsi:type="domainmodel:Import" importedNamespace="java.lang.*"/>
<elements xsi:type="domainmodel:Entity" name="Blog">
<features name="title" type="//@elements.0/@elements.0"/>
<features many="true" name="posts" type="//@elements.1/@elements.3"/>

</elements>
<elements xsi:type="domainmodel:Entity" name="HasAuthor">
<features name="author" type="//@elements.0/@elements.0"/>
</elements>
<elements xsi:type="domainmodel:Entity" name="Post" superType="//@elements.1/@elements.2">
<features name="title" type="//@elements.0/@elements.0"/>
<features name="content" type="//@elements.0/@elements.0"/>
<features many="true" name="comments" type="//@elements.1/@elements.4"/>

</elements>
<elements xsi:type="domainmodel:Entity" name="Comment" superType="//@elements.1/@elements.2">
<features name="content" type="//@elements.0/@elements.0"/>
</elements>
</elements>
</domainmodel:Domainmodel>
  • Attachment: Model.xmi
    (Size: 1.52KB, Downloaded 229 times)
  • Attachment: outpot.xmi
    (Size: 1.72KB, Downloaded 807 times)
  • Attachment: XmiSerializer.java
    (Size: 4.09KB, Downloaded 362 times)
Re: Resource.save output is invalid XMI file [message #1006605 is a reply to message #1006462] Fri, 01 February 2013 07:03 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Houssam,

Comments below.

On 31/01/2013 3:23 PM, Houssam Abdoullah wrote:
> Hello all,
> I'm using org.eclipse.emf.ecore.resource.Resource.save(OutputStream outputStream, Map<?, ?> options) to seliaze XMI resource
> When opening the output file, I'm getting Unresolved Reference Exception
> org.eclipse.emf.ecore.xmi.UnresolvedReferenceException: Unresolved reference '//@elements.13'. (platform:/resource/my.generator.project.TestAllWithnewModel/src/metamodel/t.xmi, 7, 138)
> at org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleForwardReferences(XMLHandler.java:1154)
> at org.eclipse.emf.ecore.xmi.impl.XMLHandler.endDocument(XMLHandler.java:1228)
> at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endDocument(AbstractSAXParser.java:737)
> for the elements from 9 to 14 (Which are the last elements of the file). Evernthough they are present in the file.
> The main difference between the output of save method and the original XMI scheme is that the original scheme uses structured elements when referring to a list while save method doesn't.
> Any information about how to solve this problem? Another question please how can I add the schema location to the output file before calling save function?

# 2.22 How can I ensure that an xsi:schemaLocation is serialized for my
packages?
<http://wiki.eclipse.org/index.php/EMF-FAQ#How_can_I_ensure_that_an_xsi:schemaLocation_is_serialized_for_my_packages.3F>

The schema location is determined by the URI of the resource containing
your Ecore model
> I provided the original working XMI file, the output file (I highlighted the difference in red here) and the code I'm using.
> Thanks for your help.
> Houssam
>
> The code to call the serializer
> Resource xmiresource = resSet.createResource(URI.createURI("test.xmi"));
> xmiresource.getContents().add(model);
> xmiresource.save(xmi, Collections.EMPTY_MAP);
>
> The output file
> The output file in in this format and it's correct accourding to the input:
> <?xml version="1.0" encoding="ASCII"?>
> <domainmodel:Domainmodel xmi:version="2.0" xmlns:xmi="" xmlns:xsi="" xmlns:domainmodel="" xsi:schemaLocation="http://www.eclipse.org/xtext/example/Domainmodel metamodel.ecore">
> <elements xsi:type="domainmodel:PackageDeclaration" name="java.lang" elements="//@elements.3"/>
> <elements xsi:type="domainmodel:PackageDeclaration" name="my.company.blog" elements="//@elements.2 //@elements.6 //@elements.7 //@elements.4 //@elements.5"/>
> <elements xsi:type="domainmodel:Import" importedNamespace="java.lang.*"/>
> <elements xsi:type="domainmodel:DataType" name="String"/>
> <elements xsi:type="domainmodel:Entity" name="Post" superType="//@elements.7" features="//@elements.13 //@elements.11 //@elements.12"/>
> <elements xsi:type="domainmodel:Entity" name="Comment" superType="//@elements.7" features="//@elements.10"/>
> <elements xsi:type="domainmodel:Entity" name="Blog" features="//@elements.9"/>
> <elements xsi:type="domainmodel:Entity" name="HasAuthor" features="//@elements.8"/>
> <elements xsi:type="domainmodel:Feature" many="false" name="author" type="//@elements.3"/>
> <elements xsi:type="domainmodel:Feature" many="false" name="title" type="//@elements.3"/>
> <elements xsi:type="domainmodel:Feature" many="false" name="content" type="//@elements.3"/>
> <elements xsi:type="domainmodel:Feature" many="false" name="content" type="//@elements.3"/>
> <elements xsi:type="domainmodel:Feature" many="true" name="comments" type="//@elements.5"/>
> <elements xsi:type="domainmodel:Feature" many="false" name="title" type="//@elements.3"/>
> <elements xsi:type="domainmodel:Feature" many="true" name="posts" type="//@elements.4"/>
> </domainmodel:Domainmodel>
This output I'd expect if every object is contained in the
DomainModel's elements feature.
>
> The original file
> <?xml version="1.0" encoding="ASCII"?>
> <domainmodel:Domainmodel xmi:version="2.0" xmlns:xmi="" xmlns:xsi="" xmlns:domainmodel="http://www.eclipse.org/xtext/example/Domainmodel" xsi:schemaLocation="http://www.eclipse.org/xtext/example/Domainmodel metamodel.ecore">
> <elements xsi:type="domainmodel:PackageDeclaration" name="java.lang">
> <elements xsi:type="domainmodel:DataType" name="String"/>
> </elements>
> <elements xsi:type="domainmodel:PackageDeclaration" name="my.company.blog">
> <elements xsi:type="domainmodel:Import" importedNamespace="java.lang.*"/>
> <elements xsi:type="domainmodel:Entity" name="Blog">
> <features name="title" type="//@elements.0/@elements.0"/>
> <features many="true" name="posts" type="//@elements.1/@elements.3"/>
> </elements>
> <elements xsi:type="domainmodel:Entity" name="HasAuthor">
> <features name="author" type="//@elements.0/@elements.0"/>
> </elements>
> <elements xsi:type="domainmodel:Entity" name="Post" superType="//@elements.1/@elements.2">
> <features name="title" type="//@elements.0/@elements.0"/>
> <features name="content" type="//@elements.0/@elements.0"/>
> <features many="true" name="comments" type="//@elements.1/@elements.4"/>
> </elements>
> <elements xsi:type="domainmodel:Entity" name="Comment" superType="//@elements.1/@elements.2">
> <features name="content" type="//@elements.0/@elements.0"/>
> </elements>
> </elements>
> </domainmodel:Domainmodel>
This output I'd expect if the objects are properly contained in the
hierarchy where you're expecting them. Somehow you're populating
everything as elements of the domain model and not as nested elements
and features as you were expecting/hoping.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Change file to parse
Next Topic:Dynamic Syntax Highlighting
Goto Forum:
  


Current Time: Fri Mar 29 10:28:12 GMT 2024

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

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

Back to the top