XML Binding to EMF [message #1751144] |
Wed, 04 January 2017 17:30  |
Eclipse User |
|
|
|
I am trying to create an .ecore file based on maven pom.xsd in order to generate maven pom.xml using M2M tools (QVTo). The issue I currently encounter is around properties. Basically, pom allows to specify user defined properties as:
....
<properties>
<name1.version>2.3.7</name1.version>
<name2.version>2.3.7</name2.version>
.....
</properties>
....
Obviously, the name of property will not be defined in XSD as POM allows you to define any property with random name at design time.
XSD Fragment for this:
<xs:element minOccurs="0" name="properties">
<xs:complexType>
<xs:sequence>
<xs:any minOccurs="0" maxOccurs="unbounded" processContents="skip"/>
</xs:sequence>
</xs:complexType>
</xs:element>
And corresponding .ecore generated based on this pom.xsd will create an EClass "PropertiesType" with an EAttribute "any" as EFeatureMapEntry / ExtendedMetaData: kind="elementWildcard", wildcards="##any", name=":0", processing="skip".
To add a new property, I have defined an operation named addInlineProperty(String name, String value) with following implementation:
-- code starts --
public void addInlineProperty(String name, String value) {
final ExtendedMetaData extendedMetaData =
new BasicExtendedMetaData( this.eResource().getResourceSet().getPackageRegistry() );
EStructuralFeature feature = extendedMetaData.demandFeature(mpom4Package.eNS_URI, name, true);
EClass propertyClass = feature. getEContainingClass();
EObject propertyObject = EcoreUtil.create(propertyClass);
FeatureMapUtil.addText(((XMLTypeDocumentRoot)propertyObject).getMixed(),value);
getAny().add(feature, propertyObject);
}
This will all the new property with the name of my choice but the property element gets an @xsi:type attribute as follows:
<?xml version="1.0" encoding="UTF-8"?>
<mpom4:project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mpom4="http://maven.apache.org/myPOM/4.0.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<mpom4:properties>
<mpom4:xyz xsi:type="mpom4">122</mpom4:xyz>
</mpom4:properties>
</mpom4:project>
@xsi:type value is the same as the NS_PREFIX of the EPackage I used to demand an EStructuralFeature which is not correct. I would like to either set the proper xsi:type to xsd:string or find a way to ignore at all xsi:type during serialization. I really appreciate any tips. Thanks, Ioan
|
|
|
|
|
|
|
Re: XML Binding to EMF [message #1751217 is a reply to message #1751211] |
Thu, 05 January 2017 13:27  |
Eclipse User |
|
|
|
Do you see that for your schema-based model there is a generated resource factory? That is where the necessary options are set; changing the base class for your resource implementation isn't likely to help, and if your factory isn't used in the first place, it will of course have no impact. You should ensure that your factory is the one being used to create the resource. And note, that given the file extension is "xml", it's unlikely that you can just globally register your factory against that extension without conflict.
|
|
|
Powered by
FUDForum. Page generated in 0.05863 seconds