Skip to main content



      Home
Home » Modeling » EMF » XML Serialization of not-set required attributes/elements
XML Serialization of not-set required attributes/elements [message #877838] Sun, 27 May 2012 18:06 Go to next message
Eclipse UserFriend
Hi,
I have a question, I have an efeature which is required but does not have its default value set (it is null). How can I
force that it is serialized to xml?
Currently it seems that if an efeature is not set and has a null value or no default value then it is not serialized.
I can override the XMLSaveImpl.shouldSaveFeature to always write out required efeatures. Does it make sense?


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: XML Serialization of not-set required attributes/elements [message #877931 is a reply to message #877838] Mon, 28 May 2012 01:09 Go to previous messageGo to next message
Eclipse UserFriend
Hi Martin

I think XMLResource

/**
* Keep default content ( e.g. default attributes). This applies to
saving and converting contents to DOM.
* By default the default content is discarded.
* To save the default content, set this option to
<code>Boolean.TRUE</code>.
*/
String OPTION_KEEP_DEFAULT_CONTENT = "KEEP_DEFAULT_CONTENT";

is what you want in the saveOptions map.

Regards

Ed Willink

On 27/05/2012 23:06, Martin Taal wrote:
> Hi,
> I have a question, I have an efeature which is required but does not
> have its default value set (it is null). How can I force that it is
> serialized to xml?
> Currently it seems that if an efeature is not set and has a null value
> or no default value then it is not serialized.
> I can override the XMLSaveImpl.shouldSaveFeature to always write out
> required efeatures. Does it make sense?
>
>
Re: XML Serialization of not-set required attributes/elements [message #877960 is a reply to message #877931] Mon, 28 May 2012 03:03 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed,
This feature only works if there is a default value but if there is no default value then nothing is serialized, no
default value means also null which is a perfectly fine default value imho.

So my question is specifically for the case of a (required) efeature which has a null default value, how can I get it
serialized if its value is null?

gr. Martin

On 05/28/2012 07:09 AM, Ed Willink wrote:
> Hi Martin
>
> I think XMLResource
>
> /**
> * Keep default content ( e.g. default attributes). This applies to saving and converting contents to DOM.
> * By default the default content is discarded.
> * To save the default content, set this option to <code>Boolean.TRUE</code>.
> */
> String OPTION_KEEP_DEFAULT_CONTENT = "KEEP_DEFAULT_CONTENT";
>
> is what you want in the saveOptions map.
>
> Regards
>
> Ed Willink
>
> On 27/05/2012 23:06, Martin Taal wrote:
>> Hi,
>> I have a question, I have an efeature which is required but does not have its default value set (it is null). How can
>> I force that it is serialized to xml?
>> Currently it seems that if an efeature is not set and has a null value or no default value then it is not serialized.
>> I can override the XMLSaveImpl.shouldSaveFeature to always write out required efeatures. Does it make sense?
>>
>>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: XML Serialization of not-set required attributes/elements [message #877980 is a reply to message #877960] Mon, 28 May 2012 04:34 Go to previous messageGo to next message
Eclipse UserFriend
Hi Martin

xsi:nil is what you need to end up with; I can't see an XMLResource
option, XMLSaverImpl.saveNil seems to be a narrower overload. Of course
if your clever with ExtendedMetaData you can probably do anything.

Regards

Ed Willink


On 28/05/2012 08:03, Martin Taal wrote:
> Hi Ed,
> This feature only works if there is a default value but if there is no
> default value then nothing is serialized, no default value means also
> null which is a perfectly fine default value imho.
>
> So my question is specifically for the case of a (required) efeature
> which has a null default value, how can I get it serialized if its
> value is null?
>
> gr. Martin
>
> On 05/28/2012 07:09 AM, Ed Willink wrote:
>> Hi Martin
>>
>> I think XMLResource
>>
>> /**
>> * Keep default content ( e.g. default attributes). This applies to
>> saving and converting contents to DOM.
>> * By default the default content is discarded.
>> * To save the default content, set this option to
>> <code>Boolean.TRUE</code>.
>> */
>> String OPTION_KEEP_DEFAULT_CONTENT = "KEEP_DEFAULT_CONTENT";
>>
>> is what you want in the saveOptions map.
>>
>> Regards
>>
>> Ed Willink
>>
>> On 27/05/2012 23:06, Martin Taal wrote:
>>> Hi,
>>> I have a question, I have an efeature which is required but does not
>>> have its default value set (it is null). How can
>>> I force that it is serialized to xml?
>>> Currently it seems that if an efeature is not set and has a null
>>> value or no default value then it is not serialized.
>>> I can override the XMLSaveImpl.shouldSaveFeature to always write out
>>> required efeatures. Does it make sense?
>>>
>>>
>>
>
>
Re: XML Serialization of not-set required attributes/elements [message #877989 is a reply to message #877980] Mon, 28 May 2012 04:56 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed,
Thanks, yes I will override to get it done, I just wondered how 'incorrect' that would be.

gr. Martin

On 05/28/2012 10:34 AM, Ed Willink wrote:
> Hi Martin
>
> xsi:nil is what you need to end up with; I can't see an XMLResource option, XMLSaverImpl.saveNil seems to be a narrower
> overload. Of course if your clever with ExtendedMetaData you can probably do anything.
>
> Regards
>
> Ed Willink
>
>
> On 28/05/2012 08:03, Martin Taal wrote:
>> Hi Ed,
>> This feature only works if there is a default value but if there is no default value then nothing is serialized, no
>> default value means also null which is a perfectly fine default value imho.
>>
>> So my question is specifically for the case of a (required) efeature which has a null default value, how can I get it
>> serialized if its value is null?
>>
>> gr. Martin
>>
>> On 05/28/2012 07:09 AM, Ed Willink wrote:
>>> Hi Martin
>>>
>>> I think XMLResource
>>>
>>> /**
>>> * Keep default content ( e.g. default attributes). This applies to saving and converting contents to DOM.
>>> * By default the default content is discarded.
>>> * To save the default content, set this option to <code>Boolean.TRUE</code>.
>>> */
>>> String OPTION_KEEP_DEFAULT_CONTENT = "KEEP_DEFAULT_CONTENT";
>>>
>>> is what you want in the saveOptions map.
>>>
>>> Regards
>>>
>>> Ed Willink
>>>
>>> On 27/05/2012 23:06, Martin Taal wrote:
>>>> Hi,
>>>> I have a question, I have an efeature which is required but does not have its default value set (it is null). How can
>>>> I force that it is serialized to xml?
>>>> Currently it seems that if an efeature is not set and has a null value or no default value then it is not serialized.
>>>> I can override the XMLSaveImpl.shouldSaveFeature to always write out required efeatures. Does it make sense?
>>>>
>>>>
>>>
>>
>>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: XML Serialization of not-set required attributes/elements [message #877993 is a reply to message #877960] Mon, 28 May 2012 05:02 Go to previous messageGo to next message
Eclipse UserFriend
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Martin,<br>
<br>
Is your question about a model that's in an invalid state?&nbsp; A
required feature must be considered set if it is unsettable or must
have a non-null value otherwise:<br>
<br>
<small>&nbsp;&nbsp;&nbsp; else if (eStructuralFeature.isRequired())<br>
&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (eStructuralFeature.isUnsettable() ?
!eObject.eIsSet(eStructuralFeature) :
eObject.eGet(eStructuralFeature, false) == null)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result = false;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (diagnostics != null)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; diagnostics.add<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (createDiagnostic<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Diagnostic.ERROR,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DIAGNOSTIC_SOURCE,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EOBJECT__EVERY_MULTIPCITY_CONFORMS,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "_UI_RequiredFeatureMustBeSet_diagnostic",<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Object [] { getFeatureLabel(eStructuralFeature,
context), getObjectLabel(eObject, context) },<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Object [] { eObject, eStructuralFeature },<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; context));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
</small><br>
Is the feature an EAttribute? In&nbsp; the serialized XML, is supposed to
appear as an XML attribute? In such a case, it's better to ensure
the model's state is valid by setting the value you want serialized.<br>
<br>
<br>
On 28/05/2012 9:03 AM, Martin Taal wrote:
<blockquote cite="mid:jpv80u$t35$1@xxxxxxxxe.org" type="cite">Hi
Ed,
<br>
This feature only works if there is a default value but if there
is no default value then nothing is serialized, no default value
means also null which is a perfectly fine default value imho.
<br>
<br>
So my question is specifically for the case of a (required)
efeature which has a null default value, how can I get it
serialized if its value is null?
<br>
<br>
gr. Martin
<br>
<br>
On 05/28/2012 07:09 AM, Ed Willink wrote:
<br>
<blockquote type="cite">Hi Martin
<br>
<br>
I think XMLResource
<br>
<br>
/**
<br>
* Keep default content ( e.g. default attributes). This applies
to saving and converting contents to DOM.
<br>
* By default the default content is discarded.
<br>
* To save the default content, set this option to
&lt;code&gt;Boolean.TRUE&lt;/code&gt;.
<br>
*/
<br>
String OPTION_KEEP_DEFAULT_CONTENT = "KEEP_DEFAULT_CONTENT";
<br>
<br>
is what you want in the saveOptions map.
<br>
<br>
Regards
<br>
<br>
Ed Willink
<br>
<br>
On 27/05/2012 23:06, Martin Taal wrote:
<br>
<blockquote type="cite">Hi,
<br>
I have a question, I have an efeature which is required but
does not have its default value set (it is null). How can
<br>
I force that it is serialized to xml?
<br>
Currently it seems that if an efeature is not set and has a
null value or no default value then it is not serialized.
<br>
I can override the XMLSaveImpl.shouldSaveFeature to always
write out required efeatures. Does it make sense?
<br>
<br>
<br>
</blockquote>
<br>
</blockquote>
<br>
<br>
</blockquote>
</body>
</html>
Re: XML Serialization of not-set required attributes/elements [message #878206 is a reply to message #877993] Mon, 28 May 2012 16:34 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed,
Hmm, okay, but the same question applies to non-required efeatures, I would like to have these also serialized even if
the value is empty/null, this doesn't happen even if I set the keep default content option, as the eattribute does not
have a default value (it is null, which I want to have serialized also).

gr. Martin

On 05/28/2012 11:02 AM, Ed Merks wrote:
> Martin,
>
> Is your question about a model that's in an invalid state? A required feature must be considered set if it is unsettable
> or must have a non-null value otherwise:
>
> else if (eStructuralFeature.isRequired())
> {
> if (eStructuralFeature.isUnsettable() ? !eObject.eIsSet(eStructuralFeature) : eObject.eGet(eStructuralFeature, false) ==
> null)
> {
> result = false;
> if (diagnostics != null)
> {
> diagnostics.add
> (createDiagnostic
> (Diagnostic.ERROR,
> DIAGNOSTIC_SOURCE,
> EOBJECT__EVERY_MULTIPCITY_CONFORMS,
> "_UI_RequiredFeatureMustBeSet_diagnostic",
> new Object [] { getFeatureLabel(eStructuralFeature, context), getObjectLabel(eObject, context) },
> new Object [] { eObject, eStructuralFeature },
> context));
> }
> }
> }
>
> Is the feature an EAttribute? In the serialized XML, is supposed to appear as an XML attribute? In such a case, it's
> better to ensure the model's state is valid by setting the value you want serialized.
>
>
> On 28/05/2012 9:03 AM, Martin Taal wrote:
>> Hi Ed,
>> This feature only works if there is a default value but if there is no default value then nothing is serialized, no
>> default value means also null which is a perfectly fine default value imho.
>>
>> So my question is specifically for the case of a (required) efeature which has a null default value, how can I get it
>> serialized if its value is null?
>>
>> gr. Martin
>>
>> On 05/28/2012 07:09 AM, Ed Willink wrote:
>>> Hi Martin
>>>
>>> I think XMLResource
>>>
>>> /**
>>> * Keep default content ( e.g. default attributes). This applies to saving and converting contents to DOM.
>>> * By default the default content is discarded.
>>> * To save the default content, set this option to <code>Boolean.TRUE</code>.
>>> */
>>> String OPTION_KEEP_DEFAULT_CONTENT = "KEEP_DEFAULT_CONTENT";
>>>
>>> is what you want in the saveOptions map.
>>>
>>> Regards
>>>
>>> Ed Willink
>>>
>>> On 27/05/2012 23:06, Martin Taal wrote:
>>>> Hi,
>>>> I have a question, I have an efeature which is required but does not have its default value set (it is null). How can
>>>> I force that it is serialized to xml?
>>>> Currently it seems that if an efeature is not set and has a null value or no default value then it is not serialized.
>>>> I can override the XMLSaveImpl.shouldSaveFeature to always write out required efeatures. Does it make sense?
>>>>
>>>>
>>>
>>
>>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: XML Serialization of not-set required attributes/elements [message #878341 is a reply to message #878206] Tue, 29 May 2012 01:33 Go to previous message
Eclipse UserFriend
Martin,

Comments below.

On 28/05/2012 10:34 PM, Martin Taal wrote:
> Hi Ed,
> Hmm, okay, but the same question applies to non-required efeatures, I
> would like to have these also serialized even if the value is empty/null,
In that case, it's certainly not an issue of conformance to a schema,
but rather a stylistic preference. In any case, something needs to be
serialized, so setting what that should be as the default and
instructing the serializer to use what's specified should do the trick...
> this doesn't happen even if I set the keep default content option,
You're right, not if there is no default. Keep in mind that if you want
to serialize as an attribute, there isn't a way to represent null as an
attribute other than its absence. Also note that if you make your
features unsettable, and set a feature, you'll definitely always get
something serialized.
> as the eattribute does not have a default value (it is null, which I
> want to have serialized also).
An xsi:nil="true" XML element is okay?
>
> gr. Martin
>
> On 05/28/2012 11:02 AM, Ed Merks wrote:
>> Martin,
>>
>> Is your question about a model that's in an invalid state? A required
>> feature must be considered set if it is unsettable
>> or must have a non-null value otherwise:
>>
>> else if (eStructuralFeature.isRequired())
>> {
>> if (eStructuralFeature.isUnsettable() ?
>> !eObject.eIsSet(eStructuralFeature) :
>> eObject.eGet(eStructuralFeature, false) ==
>> null)
>> {
>> result = false;
>> if (diagnostics != null)
>> {
>> diagnostics.add
>> (createDiagnostic
>> (Diagnostic.ERROR,
>> DIAGNOSTIC_SOURCE,
>> EOBJECT__EVERY_MULTIPCITY_CONFORMS,
>> "_UI_RequiredFeatureMustBeSet_diagnostic",
>> new Object [] { getFeatureLabel(eStructuralFeature, context),
>> getObjectLabel(eObject, context) },
>> new Object [] { eObject, eStructuralFeature },
>> context));
>> }
>> }
>> }
>>
>> Is the feature an EAttribute? In the serialized XML, is supposed to
>> appear as an XML attribute? In such a case, it's
>> better to ensure the model's state is valid by setting the value you
>> want serialized.
>>
>>
>> On 28/05/2012 9:03 AM, Martin Taal wrote:
>>> Hi Ed,
>>> This feature only works if there is a default value but if there is
>>> no default value then nothing is serialized, no
>>> default value means also null which is a perfectly fine default
>>> value imho.
>>>
>>> So my question is specifically for the case of a (required) efeature
>>> which has a null default value, how can I get it
>>> serialized if its value is null?
>>>
>>> gr. Martin
>>>
>>> On 05/28/2012 07:09 AM, Ed Willink wrote:
>>>> Hi Martin
>>>>
>>>> I think XMLResource
>>>>
>>>> /**
>>>> * Keep default content ( e.g. default attributes). This applies to
>>>> saving and converting contents to DOM.
>>>> * By default the default content is discarded.
>>>> * To save the default content, set this option to
>>>> <code>Boolean.TRUE</code>.
>>>> */
>>>> String OPTION_KEEP_DEFAULT_CONTENT = "KEEP_DEFAULT_CONTENT";
>>>>
>>>> is what you want in the saveOptions map.
>>>>
>>>> Regards
>>>>
>>>> Ed Willink
>>>>
>>>> On 27/05/2012 23:06, Martin Taal wrote:
>>>>> Hi,
>>>>> I have a question, I have an efeature which is required but does
>>>>> not have its default value set (it is null). How can
>>>>> I force that it is serialized to xml?
>>>>> Currently it seems that if an efeature is not set and has a null
>>>>> value or no default value then it is not serialized.
>>>>> I can override the XMLSaveImpl.shouldSaveFeature to always write
>>>>> out required efeatures. Does it make sense?
>>>>>
>>>>>
>>>>
>>>
>>>
>
>
Previous Topic:NPE in EcoreSchemaBuilder transformDefaultValue
Next Topic:Model Package not registered
Goto Forum:
  


Current Time: Tue Jul 01 14:54:00 EDT 2025

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

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

Back to the top