Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Howto use xsd2Ecore so that the xmi-files can be validated with xsd?
Howto use xsd2Ecore so that the xmi-files can be validated with xsd? [message #743162] Fri, 21 October 2011 07:25 Go to next message
Daniel Engelhardt is currently offline Daniel EngelhardtFriend
Messages: 11
Registered: November 2010
Junior Member
Hello,

I have got a problem with my Ecore meta models. I created two Ecore meta models from two xsd files describing different namespaces in XML (let's say AAA and BBB). These xsd files reference each other (or: on references elements of the other) and so do these two ecore files.

Now, I want to create an xmi file (using "Create dynamic instance" for example) which is supposed to look like this:
<?xml version="1.0" encoding="ASCII"?>
<aaa:DocumentRoot xmi:version="2.0" xmlns:xmi="http:SLASHSLASHwww.omg.org/XMI" xmlns:xsi="http:SLASHSLASHwww.w3.org/2001/XMLSchema-instance" xmlns:aaa="http:SLASHSLASHwww.aaa.org/aaa" xsi:schemaLocation="http:SLASHSLASHwww.aaa.org/aaa aaa.ecore">
  <node>
    <bbb:somethingFromBBB>xx</somethingFromBBB>
  </node>
</aaa:DocumentRoot>

Notice, that there is a namespace qualifier given for elements from the other Ecore model BBB (or xsd file).

I want this, because this xmi file to be compatible to the xsd files I initially started with. And I want to validate the xmi file.

But this is not what I get, instead I get
<?xml version="1.0" encoding="ASCII"?>
<aaa:DocumentRoot xmi:version="2.0" xmlns:xmi="http:SLASHSLASHwww.omg.org/XMI" xmlns:xsi="http:SLASHSLASHwww.w3.org/2001/XMLSchema-instance" xmlns:aaa="http:SLASHSLASHwww.aaa.org/aaa" xsi:schemaLocation="http:SLASHSLASHwww.aaa.org/aaa aaa.ecore">
  <node>
    <somethingFromBBB>xx</somethingFromBBB>
  </node>
</aaa:DocumentRoot>


The xsd files look like
aaa.xsd:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns:xs="http:SLASHSLASHwww.w3.org/2001/XMLSchema"
	targetNamespace="http:SLASHSLASHwww.aaa.org/aaa"
	xmlns:aaa="http:SLASHSLASHwww.aaa.org/aaa"
	xmlns:bbb="http:SLASHSLASHwww.bbb.org/bbb">
		
	<xs:import namespace="http:SLASHSLASHwww.bbb.org/bbb"/>

 <xs:element name="node">
  <xs:complexType>
   <xs:choice minOccurs="0" maxOccurs="unbounded">
    <xs:element ref="bbb:something_from_BBB" />
   </xs:choice>
   </xs:complexType>
</xs:element>

 
</xs:schema>


bbb.xsd:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns:bbb="http:SLASHSLASHwww.bbb.org/bbb" xmlns:xsd="http:SLASHSLASHwww.w3.org/2001/XMLSchema"
	xmlns:aaa="http:SLASHSLASHwww.aaa.org/aaa"
	targetNamespace="http:SLASHSLASHwww.bbb.org/bbb"
	elementFormDefault="qualified"
  	attributeFormDefault="unqualified">
  		
<xsd:import schemaLocation="aaa.xsd" namespace="http://www.aaa.org/aaa"/>
  		
<xsd:element name="something_from_BBB" type="xsd:string"/>
	
</xsd:schema>



The options used for saving and loading are:
		result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
		result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);

		result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);

		result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
		result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);

		result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);


What am I doing wrong? What is the right way? Is this behaviour even possible? Am I totally on the wrong track?


Thank you very much for an answer!

Best regards,
Daniel
Re: Howto use xsd2Ecore so that the xmi-files can be validated with xsd? [message #743186 is a reply to message #743162] Fri, 21 October 2011 07:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Daniel,

Comments below.

On 21/10/2011 9:25 AM, daniel.engelhardt wrote:
> Hello,
>
> I have got a problem with my Ecore meta models. I created two Ecore
> meta models from two xsd files describing different namespaces in XML
> (let's say AAA and BBB). These xsd files reference each other (or: on
> references elements of the other) and so do these two ecore files.
>
> Now, I want to create an xmi file (using "Create dynamic instance" for
> example) which is supposed to look like this:
>
> <?xml version="1.0" encoding="ASCII"?>
> <aaa:DocumentRoot xmi:version="2.0"
> xmlns:xmi="http:SLASHSLASHwww.omg.org/XMI"
> xmlns:xsi="http:SLASHSLASHwww.w3.org/2001/XMLSchema-instance"
> xmlns:aaa="http:SLASHSLASHwww.aaa.org/aaa"
> xsi:schemaLocation="http:SLASHSLASHwww.aaa.org/aaa aaa.ecore">
> <node>
> <bbb:somethingFromBBB>xx</somethingFromBBB>
> </node>
> </aaa:DocumentRoot>
>
> Notice, that there is a namespace qualifier given for elements from
> the other Ecore model BBB (or xsd file).
Without an xmlns for bbb?
>
> I want this, because this xmi file to be compatible to the xsd files I
> initially started with.
XMI serializations won't be compatible with the XSD. You need to use
the generated resource factory to create resources that do the proper
XML serialization. That's not supported for dynamic models.
> And I want to validate the xmi file.
>
> But this is not what I get, instead I get
>
> <?xml version="1.0" encoding="ASCII"?>
> <aaa:DocumentRoot xmi:version="2.0"
> xmlns:xmi="http:SLASHSLASHwww.omg.org/XMI"
> xmlns:xsi="http:SLASHSLASHwww.w3.org/2001/XMLSchema-instance"
> xmlns:aaa="http:SLASHSLASHwww.aaa.org/aaa"
> xsi:schemaLocation="http:SLASHSLASHwww.aaa.org/aaa aaa.ecore">
> <node>
> <somethingFromBBB>xx</somethingFromBBB>
> </node>
> </aaa:DocumentRoot>
Yes, I'd expect that from an XMI serialization.
>
>
> The xsd files look like
> aaa.xsd:
>
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <xs:schema xmlns:xs="http:SLASHSLASHwww.w3.org/2001/XMLSchema"
> targetNamespace="http:SLASHSLASHwww.aaa.org/aaa"
> xmlns:aaa="http:SLASHSLASHwww.aaa.org/aaa"
> xmlns:bbb="http:SLASHSLASHwww.bbb.org/bbb">
>
> <xs:import namespace="http:SLASHSLASHwww.bbb.org/bbb"/>
>
> <xs:element name="node">
> <xs:complexType>
> <xs:choice minOccurs="0" maxOccurs="unbounded">
> <xs:element ref="bbb:something_from_BBB" />
> </xs:choice>
> </xs:complexType>
> </xs:element>
>
>
> </xs:schema>
>
>
> bbb.xsd:
>
> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
> <xsd:schema xmlns:bbb="http:SLASHSLASHwww.bbb.org/bbb"
> xmlns:xsd="http:SLASHSLASHwww.w3.org/2001/XMLSchema"
> xmlns:aaa="http:SLASHSLASHwww.aaa.org/aaa"
> targetNamespace="http:SLASHSLASHwww.bbb.org/bbb"
> elementFormDefault="qualified"
> attributeFormDefault="unqualified">
>
> <xsd:import schemaLocation="aaa.xsd" namespace="http://www.aaa.org/aaa"/>
>
> <xsd:element name="something_from_BBB" type="xsd:string"/>
>
> </xsd:schema>
>
>
>
> The options used for saving and loading are:
>
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA,
> Boolean.TRUE);
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA,
> Boolean.TRUE);
>
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION,
> Boolean.TRUE);
>
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE,
> Boolean.TRUE);
>
> result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE,
> Boolean.TRUE);
>
>
> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER,
> Boolean.TRUE);
>
>
> What am I doing wrong?
You mentioned creating a dynamic instance. That doesn't use generated
code at all.
> What is the right way? Is this behaviour even possible? Am I totally
> on the wrong track?
If you use the generated resource factory to create the resource it
should work a lot better...
>
>
> Thank you very much for an answer!
>
> Best regards,
> Daniel


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Howto use xsd2Ecore so that the xmi-files can be validated with xsd? [message #743191 is a reply to message #743186] Fri, 21 October 2011 07:57 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Daniel,

Note that my comment about what's not supported for dynamic models
should really say that's not supported when creating dynamic instances
using the Ecore editor. It is supported for dynamic models, you but
it's clear you're using an XMIResourceImpl not an XMLResourceImpl for
the serialization to get what you've shown...

On 21/10/2011 9:54 AM, Ed Merks wrote:
> Daniel,
>
> Comments below.
>
> On 21/10/2011 9:25 AM, daniel.engelhardt wrote:
>> Hello,
>>
>> I have got a problem with my Ecore meta models. I created two Ecore
>> meta models from two xsd files describing different namespaces in XML
>> (let's say AAA and BBB). These xsd files reference each other (or: on
>> references elements of the other) and so do these two ecore files.
>>
>> Now, I want to create an xmi file (using "Create dynamic instance"
>> for example) which is supposed to look like this:
>>
>> <?xml version="1.0" encoding="ASCII"?>
>> <aaa:DocumentRoot xmi:version="2.0"
>> xmlns:xmi="http:SLASHSLASHwww.omg.org/XMI"
>> xmlns:xsi="http:SLASHSLASHwww.w3.org/2001/XMLSchema-instance"
>> xmlns:aaa="http:SLASHSLASHwww.aaa.org/aaa"
>> xsi:schemaLocation="http:SLASHSLASHwww.aaa.org/aaa aaa.ecore">
>> <node>
>> <bbb:somethingFromBBB>xx</somethingFromBBB>
>> </node>
>> </aaa:DocumentRoot>
>>
>> Notice, that there is a namespace qualifier given for elements from
>> the other Ecore model BBB (or xsd file).
> Without an xmlns for bbb?
>>
>> I want this, because this xmi file to be compatible to the xsd files
>> I initially started with.
> XMI serializations won't be compatible with the XSD. You need to use
> the generated resource factory to create resources that do the proper
> XML serialization. That's not supported for dynamic models.
>> And I want to validate the xmi file.
>>
>> But this is not what I get, instead I get
>>
>> <?xml version="1.0" encoding="ASCII"?>
>> <aaa:DocumentRoot xmi:version="2.0"
>> xmlns:xmi="http:SLASHSLASHwww.omg.org/XMI"
>> xmlns:xsi="http:SLASHSLASHwww.w3.org/2001/XMLSchema-instance"
>> xmlns:aaa="http:SLASHSLASHwww.aaa.org/aaa"
>> xsi:schemaLocation="http:SLASHSLASHwww.aaa.org/aaa aaa.ecore">
>> <node>
>> <somethingFromBBB>xx</somethingFromBBB>
>> </node>
>> </aaa:DocumentRoot>
> Yes, I'd expect that from an XMI serialization.
>>
>>
>> The xsd files look like
>> aaa.xsd:
>>
>> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
>> <xs:schema xmlns:xs="http:SLASHSLASHwww.w3.org/2001/XMLSchema"
>> targetNamespace="http:SLASHSLASHwww.aaa.org/aaa"
>> xmlns:aaa="http:SLASHSLASHwww.aaa.org/aaa"
>> xmlns:bbb="http:SLASHSLASHwww.bbb.org/bbb">
>>
>> <xs:import namespace="http:SLASHSLASHwww.bbb.org/bbb"/>
>>
>> <xs:element name="node">
>> <xs:complexType>
>> <xs:choice minOccurs="0" maxOccurs="unbounded">
>> <xs:element ref="bbb:something_from_BBB" />
>> </xs:choice>
>> </xs:complexType>
>> </xs:element>
>>
>>
>> </xs:schema>
>>
>>
>> bbb.xsd:
>>
>> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
>> <xsd:schema xmlns:bbb="http:SLASHSLASHwww.bbb.org/bbb"
>> xmlns:xsd="http:SLASHSLASHwww.w3.org/2001/XMLSchema"
>> xmlns:aaa="http:SLASHSLASHwww.aaa.org/aaa"
>> targetNamespace="http:SLASHSLASHwww.bbb.org/bbb"
>> elementFormDefault="qualified"
>> attributeFormDefault="unqualified">
>>
>> <xsd:import schemaLocation="aaa.xsd"
>> namespace="http://www.aaa.org/aaa"/>
>>
>> <xsd:element name="something_from_BBB" type="xsd:string"/>
>>
>> </xsd:schema>
>>
>>
>>
>> The options used for saving and loading are:
>>
>>
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA,
>> Boolean.TRUE);
>>
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA,
>> Boolean.TRUE);
>>
>>
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
>>
>>
>>
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE,
>> Boolean.TRUE);
>>
>> result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE,
>> Boolean.TRUE);
>>
>>
>> result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER,
>> Boolean.TRUE);
>>
>>
>> What am I doing wrong?
> You mentioned creating a dynamic instance. That doesn't use generated
> code at all.
>> What is the right way? Is this behaviour even possible? Am I totally
>> on the wrong track?
> If you use the generated resource factory to create the resource it
> should work a lot better...
>>
>>
>> Thank you very much for an answer!
>>
>> Best regards,
>> Daniel


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[EEF] How to programmatically display a View?
Next Topic:[Texo] ORM.xml generation for bi-directional refs
Goto Forum:
  


Current Time: Thu Mar 28 13:33:23 GMT 2024

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

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

Back to the top