Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Missing XML namespace declaration(Missing XML namespace declaration when XMLResource is serialized)
Missing XML namespace declaration [message #1044931] Fri, 19 April 2013 10:21 Go to next message
Charles Bonneau is currently offline Charles Bonneau
Messages: 32
Registered: February 2010
Location: Belgium
Member
Hello,
Here is my set-up:
I have two Ecore models, one that references the other: B->A
I uses XML serialization of models (instances of Ecores).
I've generated the XSDs for the two Ecore models.
As expected the schema of the Ecore model B imports the schema A:
<xsd:schema xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
	xmlns:A_prefix="http://A.nsURI"
	xmlns:B_prefix="http://B.nsURI"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
        ecore:nsPrefix="B_prefix"
	ecore:package="BPackage"
	targetNamespace="http://B.nsURI">
[...]
 <xsd:import namespace = "http://A.nsURI" schemaLocation="platform:/plugin/where/the/schema/A/is"/>
[..]
</xsd:schema>

The problem is that when I try to create an instance of my model B and serialize it using XMLResource, the namespace of the referenced ecore(schema) is missing :
I only get the xmlns of the Ecore model B and its schemaLocation value.
<?xml version="1.0" encoding="UTF-8"?>
<B_prefix:rootNode
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:B_prefix="http://B.nsURI"
	xsi:schemaLocation="http://B.nsURI java://BPackage"
	id="test.component12" version="1.0.0" />

I fear that is because no instance of Ecore model A has been created yet.
How can I force the XML resource to add all the needed namespace declaration even on an empty instance ?
While debugging I found that the XMLHelper of the XMLSave has a package list, I though may be I should try to add the missing package here. But I haven't find a way to do it.
One other thing, I would like to avoid touching the generated code i.e. BResource.java

Any idea ?

I hope it clear enough.

Best regards,

Charles

[Updated on: Fri, 19 April 2013 10:35]

Report message to a moderator

Re: Missing XML namespace declaration [message #1045349 is a reply to message #1044931] Sat, 20 April 2013 01:16 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25747
Registered: July 2009
Senior Member
Charles,

Comments below.

On 19/04/2013 4:21 PM, Charles Bonneau wrote:
> Hello,
> Here is my set-up:
> I have two Ecore models, one that references the other: B->A
> I uses XML serialization of models (instances of Ecores).
> I've generated the XSDs for the two Ecore models.
> As expected the schema of the Ecore model (B) that references the
> other one contains imports of the schema of the other one (A):
>
> <xsd:schema [...]
> xmlns:B_prefix="http://B.nsURI"
> xmlns:A_prefix="http://A.nsURI">
> [...]
> <xsd:import namespace = "http://A.nsURI"
> schemaLocation="platform:/plugin/where/the/schema/A/is"/>
> [..]
> </xsd:schema>
>
> The problem is that when I try to create an instance of my model B and
> serialize it using XMLResource, the namespace of the referenced
> ecore(schema) is missing :
> I only get the xmlns of the Ecore model B and its schemaLocation value.
> I fear that is because no instance of Ecore model A has been created yet.
> How can I force the XML resource to add all the needed namespace
> declaration even on an empty instance ?
It seems to me this comment is self contradictory. Why would an empty
instance need anything other than the namespace of the root element?
> While debugging I found that the XMLHelper of the XMLSave has a
> package list, I though may be I should try to add the missing package
> here. But I haven't find a way to do it.
> One other thing, I would like to avoid touching the generated code
> i.e. BResource.java
>
> Any idea ?
If there is a DocumentRoot involved, (if this is a schema-derived model,
but it doesn't sound like that) you can populate namespaces via that.
>
> I hope it clear enough.
No really. What makes you think you need a namespace? Serialization
generally produces the namespace you actually need and not any you don't
need, so the fact there's something missing implies to me it's not needed...
>
> Best regards,
>
> Charles
Re: Missing XML namespace declaration [message #1046661 is a reply to message #1045349] Mon, 22 April 2013 03:46 Go to previous messageGo to next message
Charles Bonneau is currently offline Charles Bonneau
Messages: 32
Registered: February 2010
Location: Belgium
Member
Hello,
Thank you for your answer, I'll try to declare the namespaces via the DocumentRoot.

Let me explain a bit more my situation :
The problem is that some of our users prefer to use the default XML editor to edit models Confused .
To do so, they were using the default "New XML File" wizard which creates a XML file with all the needed XML Namespace declaration and schema locations, which provides a content assistant based on XML Schemas.
We are providing a wizard to create models. This wizard creates a empty model using Java and serialize it in XML, but our users (the ones whose prefer XML) complain that some XML Namespace declaration and schema locations are missing and that the content assistant isn't providing the result they were expecting.
If I understand correctly, the problem is that for the XMLResource, the XML Schema namespace and location of the imported schema are not needed at serialization time, because there isn't any instance of that schema yet.
That why I wanted to compute and declare all the XML schema before the serialization of the model.

Best regards,

Charles


Re: Missing XML namespace declaration [message #1046677 is a reply to message #1046661] Mon, 22 April 2013 04:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25747
Registered: July 2009
Senior Member
Charles,

What's the relation between the schemas? I.e., does the schema of the
root element import the schema of the "missing" namespaces? If so, I'd
expect content assist to know about both schemas. Also, I'd imagine
that most XML editors don't require explicit schema locations but allow
configuration so that one can specify the location associated with a
namespace so that documents with only namespaces can be nicely edited;
certainly WTP's editor supports that.


On 22/04/2013 9:46 AM, Charles Bonneau wrote:
> Hello,
> Thank you for your answer, I'll try to declare the namespaces via the
> DocumentRoot.
>
> Let me explain a bit more my situation :
> The problem is that some of our users prefer to use the default XML
> editor to edit models :? .
> To do so, they were using the default "New XML File" wizard which
> creates a XML file with all the needed XML Namespace declaration and
> schema locations, which provides a content assistant based on XML
> Schemas.
> We are providing a wizard to create models. This wizard creates a
> empty model using Java and serialize it in XML, but our users (the
> ones whose prefer XML) complain that some XML Namespace declaration
> and schema locations are missing and that the content assistant isn't
> providing the result they were expecting.
> If I understand correctly, the problem is that for the XMLResource,
> the XML Schema namespace and location of the imported schema are not
> needed at serialization time, because there isn't any instance of that
> schema yet.
> That why I wanted to compute and declare all the XML schema before the
> serialization of the model.
>
> Best regards,
>
> Charles
>
>
>
Re: Missing XML namespace declaration [message #1046692 is a reply to message #1046677] Mon, 22 April 2013 04:39 Go to previous messageGo to next message
Charles Bonneau is currently offline Charles Bonneau
Messages: 32
Registered: February 2010
Location: Belgium
Member
Ed,
Indeed schema of the root element import the schema of the "missing" namespaces :
<xsd:schema xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
	xmlns:A_prefix="http://A.nsURI"
	xmlns:B_prefix="http://B.nsURI"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
        ecore:nsPrefix="B_prefix"
	ecore:package="BPackage"
	targetNamespace="http://B.nsURI">
[...]
 <xsd:import namespace = "http://A.nsURI" schemaLocation="platform:/plugin/where/the/schema/A/is"/>
[..]
</xsd:schema>

And the content assistant provides results, but without the namespace declaration, the results are wrong :
<?xml version="1.0" encoding="UTF-8"?>
<B_prefix:rootNode
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:B_prefix="http://B.nsURI"
	xsi:schemaLocation="http://B.nsURI java://BPackage"
	id="test.component12" version="1.0.0" >


        <node xsi:type="<!-- when calling content assist here, the result is : "ANode", instead of "A_prefix:ANode" and the editor marks it as an error:
        "Cannot resolve 'ANode' to a type definition for element 'node'."-->
        "/>


<!-- it is because the namespace declaration is missing :  xmlns:A_prefix="http://A.nsURI"-->    
        
</B_prefix:rootNode>

My bad, only the xml namespace declaration is needed, not the schema location.

I tried to add the missing declaration manually and everything worked as expected.

BR,

Charles

Re: Missing XML namespace declaration [message #1046697 is a reply to message #1046692] Mon, 22 April 2013 04:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25747
Registered: July 2009
Senior Member
Charles,

But even that sounds like a bug (shortcoming) in the XML editor. Content
assist should be able to know all the schemas imported by any schema
whose namespace appears in the document. It should be able to suggest
things from namespaces not already in the document and should be able to
add the namespace as needed. I.e., it should be able to do as good a
job as the EMF editor itself does...



On 22/04/2013 10:39 AM, Charles Bonneau wrote:
> Ed,
> Indeed schema of the root element import the schema of the "missing"
> namespaces :
> <xsd:schema xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xmlns:A_prefix="http://A.nsURI"
> xmlns:B_prefix="http://B.nsURI"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> ecore:nsPrefix="B_prefix"
> ecore:package="BPackage"
> targetNamespace="http://B.nsURI">
> [...]
> <xsd:import namespace = "http://A.nsURI"
> schemaLocation="platform:/plugin/where/the/schema/A/is"/>
> [..]
> </xsd:schema>
>
> And the content assistant provides results, but without the namespace
> declaration, the results are wrong :
> <?xml version="1.0" encoding="UTF-8"?>
> <B_prefix:rootNode
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:B_prefix="http://B.nsURI"
> xsi:schemaLocation="http://B.nsURI java://BPackage"
> id="test.component12" version="1.0.0" >
>
>
> <node xsi:type="<!-- when calling content assist here, the
> result is : "ANode", instead of "A_prefix:ANode" and the editor marks
> it as an error:
> "Cannot resolve 'ANode' to a type definition for element
> 'node'."-->
> "/>
>
>
> <!-- it is because the namespace declaration is missing :
> xmlns:A_prefix="http://A.nsURI"--> </B_prefix:rootNode>
>
> My bad, only the xml namespace declaration is needed, not the schema
> location.
>
> I tried to add the missing declaration manually and everything worked
> as expected.
>
> BR,
>
> Charles
>
>
Re: Missing XML namespace declaration [message #1046701 is a reply to message #1046697] Mon, 22 April 2013 04:49 Go to previous messageGo to next message
Charles Bonneau is currently offline Charles Bonneau
Messages: 32
Registered: February 2010
Location: Belgium
Member
OK, so I guess I'll have to check WTP's forum.
Thanks a lot for your time.

BR,

Charles
Re: Missing XML namespace declaration [message #1046848 is a reply to message #1046701] Mon, 22 April 2013 09:07 Go to previous messageGo to next message
Charles Bonneau is currently offline Charles Bonneau
Messages: 32
Registered: February 2010
Location: Belgium
Member
Hello,
I looked at WTP's forum and it seems that there is a bug related to the content assistant.

On the EMF side is there some kind of Flag to set to the XMLSave, to say "declare all the namespace of the package that might be used even though they aren't used yet" ?

The goal would be to have an empty model serialized this way :
<B_prefix:rootNode
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:B_prefix="http://B.nsURI"
        xmlns:A_prefix="http://A.nsURI"
        xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
	xsi:schemaLocation="http://B.nsURI java://BPackage"
	id="test.component12" version="1.0.0" />


Best regards,

Charles
Re: Missing XML namespace declaration [message #1046965 is a reply to message #1046848] Mon, 22 April 2013 11:57 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 25747
Registered: July 2009
Senior Member
Charles,

Comments below.


On 22/04/2013 3:07 PM, Charles Bonneau wrote:
> Hello,
> I looked at WTP's forum and it seems that there is a bug related to
> the content assistant.
>
> On the EMF side is there some kind of Flag to set to the XMLSave, to
> say "declare all the namespace of the package that might be used even
> though they aren't used yet" ?
No. That's generally even unbounded if you consider that any other
schema can extend the complex types or contribute to substitution groups
heads, i.e., elements.
>
> The goal would be to have an empty model serialized this way :
>
> <B_prefix:rootNode
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:B_prefix="http://B.nsURI"
> xmlns:A_prefix="http://A.nsURI"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xsi:schemaLocation="http://B.nsURI java://BPackage"
> id="test.component12" version="1.0.0" />
If there is a document root (if it's an XML Schema-based model) you can
control all such things explicitly.
>
>
> Best regards,
>
> Charles
Previous Topic:[CDO] Migrate Repository when Ecore changes
Next Topic:Eclipse e4 not running directly from product configuration file
Goto Forum:
  


Current Time: Sun Apr 20 16:04:05 EDT 2014

Powered by FUDForum. Page generated in 0.01851 seconds