java - How to copy XML nodes from a text file and paste it as a EMF EObject in Eclipse? -
i have text file contains multiple xml nodes. want each node copied/converted emf object , pasted in eclipse editor (by using ctrl + c in text file , ctrl + v in eclipse editor). not able paste in eclipse editor. can please me out.
i had similar question. can read xml model , convert xmi model. in way need implement next code emf project. created new class , generate main method including code:
    //generate uri     resourcefactoryimpl factory = new resourcefactoryimpl();     uri sourceuri = uri.createuri("your xml path");     resource loadresource = (resourceimpl)factory.createresource(sourceuri);     system.out.println(sourceuri.path());      //add loading options     map<string, boolean> options = new hashmap<string, boolean>();      options.put(xmlresource.option_suppress_document_root, true);      //load xml     loadresource.load( options);      //create xmi output     uri targeturi = uri.createuri("your xmi path");     resource resourceout = new resourceimpl(targeturi);      //generating eobjects xml model     elist listobj = loadresource.getcontents();     eobject obj = (eobject) listobj.get(0);     resourceout.getcontents().add(obj);      resourceout.save(options);   remember need register epackages ecore model. so, right click .ecore metamodel , select option "register epackages". if there problem step going obtain org.eclipse.emf.ecore.resource.resource$iowrappedexception: package uri 'http://something.com' not found. (xml path).
in conclusion:
- invoke method main method tha includes presented code.
 - register epackages.
 - if obtain exception resolve uri data xml.
 
pd: code presented on post created @victormpav. add modifications.
Comments
Post a Comment