Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » XML2XMI Serialization with nillable attributes
XML2XMI Serialization with nillable attributes [message #1727937] Tue, 29 March 2016 14:52 Go to next message
Ahmed AHMED is currently offline Ahmed AHMEDFriend
Messages: 10
Registered: December 2015
Junior Member
Hi,
I have a problem converting XML files to XMI containing nillable attributes.
Futhermore, i need to verify my procedure to load XML models using the model editor.
Below is the sequence of steps that i did and the problems that i had.

1. Converting XSD2Ecore
a. Transformed XSD schema to Ecore MM using XSD2ecore.
b. modified the NsPrefix ("set") and the Ns URI values of the generated ecore model.
c. generated the model, edit and editor code.
2. loading XML using the tree editor
After generating the code, i loaded the files after performing two steps:
a. Modiftying the xmlns to the generated ecore model
b. Modifying the file extension to name specified in the nsprefix (myModel.xml -> myModel.set)
The model is loading and everything is working OK.
However, i need to verify whether i am loading the XML model in the right way, or i can do it without modifying the extension and namespace ?

3. Converting XML2XMI
My real problem exist in this section.
I need to convert the XMLmodel to XMI. Therefore i loaded my XML file using XMLResourceFactoryImplemention with the extended meta data option and save it using XMIResourceImpl with null options.
This conversion works for some xml files, however with some files, i get a NullPointerException. After analyzing the XML files, i found that the problem is due to the existence of nillable attributes in some tags of these file.

I cannot manage to solve this problem and i am looking for your help.
e.g of the XML file.

<Description p5:nil="true" xmlns:p5="http://www.w3.org/2001/XMLSchema-instance" />

The error stack is as follows:

Exception in thread "main" java.lang.NullPointerException
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1114)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2466)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1518)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1181)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2466)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1518)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1181)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2466)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1518)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1181)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2466)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1518)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1181)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2466)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1518)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1181)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveContainedSingle(XMLSaveImpl.java:2403)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1547)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1181)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2466)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1518)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1181)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2466)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1518)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XMLSaveImpl.java:683)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveImpl.java:591)
at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl.java:251)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLResourceImpl.java:389)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1430)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:999)
at testXML2XMI.main(testXML2XMI.java:97)
Re: XML2XMI Serialization with nillable attributes [message #1728181 is a reply to message #1727937] Thu, 31 March 2016 15:38 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Ahmed,

Comments below.

On 29.03.2016 16:52, Ahmed AHMED wrote:
> Hi,
> I have a problem converting XML files to XMI containing nillable
> attributes.
Such conversion sounds kind of pointless. And worse, an XMI
serializations are highly stylized, so things like EMF's support for
feature maps, any type, and the "xsi" namespace are all not "compatible"
with an XMI serialization (at least in so far as it's defined in the
specification).
> Futhermore, i need to verify my procedure to load XML models using the
> model editor.
> Below is the sequence of steps that i did and the problems that i had.
>
> 1. Converting XSD2Ecore
> a. Transformed XSD schema to Ecore MM using XSD2ecore.
> b. modified the NsPrefix ("set") and the Ns URI values of the
> generated ecore model.
Why?
> c. generated the model, edit and editor code.
> 2. loading XML using the tree editor
> After generating the code, i loaded the files after performing two steps:
> a. Modiftying the xmlns to the generated ecore model
Why?
> b. Modifying the file extension to name specified in the nsprefix
> (myModel.xml -> myModel.set)
You do that in the *.genmodel or in the code?
> The model is loading and everything is working OK.
> However, i need to verify whether i am loading the XML model in the
> right way, or i can do it without modifying the extension and namespace ?
I don't know why you're doing this. Is the namespace of the schema not
exactly the one used in the instances?
>
> 3. Converting XML2XMI
Why would you need to do that?
> My real problem exist in this section.
> I need to convert the XMLmodel to XMI. Therefore i loaded my XML file
> using XMLResourceFactoryImplemention with the extended meta data
> option and save it using XMIResourceImpl with null options.
> This conversion works for some xml files, however with some files, i
> get a NullPointerException. After analyzing the XML files, i found
> that the problem is due to the existence of nillable attributes in
> some tags of these file.
>
> I cannot manage to solve this problem and i am looking for your help.
> e.g of the XML file.
> <Description p5:nil="true"
> xmlns:p5="http://www.w3.org/2001/XMLSchema-instance" />

What exactly is "p5"?
>
> The error stack is as follows:
>
> Exception in thread "main" java.lang.NullPointerException
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1114)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2466)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1518)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1181)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2466)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1518)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1181)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2466)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1518)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1181)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2466)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1518)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1181)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2466)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1518)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1181)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveContainedSingle(XMLSaveImpl.java:2403)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1547)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1181)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2466)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1518)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1181)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElement(XMLSaveImpl.java:1042)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2466)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1518)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1224)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2716)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.writeTopObject(XMLSaveImpl.java:683)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.traverse(XMLSaveImpl.java:591)
> at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl.java:251)
> at
> org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLResourceImpl.java:389)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1430)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:999)
> at testXML2XMI.main(testXML2XMI.java:97)


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Why am I not seeing EMF types in a project with a Plug-in nature?
Next Topic:Deregister epackages
Goto Forum:
  


Current Time: Sat Apr 20 04:38:43 GMT 2024

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

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

Back to the top