Xsd 如何禁用文档根目录的创建

Xsd 如何禁用文档根目录的创建,xsd,eclipse-emf,Xsd,Eclipse Emf,我将EMF与XSD生成的ecore一起使用。现在我有一个问题,生成的文件无效。 原因有二: 插入了DocumentRoot元素 属性的大小写错误 问题是:这不是模型的问题,而是保存过程的问题(因为在EMF生成的编辑器中,输出是正确的) 首先是正确的结果: <?xml version="1.0" encoding="UTF-8"?> <model:widgetspecification xmlns:model="http://test.com/model" Description

我将EMF与XSD生成的ecore一起使用。现在我有一个问题,生成的文件无效。 原因有二:

  • 插入了DocumentRoot元素
  • 属性的大小写错误
  • 问题是:这不是模型的问题,而是保存过程的问题(因为在EMF生成的编辑器中,输出是正确的)

    首先是正确的结果:

    <?xml version="1.0" encoding="UTF-8"?>
    <model:widgetspecification xmlns:model="http://test.com/model" Description="DESC" Name="NAME">
      <model:Property Name="PROP1"/>
      <model:Property Name="PROP2/>
    </model:widgetspecification>
    
    遗憾的是,我在保存例程中找不到任何相关的差异(当然,EMF生成的代码要复杂得多)——我想我可能错过了s.th,但我仍然没有找到任何东西)。
    同样有趣的是,EMF生成的文件是UTF-8,但我找不到设置此选项的任何引用。

    使用
    XMLResource
    而不是
    XMIResource
    ,并将
    选项扩展的元数据设置为true

    XMLResource resource = new XMLResourceImpl();
    resource.setEncoding("UTF-8");
    resource.getContents().add(modelRoot);
    Map<Object, Object> options = new HashMap<>();
    options.put(XMLResource.OPTION_EXTENDED_META_DATA, true);
    resource.save(System.out, options);
    
    XMLResource=new XMLResourceImpl();
    资源设置编码(“UTF-8”);
    resource.getContents().add(modelRoot);
    Map options=newhashmap();
    options.put(XMLResource.OPTION\u扩展\u元数据,true);
    资源保存(System.out,选项);
    
    Resource resource = new XMIResourceImpl();
    resource.getContents().add(modelRoot);
    resource.save(System.out, Collections.EMPTY_MAP);
    
    XMLResource resource = new XMLResourceImpl();
    resource.setEncoding("UTF-8");
    resource.getContents().add(modelRoot);
    Map<Object, Object> options = new HashMap<>();
    options.put(XMLResource.OPTION_EXTENDED_META_DATA, true);
    resource.save(System.out, options);