Load EObject from xs:any or FeatureMap [message #1859374] |
Fri, 02 June 2023 20:39 |
Michael Relby Messages: 9 Registered: November 2013 |
Junior Member |
|
|
Hello Everyone,
I have XSD where the following complexType is defined:
<xs:complexType name="appinfo" mixed="true">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:any processContents="lax"/>
</xs:sequence>
</xs:complexType>
I also have the following XML that conforms the schema:
<root xmlns:pkga="com.example.packagea" xmlns:nsx="http://example.com/namespacex">
<appinfo>
<pkga:myClass foo="bar"/>
</appinfo>
<appinfo>
<nsx:foreignElement attr="value"/>
</appinfo>
</root>
I have model of main model package, which Root and Appinfo classes belong to, and the model of com.example.packagea package and MyClass class. There is no model for another NS with prefix "nsx".
Generated Appinfo class's content is defined as FeatureMap. I understand why (because of xs:any), but I'm wondering if there is any alternative approach, which allows me to somehow load MyClass from one of those Appinfos, if I have registered the package com.example.packagea. Can you please advise? So that I can write something like MyClass myObj = (MyClass) appinfo.getContent().get(0);
Another requirement is that any other unknown namespaces like "nsx" in the example, should behave like now, i.e. loaded into FeatureMaps.
What I'm using now is that I traverse the FeatureMap, detecting content namespace, finding corresponding EPackage and EClass, creating the instance and populating the features one by one. It works for simple things like foo="bar" attribute, but I want to be able to load more complex objects.
If only I can take <appinfo> content like XML string or DOM model, and load EMF Resource from it, but I was unable to find a way to do it. Or maybe there is some existing utility which can create EObject from the FeatureMap?
Do you have any idea on how to solve this task? Thanks in advance!
|
|
|
|
Re: Load EObject from xs:any or FeatureMap [message #1859397 is a reply to message #1859378] |
Mon, 05 June 2023 10:37 |
Michael Relby Messages: 9 Registered: November 2013 |
Junior Member |
|
|
Hello Ed,
Thank you for the answer!
UPD. Solved, please see my next post below.
It's still unclear to me what exactly should work in that case. I did as you suggested, created DocumentRoot EClass in "pkga" model and configured as needed. But I still have no API in Appinfo class to get arbitrary EObject, only the FeatureMap which still contain just EReference of type EObject, named "myClass" and having value of AnyType, not MyClass.
Should XML resource loader from EMF care about registered EPackages when it loads the elements which are xs:any according to the schema?
And another question, do I have to have XSD and Genmodel for "pkga" model, or ecore with extended metadata should be enough?
[Updated on: Mon, 05 June 2023 12:07] Report message to a moderator
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03652 seconds