Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » xsd to Ecore: Trouble with xsd:Extension(Trouble with loading an XML against ecore with an extension)
xsd to Ecore: Trouble with xsd:Extension [message #1852429] Mon, 16 May 2022 10:35 Go to next message
Anne Hermann is currently offline Anne HermannFriend
Messages: 3
Registered: May 2022
Junior Member
Hello,

I am having problems with extensions in my xsd. I used the xsd to build an ecore model and then generated my java code.

In my xsd I have the following code:

<xsd:complexType ecore:name="DistinctRowsNodeType" name="distinctRowsNode_._type">
    <xsd:complexContent>
      <xsd:extension base="nodes_._type">
        <xsd:sequence>
          <xsd:element maxOccurs="unbounded" minOccurs="0" ref="inputs" />
        </xsd:sequence>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>
  <xsd:complexType ecore:name="NodesType" name="nodes_._type">
    <xsd:attribute name="id" type="xsd:string" />
    <xsd:attribute name="location" type="xsd:string" />
    <xsd:attribute name="nodeClassId" type="xsd:string" />
    <xsd:attribute name="nodeName" type="xsd:string" />
  </xsd:complexType>


Now I am trying to read an XML document and everything works fine until this section:

 <nodes>           
            <distinctRowsNode id="fEH_EvE2CEq_mwx6TPx9Yg" nodeClassId="PVTOVUhxYEWWtVDhyu58Mg" nodeName="distinct-rows" location="830,396">
                <inputs>
                    <input parameter="Source">
                        <source id="P98crK3zdU-IbZv4Hm55Zw" node="nt3QKwi-QUCdwfYzi99O3Q"/>
                        <source id="mM2APobMOk-8Ih27ENmxWg" node="HG8wjtoWpUixOpInRCWBDA"/>
                        <source id="r-kvCD8OQUWVvAmdqp0CLQ" node="HeRo9bY0mUWX76DYwr5VNA"/>
                        <source id="ig-0PotDBkmdlAQboi7_LQ" node="-HXQss6mlESysB_mW7D4jA"/>
                      </input>
                      <input parameter="Columns">
                        <source id="aSfVqrhdAkWz0ySflGp3fg"/>
                      </input>
                   </inputs>
            </distinctRowsNode>
</nodes>


This is the error I get:

org.eclipse.emf.ecore.resource.Resource$IOWrappedException: Feature 'distinctRowsNode' not found. (, 657, 140)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.handleErrors(XMLLoadImpl.java:77)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:185)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:261)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1563)
at app.XMLConverter.ConvertLowCodeXML(XMLConverter.java:48)
at app.App.main(App.java:13)

If you need more information to solve this, please let me know. I don't understand why distinctRowsNode can't be read :(

Thanks you all
Anne
Re: xsd to Ecore: Trouble with xsd:Extension [message #1852447 is a reply to message #1852429] Mon, 16 May 2022 17:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Are you using the generated XyzResourceFactoryImpl to create the resource that is being used to load this instance? Set a breakpoint in its createResource method to be sure.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: xsd to Ecore: Trouble with xsd:Extension [message #1852449 is a reply to message #1852447] Mon, 16 May 2022 18:56 Go to previous messageGo to next message
Anne Hermann is currently offline Anne HermannFriend
Messages: 3
Registered: May 2022
Junior Member
This is my code to load a XML:

xyzPackage pack = xyzPackageImpl.init();
ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getPackageRegistry().put(pack.getNsURI(), pack);
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xml", new XMLResourceFactoryImpl());

XMLResourceImpl resource = new XMLResourceImpl();

try {
			resource.load(new FileInputStream(new File(PATH_TO_XML).getAbsolutePath()), Collections.EMPTY_MAP);
} catch (FileNotFoundException e1) {
			System.out.println("Datei konnte nicht gefunden werden.");
			e1.printStackTrace();
} catch (IOException e1) {
			System.out.println("Datei konnte nicht eingelesen werden.");
			e1.printStackTrace();
}

return (DocumentRoot) resource.getContents().get(0);


I don't think that I am using the XyzResourceFactoryImpl
Re: xsd to Ecore: Trouble with xsd:Extension [message #1852456 is a reply to message #1852449] Tue, 17 May 2022 06:33 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
I asked because the generated resource factor's create method looks like this:
	/**
	 * Creates an instance of the resource.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Resource createResource(URI uri) {
		XMLResource result = new DcResourceImpl(uri);
		result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
		result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);

		result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);

		result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
		result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);

		result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
		return result;
	}
Without those options, it's not going to work. Worse still, you don't actually use a resource factory or the resource set at all, you directly create an XMLResourceImpl.

I'd suggest invoking Generate Test Code and look for the XyzExample.java. The generated main method will show how to read and write resources properly/correctly. Copy and paste from that...


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: xsd to Ecore: Trouble with xsd:Extension [message #1852461 is a reply to message #1852456] Tue, 17 May 2022 08:47 Go to previous messageGo to next message
Anne Hermann is currently offline Anne HermannFriend
Messages: 3
Registered: May 2022
Junior Member
thanks for the hint!

So I've changed it to this:

ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION,  new xyzResourceFactoryImpl());
resourceSet.getPackageRegistry().put(xyzPackage.eNS_URI, xyzPackage.eINSTANCE);
				
File file = new File(PATH_TO_XML);
URI uri = file.isFile() ? URI.createFileURI(file.getAbsolutePath()): URI.createURI(PATH_TO_XML);
		
try {
		Resource resource = resourceSet.getResource(uri, true);
		System.out.println("Loaded " + uri);
		return (DocumentRoot) resource.getContents().get(0);

	} catch (RuntimeException exception) {
		System.out.println("Problem loading " + uri);
		exception.printStackTrace();
	}


but I still have the same problem. Everything is read just fine until the distinctRowsNode.
Re: xsd to Ecore: Trouble with xsd:Extension [message #1852462 is a reply to message #1852461] Tue, 17 May 2022 09:23 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33141
Registered: July 2009
Senior Member
Given you haven't shown anything in a schema with an element definition named distinctRowsNode I cannot guess what could be wrong. Is the serialization you are trying to read one that you produced yourself with this model or it came from somewhere else?

Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EMF compare post processor for multiple files
Next Topic:Why refresh call in PlatformResourceURIHandlerImpl.WorkbenchHelper.createPlatformResourceInputStream
Goto Forum:
  


Current Time: Fri Apr 26 05:49:50 GMT 2024

Powered by FUDForum. Page generated in 0.03026 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top