Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Avoiding xsi:type in instance serializations with no target namespace in schema
Avoiding xsi:type in instance serializations with no target namespace in schema [message #659096] Thu, 10 March 2011 23:22 Go to next message
Nalini Ganapati is currently offline Nalini GanapatiFriend
Messages: 5
Registered: July 2009
Junior Member
We have a requirement to not have any namespace pollution in the
instance serializations. I got the example from Ed's blog
http://ed-merks.blogspot.com/2007_12_01_archive.html to work with a
targetNamespace specified in the schema. However, when there is no
targetNamespace, the elements under the root are serialized fine without
the namespace, but all the other elements have the xsi:types.
e.g.
<?xml version="1.0" encoding="UTF-8"?>
<fileSystem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.example.com/resource">
<folder name="folder1">
<member xsi:type="File" name="file1"/>
<member xsi:type="Folder" name="nestedFolder"/>
</folder>
</fileSystem>

I am new to EMF, so was wondering if it is possible at all to avoid the
xsi:type for all the elements?

Thanks,
Nalini.
Re: Avoiding xsi:type in instance serializations with no target namespace in schema [message #659097 is a reply to message #659096] Thu, 10 March 2011 23:29 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Nalini,

Comments below.


Nalini Ganapati wrote:
> We have a requirement to not have any namespace pollution in the
> instance serializations.
Pollution. :-P
> I got the example from Ed's blog
> http://ed-merks.blogspot.com/2007_12_01_archive.html to work with a
> targetNamespace specified in the schema. However, when there is no
> targetNamespace, the elements under the root are serialized fine
> without the namespace, but all the other elements have the xsi:types.
> e.g.
> <?xml version="1.0" encoding="UTF-8"?>
> <fileSystem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="http://www.example.com/resource">
> <folder name="folder1">
> <member xsi:type="File" name="file1"/>
> <member xsi:type="Folder" name="nestedFolder"/>
> </folder>
> </fileSystem>
>
> I am new to EMF, so was wondering if it is possible at all to avoid
> the xsi:type for all the elements?
Only by avoiding subclassing or with the use of substitution groups, but
I think you found that blog. You're saying it's not working for
non-namespace schemas? You're sure you're using this option for save?

result.getDefaultSaveOptions().put
(XMLResource.OPTION_ELEMENT_HANDLER,
new ElementHandlerImpl(false));


>
> Thanks,
> Nalini.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Avoiding xsi:type in instance serializations with no target namespace in schema [message #659100 is a reply to message #659097] Fri, 11 March 2011 00:44 Go to previous messageGo to next message
Nalini Ganapati is currently offline Nalini GanapatiFriend
Messages: 5
Registered: July 2009
Junior Member
On 3/10/2011 3:29 PM, Ed Merks wrote:
> Nalini,
>
> Comments below.
>
>
> Nalini Ganapati wrote:
>> We have a requirement to not have any namespace pollution in the
>> instance serializations.
> Pollution. :-P
>> I got the example from Ed's blog
>> http://ed-merks.blogspot.com/2007_12_01_archive.html to work with a
>> targetNamespace specified in the schema. However, when there is no
>> targetNamespace, the elements under the root are serialized fine
>> without the namespace, but all the other elements have the xsi:types.
>> e.g.
>> <?xml version="1.0" encoding="UTF-8"?>
>> <fileSystem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xsi:noNamespaceSchemaLocation="http://www.example.com/resource">
>> <folder name="folder1">
>> <member xsi:type="File" name="file1"/>
>> <member xsi:type="Folder" name="nestedFolder"/>
>> </folder>
>> </fileSystem>
>>
>> I am new to EMF, so was wondering if it is possible at all to avoid
>> the xsi:type for all the elements?
> Only by avoiding subclassing or with the use of substitution groups, but
> I think you found that blog. You're saying it's not working for
> non-namespace schemas? You're sure you're using this option for save?
>
> result.getDefaultSaveOptions().put
> (XMLResource.OPTION_ELEMENT_HANDLER, new ElementHandlerImpl(false));


Yes, I am using the options XMLResource.OPTION_ELEMENT_HANDLER for save.

I tried a couple of things, I just added ExtendedMetadata entry
qualified=true on the ecore generated while generating the model from
the schema. And then used this ecore to reload the model. This resulted
in the xsi:type for all the elements under the root.

The next time, I removed the targetNamespace from the resource example
xsd itself and all references to resource to generate the model. That
also had the xsi:type for the elements not under the root.

We may not be able to avoid the subclassing, so will be using
substitution groups. So, you think what was outlined in the blog should
work for non-namespace schemas too?

Thanks,
Nalini.
Re: Avoiding xsi:type in instance serializations with no target namespace in schema [message #659101 is a reply to message #659100] Fri, 11 March 2011 01:13 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Nalini,

I think it should work, but I haven't tried. It would be a bug if it
doesn't...


Nalini Ganapati wrote:
> On 3/10/2011 3:29 PM, Ed Merks wrote:
>> Nalini,
>>
>> Comments below.
>>
>>
>> Nalini Ganapati wrote:
>>> We have a requirement to not have any namespace pollution in the
>>> instance serializations.
>> Pollution. :-P
>>> I got the example from Ed's blog
>>> http://ed-merks.blogspot.com/2007_12_01_archive.html to work with a
>>> targetNamespace specified in the schema. However, when there is no
>>> targetNamespace, the elements under the root are serialized fine
>>> without the namespace, but all the other elements have the xsi:types.
>>> e.g.
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <fileSystem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> xsi:noNamespaceSchemaLocation="http://www.example.com/resource">
>>> <folder name="folder1">
>>> <member xsi:type="File" name="file1"/>
>>> <member xsi:type="Folder" name="nestedFolder"/>
>>> </folder>
>>> </fileSystem>
>>>
>>> I am new to EMF, so was wondering if it is possible at all to avoid
>>> the xsi:type for all the elements?
>> Only by avoiding subclassing or with the use of substitution groups, but
>> I think you found that blog. You're saying it's not working for
>> non-namespace schemas? You're sure you're using this option for save?
>>
>> result.getDefaultSaveOptions().put
>> (XMLResource.OPTION_ELEMENT_HANDLER, new ElementHandlerImpl(false));
>
>
> Yes, I am using the options XMLResource.OPTION_ELEMENT_HANDLER for save.
>
> I tried a couple of things, I just added ExtendedMetadata entry
> qualified=true on the ecore generated while generating the model from
> the schema. And then used this ecore to reload the model. This
> resulted in the xsi:type for all the elements under the root.
>
> The next time, I removed the targetNamespace from the resource example
> xsd itself and all references to resource to generate the model. That
> also had the xsi:type for the elements not under the root.
>
> We may not be able to avoid the subclassing, so will be using
> substitution groups. So, you think what was outlined in the blog
> should work for non-namespace schemas too?
>
> Thanks,
> Nalini.
>
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Avoiding xsi:type in instance serializations with no target namespace in schema [message #659599 is a reply to message #659101] Mon, 14 March 2011 18:35 Go to previous message
Nalini Ganapati is currently offline Nalini GanapatiFriend
Messages: 5
Registered: July 2009
Junior Member
Ed, I have filed https://bugs.eclipse.org/bugs/show_bug.cgi?id=339935 as
this does not work for me.

It looks like the bug is in the BasicExtendedMetadata class where the
substitution group does not seem to get resolved when there is no
namespace. I have just started debugging this to see if I can workaround
this issue, but was wondering if you have any tips for workarounds here.

Thanks,
Nalini.

On 3/10/2011 5:13 PM, Ed Merks wrote:
> Nalini,
>
> I think it should work, but I haven't tried. It would be a bug if it
> doesn't...
>
>
> Nalini Ganapati wrote:
>> On 3/10/2011 3:29 PM, Ed Merks wrote:
>>> Nalini,
>>>
>>> Comments below.
>>>
>>>
>>> Nalini Ganapati wrote:
>>>> We have a requirement to not have any namespace pollution in the
>>>> instance serializations.
>>> Pollution. :-P
>>>> I got the example from Ed's blog
>>>> http://ed-merks.blogspot.com/2007_12_01_archive.html to work with a
>>>> targetNamespace specified in the schema. However, when there is no
>>>> targetNamespace, the elements under the root are serialized fine
>>>> without the namespace, but all the other elements have the xsi:types.
>>>> e.g.
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <fileSystem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>> xsi:noNamespaceSchemaLocation="http://www.example.com/resource">
>>>> <folder name="folder1">
>>>> <member xsi:type="File" name="file1"/>
>>>> <member xsi:type="Folder" name="nestedFolder"/>
>>>> </folder>
>>>> </fileSystem>
>>>>
>>>> I am new to EMF, so was wondering if it is possible at all to avoid
>>>> the xsi:type for all the elements?
>>> Only by avoiding subclassing or with the use of substitution groups, but
>>> I think you found that blog. You're saying it's not working for
>>> non-namespace schemas? You're sure you're using this option for save?
>>>
>>> result.getDefaultSaveOptions().put
>>> (XMLResource.OPTION_ELEMENT_HANDLER, new ElementHandlerImpl(false));
>>
>>
>> Yes, I am using the options XMLResource.OPTION_ELEMENT_HANDLER for save.
>>
>> I tried a couple of things, I just added ExtendedMetadata entry
>> qualified=true on the ecore generated while generating the model from
>> the schema. And then used this ecore to reload the model. This
>> resulted in the xsi:type for all the elements under the root.
>>
>> The next time, I removed the targetNamespace from the resource example
>> xsd itself and all references to resource to generate the model. That
>> also had the xsi:type for the elements not under the root.
>>
>> We may not be able to avoid the subclassing, so will be using
>> substitution groups. So, you think what was outlined in the blog
>> should work for non-namespace schemas too?
>>
>> Thanks,
>> Nalini.
>>
>>
>>
>>
Previous Topic:[CDO/Teneo] Data type error with H2 support
Next Topic:How to: Ecore Diagram for EMF
Goto Forum:
  


Current Time: Thu Mar 28 14:30:55 GMT 2024

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

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

Back to the top