[EMF] Required XML Attributes with only one value [message #1194887] |
Mon, 18 November 2013 18:56 |
Benjamin M. Messages: 13 Registered: September 2012 |
Junior Member |
|
|
Hello everyone,
I actually found some threads about this topic, but they are not up to date and sadly didn't solve my problem.
As far as I know XML attributes which are set to be required, but have only one value they can obtain, are not getting serialized with EMF. I also agree to the concept behind this, but sadly SAP requires to have such xml attributes declared.
I used the given xsd's from SAP and created my Ecore Models out of it, this worked fine. The actual part of the xsd I am talking about is the following:
<xsd:attribute name="BEGIN" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="1"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
This creates the corresponding emf property for BEGIN:
Default Value = "_1 = 0"
Since the Default Value Literal property is empty, the xml attribute is not being serialized.
The Thread http://www.eclipsezone.com/eclipse/forums/t112254.html already discussed this topic. I noticed that nowadays such xml attributes are by default unsettable, but sadly this didn't fix my problem.
The only workaround I found is to manually set
xmlResource.getDefaultSaveOptions().put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE); and to set the Default Value Literal to "1".
Is there any other way to achieve the serialization of such xml attributes without changing their Default Value Literal fields programmatically?
Any help is appreciated,
Greetings,
Ben
PS: I am aware that this fails due to the shouldSaveFeature() Method, since the attribute is always not set and the Default Literal Value is empty...
|
|
|
Re: [EMF] Required XML Attributes with only one value [message #1196130 is a reply to message #1194887] |
Tue, 19 November 2013 09:01 |
Ed Merks Messages: 33113 Registered: July 2009 |
Senior Member |
|
|
Benjamin,
Comments below.
On 18/11/2013 7:56 PM, Benjamin M. wrote:
> Hello everyone,
>
> I actually found some threads about this topic, but they are not up to
> date and sadly didn't solve my problem.
>
> As far as I know XML attributes which are set to be required, but have
> only one value they can obtain, are not getting serialized with EMF. I
> also agree to the concept behind this, but sadly SAP requires to have
> such xml attributes declared.
>
> I used the given xsd's from SAP and created my Ecore Models out of it,
> this worked fine. The actual part of the xsd I am talking about is the
> following:
>
> <xsd:attribute name="BEGIN" use="required">
> <xsd:simpleType>
> <xsd:restriction base="xsd:string">
> <xsd:enumeration value="1"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:attribute>
>
> This creates the corresponding emf property for BEGIN:
> Default Value = "_1 = 0"
>
> Since the Default Value Literal property is empty, the xml attribute
> is not being serialized.
>
> The Thread http://www.eclipsezone.com/eclipse/forums/t112254.html
> already discussed this topic. I noticed that nowadays such xml
> attributes are by default unsettable, but sadly this didn't fix my
> problem.
If you set the value it will be serialized, but if you don't set it, the
instance is invalid, and if you serialize it, there will be no value
because you didn't set one.
>
> The only workaround I found is to manually set
> xmlResource.getDefaultSaveOptions().put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT,
> Boolean.TRUE); and to set the Default Value Literal to "1".
Set the value of of that feature in the instance is more correct.
>
> Is there any other way to achieve the serialization of such xml
> attributes without changing their Default Value Literal fields
> programmatically?
The feature is required, so it must be present in the XML, and so when
you deserialize, the instance has the value set. But if you create a
new instance, you must set the value.
>
> Any help is appreciated,
>
> Greetings,
> Ben
>
> PS: I am aware that this fails due to the shouldSaveFeature() Method,
> since the attribute is always not set and the Default Literal Value is
> empty...
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.02804 seconds