Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EObject for XML fragments
EObject for XML fragments [message #1272634] Tue, 18 March 2014 11:26 Go to next message
Dhanya M is currently offline Dhanya MFriend
Messages: 19
Registered: April 2013
Junior Member
Hello,

How can I get the EObject corresponding to an XML fragment (part of XML which is adhering to the XSD with which EMF was generated).

In JAXB, JAXBFragment is available. Is there something similar available in EMF?

My requirement is to get the model object (EObject) when the user copies a text (a portion of XML) from outside and paste onto my tree editor.

Thanks.

Dhanya
Re: EObject for XML fragments [message #1272704 is a reply to message #1272634] Tue, 18 March 2014 14:44 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Dhanya,

Comments below.

On 18/03/2014 4:26 AM, Dhanya M wrote:
> Hello,
>
> How can I get the EObject corresponding to an XML fragment (part of
> XML which is adhering to the XSD with which EMF was generated).
>
> In JAXB, JAXBFragment is available. Is there something similar
> available in EMF?
>
> My requirement is to get the model object (EObject) when the user
> copies a text (a portion of XML) from outside and paste onto my tree
> editor.
As long as the root element corresponds to a global element in the XML
Schema, you can load the XML using a resource created by your generated
resource factory. You could use
org.eclipse.emf.ecore.resource.URIConverter.ReadableInputStream.ReadableInputStream(String)
to create the input stream from which to load directly from your XML
string representation.
>
> Thanks.
>
> Dhanya


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject for XML fragments [message #1273503 is a reply to message #1272704] Thu, 20 March 2014 05:08 Go to previous messageGo to next message
Dhanya M is currently offline Dhanya MFriend
Messages: 19
Registered: April 2013
Junior Member
Thanks Ed for the reply.

I tried the solution. However i get a Feature not found. Is it because my element is not root node.

As per my XSD, i can have only one root node say A and what i am trying to access a complexType which is defined 2 levels down. But it is global.
Is it that only root nodes can be read??

Thanks.
Dhanya
Re: EObject for XML fragments [message #1273833 is a reply to message #1273503] Thu, 20 March 2014 15:57 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Dhanya,

You'd need to specialize code because from the root element name and
namespace it must be possible to uniquely determine what EClass of
EObject to create. I.e., in
org.eclipse.emf.ecore.xmi.impl.XMLHandler.createTopObject(String,
String) it must be able to determine for the top element which object to
create.

On 19/03/2014 10:08 PM, Dhanya M wrote:
> Thanks Ed for the reply.
>
> I tried the solution. However i get a Feature not found. Is it because
> my element is not root node.
>
> As per my XSD, i can have only one root node say A and what i am
> trying to access a complexType which is defined 2 levels down. But it
> is global.
> Is it that only root nodes can be read??
>
> Thanks.
> Dhanya


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EObject for XML fragments [message #1276241 is a reply to message #1273833] Mon, 24 March 2014 09:35 Go to previous messageGo to next message
Dhanya M is currently offline Dhanya MFriend
Messages: 19
Registered: April 2013
Junior Member
Hello Ed,

I didnt understand how we can put this (createTopObject) in the resource loading code so that resource can load into the proper feature. Can you provide a sample?

Thanks.
Re: EObject for XML fragments [message #1276420 is a reply to message #1276241] Mon, 24 March 2014 14:44 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Dhanya,

Have you set a breakpoint to see how that code works in a case when it
works and in the case when it fails?

On 24/03/2014 2:35 AM, Dhanya M wrote:
> Hello Ed,
>
> I didnt understand how we can put this (createTopObject) in the
> resource loading code so that resource can load into the proper
> feature. Can you provide a sample?
>
> Thanks.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Update derived attriburte
Next Topic:[XCORE] Ecore.ecore inside the workspace with a relative path
Goto Forum:
  


Current Time: Thu Apr 25 09:53:22 GMT 2024

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

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

Back to the top