Home » Modeling » EMF » [EMF] Issue loading XML Resource
[EMF] Issue loading XML Resource [message #540779] |
Thu, 17 June 2010 11:12 |
Guillaume Hillairet Messages: 97 Registered: July 2009 |
Member |
|
|
Hi all,
I'm facing a problem with XML file loading. I have an Ecore model generated from a XSD schema, and I want to load a preexisting XML file, conform to this schema, with EMF. Unfortunately, during the loading process, some features do not seem to be recognized. I include here the code I used to load the XML file. Do I forgot some loading options ?
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("xml", new XMLResourceFactoryImpl());
EPackage.Registry.INSTANCE.put("http://example.com/mp", MyPackage.eINSTANCE);
ResourceSet resourceSet = new ResourceSetImpl();
Map<String, Object> options = new HashMap<String, Object>();
options.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
Resource resource = resourceSet.createResource(URI.createURI("model/file.xml"));
resource.load(options);
The generated Ecore model.
@ExtendedMetaData(name="models", kind="elementOnly")
class ModelsType {
@ExtendedMetaData(kind="element", name="dtdVersion", namespace="##targetNamespace")
!resolve val DtdVersionType dtdVersion;
@ExtendedMetaData(kind="element", name="momMetaData", namespace="##targetNamespace")
!resolve val MomMetaDataType momMetaData;
@ExtendedMetaData(kind="element", name="mim", namespace="##targetNamespace")
!resolve val MimType[*] mim;
@ExtendedMetaData(kind="element", name="interMim", namespace="##targetNamespace")
derived !resolve val InterMimType[*] interMim;
}
A excerpt of the XML file, that causes me some troubles.
<models xmlns="http://example.com/mp">
<mim name="MODEL_M" version="1" release="32"> // that is line 83
<applicationTag>Includes the ... </applicationTag>
<struct name="ValueOfUnex">
<description>The attributes in ....</description>
<structMember name="vpi">
<description>The ATM header vpi.</description>
<long>
<defaultValue>0</defaultValue>
</long>
...
And the raised exception log.
Exception in thread "main" org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature 'mim' not found. (file:///C:/../file.xml, 83, 58)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLL oadImpl.java:83)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl. java:191)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes ourceImpl.java:180)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1494)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour ceImpl.java:1282)
BRs,
Guillaume
[Updated on: Thu, 17 June 2010 11:13] Report message to a moderator
|
|
|
Re: [EMF] Issue loading XML Resource [message #540805 is a reply to message #540779] |
Thu, 17 June 2010 12:00 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Guillaume,
Try invoking Generate Test Code and have a look at MyExample.java in the
*.tests project. You'll notice it registers the generated
MyResourceFactoryImpl which sets the right options you'll need.
Guillaume Hillairet wrote:
> Hi all,
>
> I'm facing a problem with XML file loading. I have an Ecore model
> generated from a XSD schema, and I want to load a preexisting XML
> file, conform to this schema, with EMF. Unfortunately, during the
> loading process, some features do not seem to be recognized. I include
> here the code I used to load the XML file. Do I forgot some loading
> options ?
>
>
> Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap( ).put( "xml",
> new XMLResourceFactoryImpl());
>
> EPackage.Registry.INSTANCE.put("http://example.com/mp",
> MyPackage.eINSTANCE);
>
> ResourceSet resourceSet = new ResourceSetImpl();
>
> Map<String, Object> options = new HashMap<String, Object>();
> options.put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
>
> Resource resource =
> resourceSet.createResource(URI.createURI("model/file.xml"));
It's generally best to use an absolute URI with an absolute path.
Again, see how the generated example does this.
> resource.load(options);
>
>
> The generated Ecore model.
>
>
> @ExtendedMetaData(name="models", kind="elementOnly")
> class ModelsType {
>
> @ExtendedMetaData(kind="element", name="dtdVersion",
> namespace="##targetNamespace")
> !resolve val DtdVersionType dtdVersion;
>
> @ExtendedMetaData(kind="element", name="momMetaData",
> namespace="##targetNamespace")
> !resolve val MomMetaDataType momMetaData;
>
> @ExtendedMetaData(kind="element", name="mim",
> namespace="##targetNamespace")
> !resolve val MimType[*] mim;
>
> @ExtendedMetaData(kind="element", name="interMim",
> namespace="##targetNamespace")
> derived !resolve val InterMimType[*] interMim;
> }
>
>
> A excerpt of the XML file, that causes me some troubles.
>
>
> <models xmlns="http://example.com/mp">
> <mim name="MODEL_M" version="1" release="32"> // that is line 83
> <applicationTag>Includes the ... </applicationTag>
> <struct name="ValueOfUnex"> <description>The
> attributes in ....</description> <structMember
> name="vpi"> <description>The ATM header
> vpi.</description> <long>
> <defaultValue>0</defaultValue>
> </long>
> ..
>
>
> And the raised exception log.
>
> Exception in thread "main"
> org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature
> 'mim' not found. (file:///C:/../file.xml, 83, 58)
> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLL
> oadImpl.java:83)
> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.
> java:191)
> at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLRes
> ourceImpl.java:180)
> at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour
> ceImpl.java:1494)
> at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(Resour
> ceImpl.java:1282)
> at com.ericsson.mom.resource.Main.main(Main.java:36)
>
> BRs,
> Guillaume
>
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Goto Forum:
Current Time: Wed Apr 24 18:06:06 GMT 2024
Powered by FUDForum. Page generated in 0.02744 seconds
|