【问题标题】:How to map xs:any in EMF Ecore?如何在 EMF Ecore 中映射 xs:any?
【发布时间】:2016-02-08 14:05:01
【问题描述】:

我在 xsd 中有以下类型:

<xs:complexType name="VendorSpecificType">
    <xs:sequence>
        <xs:any namespace="##any" processContents="skip" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

我在 Ecore 中创建了这种类型:


我尝试注入一个包含以下标签的 xml:

<VendorSpecific>
    <Vendor ID="1"/>
</VendorSpecific>

但它崩溃了

org.eclipse.m2m.atl.core.ATLCoreException: Error loading test.xml: org.eclipse.emf.ecore.xmi.FeatureNotFoundException: Feature 'Vendor' not found.

用于在元模型中注入模型的代码已经过测试并且可以正常工作。 如果我删除 Vendor 标记,即使这个 test.xml 也会正确加载。

我的问题是如何将 xsd any 映射到 ecore 类型以便可以加载它?

更新:

经过调试,我用来将模型注入ecore模型的代码似乎不完整:extendedmetadata总是为null

// Load in metamodel
IReferenceModel metamodel = modelFactory.newReferenceModel();
injector.inject(metamodel, metamodelPath);

model = modelFactory.newModel(metamodel);
injector.inject(model, modelPath);

如何告诉它加载元数据?

【问题讨论】:

    标签: xsd eclipse-emf-ecore


    【解决方案1】:

    我添加了以下行

    ((EMFModelFactory) modelFactory).getResourceSet().getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
    

    在注入元模型之前。

    现在可以了!

    【讨论】:

      猜你喜欢
      • 2021-12-18
      • 1970-01-01
      • 2010-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-05
      相关资源
      最近更新 更多