I am trying to load an XML file using EMF and I am using the following code to do that in XMLArtefactAdapter.java:
constructor():
ResourceSet set = new ResourceSetImpl();
//registering factory
set.getResourceFactoryRegistry()
.getExtensionToFactoryMap()
.put
(Resource.Factory.Registry.DEFAULT_EXTENSION,new XMLResourceFactoryImpl());
parse() method:
//parsing XML
try {
String absolutePath = file.getAbsolutePath();
URI uri = URI.createFileURI(absolutePath);
Resource resource = resourceSet.createResource(uri);
resource.load(Collections.EMPTY_MAP);
System.out.println("LOADED");
} catch (IOException e) {
System.out.println(e.toString());
}
I am executing this code fragment from my Main class:
Path path = Paths.get("C:\\Users\\Srijani\\Desktop\\book.xml");
XMLArtefactAdapter xmlAdapter = new XMLArtefactAdapter(path);
xmlAdapter.parse();
But, I get error while running this code.
org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Package with uri 'null' not found. (file:/C:/Users/Srijani/Desktop/plugin.xml, 3, 9)
Please note the following: My Plugin.xml
<plugin>
<extension point="org.eclipse.emf.ecore.generated_package">
<!-- @generated simpletree -->
<package
uri="platform:/plugin/com.kaleidoscope.core.aux.simpletree/model/SimpleTree.ecore"
class="SimpleTree.SimpletreePackage"
genModel="model/simpletree.genmodel"/>
</extension>
</plugin>
Any idea why this is happening? Thanks in Advance!
An EPackage uri is a kind of public identifier for your EPackage. It should not be an eclipse uri.
Usually, the namespace URI is an http url providing some basic informations about the EPackage provider, ePackage name and version. eg :
You should :