Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » XMLResource.OPTION_SAVE_TYPE_INFORMATION has no effect when saved as xml
XMLResource.OPTION_SAVE_TYPE_INFORMATION has no effect when saved as xml [message #431142] Tue, 30 June 2009 05:19 Go to next message
Guido Schnider is currently offline Guido Schnider
Messages: 6
Registered: July 2009
Junior Member
Hi,

I trying to remove the xsi:type information like

<language xsi:type="language">de</language>

and found the following code snipplet and tried it out but it has no
effect.
How can I remove the xsi type informatin when persisting to xml

resource.getDefaultSaveOptions().put(XMLResource.OPTION_SAVE _TYPE_INFORMATION,
Boolean.FALSE);

I'm using emf version 2.4

Thanks for you help!

Guido
Re: XMLResource.OPTION_SAVE_TYPE_INFORMATION has no effect when saved as xml [message #431145 is a reply to message #431142] Tue, 30 June 2009 05:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25940
Registered: July 2009
Senior Member
Guido,

You need to provide an instance of XMLTypeInfo not just a Boolean.


Guido Schnider wrote:
> Hi,
>
> I trying to remove the xsi:type information like
> <language xsi:type="language">de</language>
>
> and found the following code snipplet and tried it out but it has no
> effect.
> How can I remove the xsi type informatin when persisting to xml
>
> resource.getDefaultSaveOptions().put(XMLResource.OPTION_SAVE _TYPE_INFORMATION,
> Boolean.FALSE);
>
> I'm using emf version 2.4
>
> Thanks for you help!
>
> Guido
>
Re: XMLResource.OPTION_SAVE_TYPE_INFORMATION has no effect when saved as xml [message #431151 is a reply to message #431145] Tue, 30 June 2009 06:08 Go to previous messageGo to next message
Guido Schnider is currently offline Guido Schnider
Messages: 6
Registered: July 2009
Junior Member
Thanks for the quick help, it works!

Here the code just as reference for others:
----------
XMLTypeInfo typeInfo = new XMLSave.XMLTypeInfo() {

public boolean shouldSaveType(EClass arg0, EClassifier
arg1,EStructuralFeature arg2) {
return false;
}

public boolean shouldSaveType(EClass arg0, EClass arg1,EStructuralFeature
arg2) {
return false;
}

};
resource.getDefaultSaveOptions().put(XMLResource.OPTION_SAVE _TYPE_INFORMATION,
typeInfo);
Re: XMLResource.OPTION_SAVE_TYPE_INFORMATION has no effect when saved as xml [message #661993 is a reply to message #431151] Mon, 28 March 2011 15:10 Go to previous messageGo to next message
Piotr Przybylski is currently offline Piotr Przybylski
Messages: 5
Registered: March 2011
Junior Member
Hi,
I tried to use this option and code from the previous post but it does not seem to have any effect when the type is xsd:uinon. Irrespective of the value returned by the XMLTypeInfo implementation, the xsi:type is always serialized. Is this caused by design of enforcing correct form irrespective of options ? Or can there be any other reason option has no effect for this specific type ? It does work for other types.

Thank you,

Piotr
Re: XMLResource.OPTION_SAVE_TYPE_INFORMATION has no effect when saved as xml [message #661995 is a reply to message #661993] Mon, 28 March 2011 15:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25940
Registered: July 2009
Senior Member
Piotr,

I'd need to see a complete example. You have a global elements of that
union type?


Piotr Przybylski wrote:
> Hi, I tried to use this option and code from the previous post but it
> does not seem to have any effect when the type is xsd:uinon.
> Irrespective of the value returned by the XMLTypeInfo implementation,
> the xsi:type is always serialized. Is this caused by design of
> enforcing correct form irrespective of options ? Or can there be any
> other reason option has no effect for this specific type ? It does
> work for other types.
> Thank you,
>
> Piotr
Re: XMLResource.OPTION_SAVE_TYPE_INFORMATION has no effect when saved as xml [message #662094 is a reply to message #661995] Tue, 29 March 2011 05:25 Go to previous messageGo to next message
Piotr Przybylski is currently offline Piotr Przybylski
Messages: 5
Registered: March 2011
Junior Member
Ed,
I don't think there are global elements of that type, its defined as follows (relevant fragments, the whole thing is part of industry schemas - oagis/star)

<xsd:simpleType name="CountryContentType">
<xsd:union memberTypes=" CountryEnumeratedType"/>
</xsd:simpleType>
...
<xsd:simpleType name="CountryEnumeratedType">

<xsd:restriction base="xsd:normalizedString">
<xsd:enumeration value="US">

</xsd:enumeration>
<xsd:enumeration value="AF">
...

and being used deep down in the structure of the document, the trimmed xml looks something like code below, the [xsi:type="p:CountryEnumeratedType"] is the one I would like to remove.



<?xml version="1.0" encoding="UTF-8"?>
<p:SyncVehicleServiceHistoryType xmlns:p="http://www.company.com/xsitypetest" xmlns:ns0="http://www.company.com/xsitypetest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="p:SyncVehicleServiceHistoryType">
<p:SyncVehicleServiceHistoryDataArea>
<p:VehicleServiceHistory>
<p:VehicleServiceHistoryDetail>
<p:OwnerParty>
<p:SpecifiedPerson>
<p:PostalAddress>
<p:CountryID xmlns:ns1="http://www.company.com/xsitypetest" xsi:type="p:CountryEnumeratedType">US</p:CountryID>
</p:PostalAddress>
</p:SpecifiedPerson>
</p:OwnerParty>
</p:VehicleServiceHistoryDetail>
</p:VehicleServiceHistory>
</p:SyncVehicleServiceHistoryDataArea>
</p:SyncVehicleServiceHistoryType>

Thank you,

Piotr.
Re: XMLResource.OPTION_SAVE_TYPE_INFORMATION has no effect when saved as xml [message #662166 is a reply to message #662094] Tue, 29 March 2011 11:22 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25940
Registered: July 2009
Senior Member
Piotr,

Comments below.

Piotr Przybylski wrote:
> Ed, I don't think there are global elements of that type, its defined
> as follows (relevant fragments, the whole thing is part of industry
> schemas - oagis/star)
Given there is an established schema, don't you need a serialization
that conforms to it?
> <xsd:simpleType name="CountryContentType">
> <xsd:union memberTypes=" CountryEnumeratedType"/>
> </xsd:simpleType>
> ..
> <xsd:simpleType name="CountryEnumeratedType">
> <xsd:restriction base="xsd:normalizedString">
> <xsd:enumeration value="US">
> </xsd:enumeration>
> <xsd:enumeration value="AF">
> ..
>
> and being used deep down in the structure of the document, the trimmed
> xml looks something like code below, the
> [xsi:type="p:CountryEnumeratedType"] is the one I would like to remove.
This XML was produced by EMF?
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <p:SyncVehicleServiceHistoryType
> xmlns:p="http://www.company.com/xsitypetest"
> xmlns:ns0="http://www.company.com/xsitypetest"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:type="p:SyncVehicleServiceHistoryType">
> <p:SyncVehicleServiceHistoryDataArea>
> <p:VehicleServiceHistory>
> <p:VehicleServiceHistoryDetail>
> <p:OwnerParty>
> <p:SpecifiedPerson>
> <p:PostalAddress>
> <p:CountryID
> xmlns:ns1="http://www.company.com/xsitypetest"
> xsi:type="p:CountryEnumeratedType">US</p:CountryID>
What does the type for PostalAddress look like? In particular the
definition of the CountryID element and its type as well.
> </p:PostalAddress>
> </p:SpecifiedPerson>
> </p:OwnerParty>
> </p:VehicleServiceHistoryDetail>
> </p:VehicleServiceHistory>
> </p:SyncVehicleServiceHistoryDataArea>
> </p:SyncVehicleServiceHistoryType>
>
> Thank you,
> Piotr.
Re: XMLResource.OPTION_SAVE_TYPE_INFORMATION has no effect when saved as xml [message #662186 is a reply to message #661995] Tue, 29 March 2011 12:18 Go to previous messageGo to next message
Piotr Przybylski is currently offline Piotr Przybylski
Messages: 5
Registered: March 2011
Junior Member
Ed,
yes, I would like to get XML matching schema but it seems the xsi:type for that specific element is invalid:

[Error] XSITypeTest.xml:9:110: cvc-elt.4.3: Type 'p:CountryEnumeratedType' is not validly derived from the type definition, 'CountryCodeType', of element 'p:CountryID'.

most likely caused by blockDefault="#all" directive.

Here is larger fragment of the schema with the types defined:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.company.com/xsitypetest" attributeFormDefault="unqualified"
blockDefault="#all" elementFormDefault="qualified"
targetNamespace="http://www.company.com/xsitypetest">



<xsd:simpleType name="CountryEnumeratedType">

<xsd:restriction base="xsd:normalizedString">
<xsd:enumeration value="US">

</xsd:enumeration>
<xsd:enumeration value="AF">

</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>


<xsd:simpleType name="CountryContentType">
<xsd:union memberTypes=" CountryEnumeratedType" />
</xsd:simpleType>


<xsd:simpleType name="CountryCodeType">

<xsd:restriction base="CountryContentType" />
</xsd:simpleType>


<xsd:complexType name="AddressABIEType">

<xsd:sequence>
<xsd:element name="City" type="xsd:string" minOccurs="0" />
<xsd:element name="State" type="xsd:string" minOccurs="0" />
<xsd:element minOccurs="0" name="CountryID" type="CountryCodeType">
</xsd:element>
</xsd:sequence>
</xsd:complexType>


<xsd:element name="PostalAddress" type="AddressABIEType">

</xsd:element>

Thank you,

Piotr.
Re: XMLResource.OPTION_SAVE_TYPE_INFORMATION has no effect when saved as xml [message #662237 is a reply to message #662186] Tue, 29 March 2011 14:43 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25940
Registered: July 2009
Senior Member
Piotr,

Comments below.

Piotr Przybylski wrote:
> Ed, yes, I would like to get XML matching schema but it seems the
> xsi:type for that specific element is invalid:
> [Error] XSITypeTest.xml:9:110: cvc-elt.4.3: Type
> 'p:CountryEnumeratedType' is not validly derived from the type
> definition, 'CountryCodeType', of element 'p:CountryID'.
It looks to me like it is validly derived. In any case, I don't see why
it's producing an xsi:type for a simple type in the first place. I'd
expect that only if there's a SimpleAnyType involved. You constructed
this instance using the generated APIs?
>
> most likely caused by blockDefault="#all" directive.
> Here is larger fragment of the schema with the types defined:
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns="http://www.company.com/xsitypetest"
> attributeFormDefault="unqualified"
> blockDefault="#all" elementFormDefault="qualified"
> targetNamespace="http://www.company.com/xsitypetest">
>
>
>
> <xsd:simpleType name="CountryEnumeratedType">
>
> <xsd:restriction base="xsd:normalizedString">
> <xsd:enumeration value="US">
>
> </xsd:enumeration>
> <xsd:enumeration value="AF">
>
> </xsd:enumeration>
> </xsd:restriction>
> </xsd:simpleType>
>
>
> <xsd:simpleType name="CountryContentType">
> <xsd:union memberTypes=" CountryEnumeratedType" />
> </xsd:simpleType>
>
>
> <xsd:simpleType name="CountryCodeType">
>
> <xsd:restriction base="CountryContentType" />
> </xsd:simpleType>
>
>
> <xsd:complexType name="AddressABIEType">
>
> <xsd:sequence>
> <xsd:element name="City" type="xsd:string" minOccurs="0" />
> <xsd:element name="State" type="xsd:string" minOccurs="0" />
> <xsd:element minOccurs="0" name="CountryID"
> type="CountryCodeType">
> </xsd:element>
> </xsd:sequence>
> </xsd:complexType>
>
>
> <xsd:element name="PostalAddress" type="AddressABIEType">
>
> </xsd:element>
>
> Thank you,
> Piotr.
>
Re: XMLResource.OPTION_SAVE_TYPE_INFORMATION has no effect when saved as xml [message #662475 is a reply to message #662237] Wed, 30 March 2011 14:15 Go to previous messageGo to next message
Piotr Przybylski is currently offline Piotr Przybylski
Messages: 5
Registered: March 2011
Junior Member
Ed,
thank you, you are absolutely right, the xsi:type is not generated by the api, it should not be there, at least in this case.
So it really is the question about figuring out if blockDefault="#all" is in effect when the serialization happens - saveElement in the XMLSaveImpl class.

Piotr
Re: XMLResource.OPTION_SAVE_TYPE_INFORMATION has no effect when saved as xml [message #662492 is a reply to message #662475] Wed, 30 March 2011 16:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 25940
Registered: July 2009
Senior Member
Piotr,

The mapping of XSD to Ecore ignores things like block/blockDefault so
there's nothing in EMF's serialization that supports it or knows about
it for that matter.


Piotr Przybylski wrote:
> Ed, thank you, you are absolutely right, the xsi:type is not generated
> by the api, it should not be there, at least in this case. So it
> really is the question about figuring out if blockDefault="#all" is in
> effect when the serialization happens - saveElement in the XMLSaveImpl
> class.
> Piotr
Re: XMLResource.OPTION_SAVE_TYPE_INFORMATION has no effect when saved as xml [message #663407 is a reply to message #662492] Mon, 04 April 2011 17:31 Go to previous message
Piotr Przybylski is currently offline Piotr Przybylski
Messages: 5
Registered: March 2011
Junior Member
Ed,
that makes it clear, I suppose the mapping considers it irrelevant to any further processing. Thank you very much for your help.

Piotr.
Previous Topic:Filter the avaible values for a non-containment reference
Next Topic:Copying proxy objects
Goto Forum:
  


Current Time: Tue Jul 29 13:16:03 EDT 2014

Powered by FUDForum. Page generated in 0.02355 seconds