Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » XSD->Ecore->XSD and anonymous types
XSD->Ecore->XSD and anonymous types [message #519945] Wed, 10 March 2010 15:07 Go to next message
Nikita Missing name
Messages: 32
Registered: October 2009
Member
I have an XSD with an anonymous type defined under a global element:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns="http://www.example.com/test"
            targetNamespace="http://www.example.com/test">

  <xsd:element name="address-global-element">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="zip-code" type="xsd:int" nillable="true" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>


When I import this XSD using XSDEcoreBuilder and then later generate an XSD from the Ecore model using EcoreSchemaBuilder, the resulting XSD looks like this:
<xsd:schema ecore:nsPrefix="test" ecore:package="com.example.test"
  targetNamespace="http://www.example.com/test"
  xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
  xmlns:test="http://www.example.com/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:element name="address-global-element" type="test:address-global-element_._type"/>
  
  <xsd:complexType ecore:name="AddressGlobalElementType" name="address-global-element_._type">
    <xsd:sequence>
      <xsd:element ecore:name="zipCode" name="zip-code" nillable="true" type="xsd:int"/>
    </xsd:sequence>
  </xsd:complexType>
</xsd:schema>


I was wondering if there is any way to generate the XSD with the anonymous type declaration (as in the original XSD), instead of a named type with the "_._type" suffix?

Thank you,
Nikita

For reference, this is the ecore model produced by XSDEcoreBuilder:
<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="com.example.test"
    nsURI="http://www.example.com/test" nsPrefix="test">
  <eClassifiers xsi:type="ecore:EClass" name="AddressGlobalElementType">
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="name" value="address-global-element_._type"/>
      <details key="kind" value="elementOnly"/>
    </eAnnotations>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="zipCode" lowerBound="1"
        eType="ecore:EDataType http://www.eclipse.org/emf/2003/XMLType#//IntObject"
        unsettable="true">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="zip-code"/>
      </eAnnotations>
    </eStructuralFeatures>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="DocumentRoot">
    <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
      <details key="name" value=""/>
      <details key="kind" value="mixed"/>
    </eAnnotations>
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="mixed" unique="false" upperBound="-1"
        eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="elementWildcard"/>
        <details key="name" value=":mixed"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EReference" name="xMLNSPrefixMap" upperBound="-1"
        eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEntry"
        transient="true" containment="true" resolveProxies="false">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="attribute"/>
        <details key="name" value="xmlns:prefix"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EReference" name="xSISchemaLocation" upperBound="-1"
        eType="ecore:EClass http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEntry"
        transient="true" containment="true" resolveProxies="false">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="attribute"/>
        <details key="name" value="xsi:schemaLocation"/>
      </eAnnotations>
    </eStructuralFeatures>
    <eStructuralFeatures xsi:type="ecore:EReference" name="addressGlobalElement" upperBound="-2"
        eType="ecore:EClass thisResource#//AddressGlobalElementType" volatile="true"
        transient="true" derived="true" containment="true" resolveProxies="false">
      <eAnnotations source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
        <details key="kind" value="element"/>
        <details key="name" value="address-global-element"/>
        <details key="namespace" value="##targetNamespace"/>
      </eAnnotations>
    </eStructuralFeatures>
  </eClassifiers>
</ecore:EPackage>

Re: XSD->Ecore->XSD and anonymous types [message #519974 is a reply to message #519945] Wed, 10 March 2010 16:42 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26141
Registered: July 2009
Senior Member
Nikita,

Comments.


Nikita wrote:
> I have an XSD with an anonymous type defined under a global element:
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns="http://www.example.com/test"
> targetNamespace="http://www.example.com/test">
>
> <xsd:element name="address-global-element">
> <xsd:complexType>
> <xsd:sequence>
> <xsd:element name="zip-code" type="xsd:int" nillable="true" />
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
> </xsd:schema>
>
>
> When I import this XSD using XSDEcoreBuilder and then later generate
> an XSD from the Ecore model using EcoreSchemaBuilder, the resulting
> XSD looks like this:
XSD -> Ecore -> XSD is not generally a round trip while Ecore -> XSD ->
Ecore generally is.
>
>
> <xsd:schema ecore:nsPrefix="test" ecore:package="com.example.test"
> targetNamespace="http://www.example.com/test"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> xmlns:test="http://www.example.com/test"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>
> <xsd:element name="address-global-element"
> type="test:address-global-element_._type"/>
>
> <xsd:complexType ecore:name="AddressGlobalElementType"
> name="address-global-element_._type">
> <xsd:sequence>
> <xsd:element ecore:name="zipCode" name="zip-code" nillable="true"
> type="xsd:int"/>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:schema>
>
>
> I was wondering if there is any way to generate the XSD with the
> anonymous type declaration (as in the original XSD), instead of a
> named type with the "_._type" suffix?
No. If you start with a schema, it's best to just keep it around.
>
> Thank you,
> Nikita
>
> For reference, this is the ecore model produced by XSDEcoreBuilder:
>
> <ecore:EPackage xmi:version="2.0"
> xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
> name="com.example.test"
> nsURI="http://www.example.com/test" nsPrefix="test">
> <eClassifiers xsi:type="ecore:EClass" name="AddressGlobalElementType">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value="address-global-element_._type"/>
> <details key="kind" value="elementOnly"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="zipCode"
> lowerBound="1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2003/XMLType#//IntObject"
> unsettable="true">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="zip-code"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
> <eClassifiers xsi:type="ecore:EClass" name="DocumentRoot">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="name" value=""/>
> <details key="kind" value="mixed"/>
> </eAnnotations>
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="mixed"
> unique="false" upperBound="-1"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EFeatureMapEntry">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="elementWildcard"/>
> <details key="name" value=":mixed"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference"
> name="xMLNSPrefixMap" upperBound="-1"
> eType="ecore:EClass
> http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"
> transient="true" containment="true" resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="attribute"/>
> <details key="name" value="xmlns:prefix"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference"
> name="xSISchemaLocation" upperBound="-1"
> eType="ecore:EClass
> http://www.eclipse.org/emf/2002/Ecore#//EStringToStringMapEn try"
> transient="true" containment="true" resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="attribute"/>
> <details key="name" value="xsi:schemaLocation"/>
> </eAnnotations>
> </eStructuralFeatures>
> <eStructuralFeatures xsi:type="ecore:EReference"
> name="addressGlobalElement" upperBound="-2"
> eType="ecore:EClass thisResource#//AddressGlobalElementType"
> volatile="true"
> transient="true" derived="true" containment="true"
> resolveProxies="false">
> <eAnnotations
> source="http:///org/eclipse/emf/ecore/util/ExtendedMetaData">
> <details key="kind" value="element"/>
> <details key="name" value="address-global-element"/>
> <details key="namespace" value="##targetNamespace"/>
> </eAnnotations>
> </eStructuralFeatures>
> </eClassifiers>
> </ecore:EPackage>
>
>
Previous Topic:Handling of duplicate type definition from included XSD
Next Topic:XSD->Ecore->XSD and anonymous types
Goto Forum:
  


Current Time: Sun Oct 26 05:11:11 GMT 2014

Powered by FUDForum. Page generated in 0.01813 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software