|
|
|
Re: Loading XML with multiple schemalocations [message #1231770 is a reply to message #1231762] |
Wed, 15 January 2014 10:51 |
Ed Merks Messages: 33217 Registered: July 2009 |
Senior Member |
|
|
Comments below.
On 15/01/2014 11:37 AM, Mt Naj wrote:
> I tried "factory = eClass.getEPackage().getEFactoryInstance();" the
> stack trace stayed the same.
> Yes we have been serializing without using any generated resource
> factory.
Hmmm.
> The quoted of the xmi was generated using metadata manager tool,
I'm not sure what that is.
> then I generated XSD off that XMI.
That doesn't sound terribly sensible. XMI serializations are not really
describable via a sensible schema.
> The XSD's are then used to generate the score model for which I would
> like to validate the original XML file against.
> The quoted xml code snippet is the whole XML instance. I changed the
> namespaces just for this post because the forum would not accept the
> URL's.
>
> My java code is able to load the instances of
> "AdaptiveGenericXMIExport.ecore" model, but throws the null pointed
> exception if I have any element from another ecore model.
> My java code is:
>
>
> public static void xmlLoader( String uri){
> ResourceSet load_resourceSet = new ResourceSetImpl();
>
> // Register XML Factory implementation to handle files with any
> // extension
> load_resourceSet.getResourceFactoryRegistry()
> .getExtensionToFactoryMap().put("*",
> new XMLResourceFactoryImpl());
EMF generates code (invoke Generate Test and look at the
XyzExample.java), so you should consider doing the things you see
there. E.g., ensuring that packages are registered and the generated
resource factory is registered (assuming of course you're doing all this
stand alone, not in a running Eclipse application).
>
> // Create empty resource with the given URI
> Resource load_resource = load_resourceSet.getResource(URI
> .createURI(uri), true);
>
> printAllConents(load_resource);
> }
> public static void printAllConents(Resource resource){
> for (TreeIterator iter = EcoreUtil.getAllContents(resource,
> true); iter.hasNext(); )
> {
> EObject eObject = (EObject)iter.next();
> EClass eClasses = eObject.eClass();
> System.out.println(eClasses.getName());
> }
> }
>
>
> This prints out if no elements from any other ecore model:
No doubt because the load failed, but I can't guess what state your
models are in, nor does the approach you're describing seem all that
sensible.
>
> DocumentRoot
> XMIType
> XMI.HeaderType
> XMI.MetamodelType
> XMI.ContentType
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Powered by
FUDForum. Page generated in 0.04631 seconds