Home

Avoid name collision in Ecore generated from XSD

This memo shows how to avoid name collision in Ecore generated from XSD

If you are confronted with the following log warning message you are facing a name collision in an Ecore generated from a XSD.

WARN  OawXSDEcoreBuilder - Name Conflict: Created EAttribute
'group1', EAttribute 'group' is in the way.
Container1:/EPackage'example'/EClass'Frucht',
Container2:/EPackage'example'/EClass'Apfel'

As the XSD choice tag has no name attribute the org.eclipse.xsd.ecore.XSDEcoreBuilder will set the corresponding EAttribute name to 'group' by default. Well this happens when the choice tag also has the attribute maxOccurs="unbounded".

The following code snippet will reproduce such a log warning message.

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
  xmlns:example="http://www.example.com/blah"
  targetNamespace="http://www.example.com/blah">

  <complexType name="Frucht">
    <choice maxOccurs="unbounded">
      <element name="a" type="string"/>
    </choice>
  </complexType>

  <complexType name="Apfel">
    <complexContent>
      <extension base="example:Frucht">
        <choice maxOccurs="unbounded">
          <element name="b" type="string"/>
        </choice>
      </extension>
    </complexContent>
  </complexType>
</schema>

To prevent this collision one can add the Ecore namespace to the XSD file and add a name attribute to the choice tag.

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
  xmlns:example="http://www.example.com/blah"
  targetNamespace="http://www.example.com/blah"
  xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore">

  <complexType name="Frucht">
    <choice maxOccurs="unbounded">
      <element name="a" type="string"/>
    </choice>
  </complexType>

  <complexType name="Apfel">
    <complexContent>
      <extension base="example:Frucht">
        <choice maxOccurs="unbounded" ecore:name="apfelChoice">
          <element name="b" type="string"/>
        </choice>
      </extension>
    </complexContent>
  </complexType>
</schema>

With the additional ecore:name attribute the corresponding EAttribute won't receive the name group anymore and there is no conflict.

References


Date published:
Date modified: 2013-01-16
Keywords: Modeling, Ecore, OawXSDEcoreBuilder, XSD