Loading XML with multiple schemalocations [message #1231342] |
Tue, 14 January 2014 07:13  |
Eclipse User |
|
|
|
I have an xml instance of my meta-model which I am trying to load and validate against multiple ecore models. My ecore models were generated from one XSD which is used to validate this XML instance. I can load my XML file if it only contains elements from the root ecore model. However, If I include any elements that reference a object from another ecore model, I get any NullPointerException. I have placed the all the correct schema locations within the XML file.
My xml file looks like this.
<XX:DocumentRoot
xmlns:XX='adaptive/XX'
xmlns:ADGENERAL='adaptive/ADCOMBINE'
xmlns:xsi='XMLSchema-instance...url'
xsi:schemaLocation="adaptive/XX ./resources/XMIExport.ecore
adaptive/ADGENERAL ./resources/adgeneral.ecore"
>
<XX:XMI>
<XX:XMI.Header>
<XX:XMI.Metamodel xmi.name='com.adaptive.Combined' xmi.version='1.1'/>
</XX:XMI.Header>
<XX:XMI.Content>
[b]<ADGENERAL:Dependency>
</ADGENERAL:Dependency>[/b]
</XX:XMI.Content>
</XX:XMI>
</XX:DocumentRoot>
The exception is:
Exception in thread "main" java.lang.NullPointerException
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFeatureType(XMLHandler.java:2164)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHandler.java:2042)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLHandler.java:1847)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1030)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1008)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:719)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:504)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1370)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2763)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:647)
at
Thanks in advance,
Mohammed
|
|
|
|
|
Re: Loading XML with multiple schemalocations [message #1231770 is a reply to message #1231762] |
Wed, 15 January 2014 05:51  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.06164 seconds