Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF] Required XML Attributes with only one value
[EMF] Required XML Attributes with only one value [message #1194887] Mon, 18 November 2013 18:56 Go to next message
Benjamin M. is currently offline Benjamin M.Friend
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 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30688
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...
>
Re: [EMF] Required XML Attributes with only one value [message #1196235 is a reply to message #1196130] Tue, 19 November 2013 10:06 Go to previous message
Benjamin M. is currently offline Benjamin M.Friend
Messages: 13
Registered: September 2012
Junior Member
Thanks for sharing your time Ed, then I just have to stick with modifying the EAttribute. The annoying side effect is that the needed option of keep_default_content is affecting other elements as well...

Cheers,
Ben
Previous Topic:Null pointer exception in EStructuralFeatureImpl.getSettingDelegate
Next Topic:Best Practices - associate UI to EObject creation
Goto Forum:
  


Current Time: Tue Dec 10 23:41:55 GMT 2019

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

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

Back to the top