Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF] Loading XML file with no namespace information
[EMF] Loading XML file with no namespace information [message #1008060] Fri, 08 February 2013 16:46 Go to next message
Philippe Roland is currently offline Philippe RolandFriend
Messages: 4
Registered: January 2013
Junior Member
Hey all,

I've got a metamodel and XML files instancing it. These files do not point back to the metamodel with xmlns or contain any namespace information.
I've attempted to load these files by adding the metamodel's package to the registrymap under the null URI, like this:

resourceSet.getPackageRegistry().put(null, ePackage);
EPackage.Registry.INSTANCE.put(null, ePackage)


But have had no luck so far, and get "FeatureNotFoundException : feature [rootObject] not found" exceptions thrown whenever I try to load the resource. Any advice would be greatly appreciated.

Cheers,
Philippe
Re: [EMF] Loading XML file with no namespace information [message #1008066 is a reply to message #1008060] Fri, 08 February 2013 16:58 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Philippe,

Comments below.

On 08/02/2013 5:46 PM, Philippe Roland wrote:
> Hey all,
>
> I've got a metamodel and XML files instancing it. These files do not
> point back to the metamodel with xmlns or contain any namespace
> information.
Where do such files come from? Is there an XML Schema defining the format?
> I've attempted to load these files by adding the metamodel's package
> to the registrymap under the null URI, like this:
>
> resourceSet.getPackageRegistry().put(null, ePackage);
> EPackage.Registry.INSTANCE.put(null, ePackage)
Don't pollute the global registries!
>
> But have had no luck so far, and get "FeatureNotFoundException :
> feature [rootObject] not found" exceptions thrown whenever I try to
> load the resource. Any advice would be greatly appreciated.
I'd suggest finding or creating a simple schema without a target
namespace and generate an Ecore model from it. Note in particular the
extended meta data annotation on the EPackage and look closely at the
details of the generated resource factory implementation. Those are the
two things you'll need to do for your model.
>
> Cheers,
> Philippe


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [EMF] Loading XML file with no namespace information [message #1008182 is a reply to message #1008066] Mon, 11 February 2013 10:19 Go to previous messageGo to next message
Philippe Roland is currently offline Philippe RolandFriend
Messages: 4
Registered: January 2013
Junior Member
Hi Ed, thanks for your reply!

Regarding the global registries: Thanks for the advice. It was a bit of a last-ditch effort, but I probably shouldn't have bothered to begin with.

As for the rest of your reply, I think I wasn't very clear, so I'll try and elaborate. I already have the XSD schema, as well as the corresponding Ecore model and API. The files I'm trying to load are provided by the user, and cannot be modified to include the namespace information.
I've tried looking around the package metadata and factory class, as per your suggestion, but haven't found anything out of the ordinary. Is there anything in particular that I should be looking out for?

I also have encountered a related problem that I hope you might be able to help with. My schema is heavily hierarchized. For the sake of explanation, let's say it goes like this :
<A>
  <B>
    <C>
    </C>
  <B>
</A>

If I manually add the namespace information to a file that describes an instance of A, everything's fine; If I do the same thing to a file describing an instance of B or C, I get the same error I described in my first message, ie. FeatureNotFoundException : feature B/C not found. Do you have any ideas on what I could do to fix this?

[Updated on: Mon, 11 February 2013 10:22]

Report message to a moderator

Re: [EMF] Loading XML file with no namespace information [message #1008342 is a reply to message #1008182] Tue, 12 February 2013 05:10 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Philippe,

Comments below.

On 11/02/2013 11:19 AM, Philippe Roland wrote:
> Hi Ed, thanks for your reply!
>
> Regarding the global registries: Thanks for the advice. It was a bit
> of a last-ditch effort, but I probably shouldn't have bothered to
> begin with.
>
> As for the rest of your reply, I think I wasn't very clear, so I'll
> try and elaborate. I already have the XSD schema, as well as the
> corresponding Ecore model and API.
Does that schema have a target namespace?
> The files I'm trying to load are provided by the user, and cannot be
> modified to include the namespace information.
So the XML isn't actually valid with respect to the schema. (A schema
that specifies a target namespace implies that the instance must specify
that namespace.)
> I've tried looking around the package metadata and factory class, as
> per your suggestion, but haven't found anything out of the ordinary.
You really tried what I suggested? "I'd suggest finding or creating a
simple schema without a target namespace and generate an Ecore model
from it."
> Is there anything in particular that I should be looking out for?
Yes, I mentioned the particulars in my previous answer.
>
> I also have encountered a related problem that I hope you might be
> able to help with. My schema is heavily hierarchized. For the sake of
> explanation, let's say it goes like this : <A>
> <B>
> <C>
> </C>
> <B>
> </A>
> If I manually add the namespace information to a file that describes
> an instance of A, everything's fine; If I do the same thing to a file
> describing an instance of B or C, I get the same error I described in
> my first message, ie. FeatureNotFoundException : feature A not found.
Keep in mind that if you specify xmlns="...." on the root element then
every element in the document will be implicitly from that namespace,
and that might not correspond to your schema either.
> Do you have any ideas on what I could do to fix this?
Yes, but you need to look at the particulars I suggested already. I.e.,
if you modified your schema to remove the target namespace, what EMF
generates from it should be able to read instances without xmlns
declarations; of course it won't read instances that do include the
namespace, but maybe you don't need that...


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:uri fragments vs. ID's in serialized Non-Containment references
Next Topic:Xcore - single container, multiple opposite
Goto Forum:
  


Current Time: Wed Apr 24 15:58:33 GMT 2024

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

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

Back to the top