Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » XSD & Xpand (for xmt2test)(How to combine XSD with Xpand)
icon5.gif  XSD & Xpand (for xmt2test) [message #494539] Sat, 31 October 2009 09:42 Go to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hi,

I found a tutorial for XSD and Xpand for oAW 4.3.1. This is exactly what I want to do. But how can I do with the current version integrated in eclipse Galileo?

When I create a Xpand project I do not have the XSD option.

Please help me. This tool combination would be sooo cool.

br,
Marco
Re: XSD & Xpand (for xmt2test) [message #494558 is a reply to message #494539] Sat, 31 October 2009 12:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hello Marco,

there is no problem to create a xml 2 text project using the XSD Adaptor that moved from oAW to Eclipse too.

Here are the Steps you have to do:



  1. Creste a New Xpand Project
  2. Go to your projects Properties and select XSD Metamodels in the Xtend/Xpand Section
  3. place your XSD and XML File somewhere in a Source Folder
  4. Create your workflow (adjust the one from oAW 4.3.1 to the new Classes. The result might look like this
    
    	
    <workflow>
    	<!-- load the file -->
    	<component class="org.eclipse.xtend.typesystem.xsd.XMLReader">
    		<modelSlot value="model" />
    		<uri value="model/mysetup.xml" />
    		<metaModel id="mm"
    			class="org.eclipse.xtend.typesystem.xsd.XSDMetaModel">
    		</metaModel>
    	</component>
    
    	<!-- clean up the target directory -->
    	<component
    		class="org.eclipse.emf.mwe.utils.DirectoryCleaner">
    		<directory value="src-gen/mypackage" />
    	</component>
    
    	<!-- generate some code -->
    	<component class="org.eclipse.xpand2.Generator">
    		<metaModel idRef="mm" />
    		<expand value="templates::wizard::Root FOR model" />
    		<outlet path="src-gen" />
    		<beautifier
    			class="org.eclipse.xpand2.output.JavaBeautifier" />
    	</component>
    
    </workflow>
    
    

  5. adjust your projects dependencies
  6. run the workflow



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XSD & Xpand (for xmt2test) [message #494582 is a reply to message #494558] Sat, 31 October 2009 17:42 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hi Christian,

Thanks for your help.

Still I don't know how to match my template with the names of the workflow and the model.

I start with this template:
«IMPORT metamodel»

«DEFINE Root FOR breakdownXml::BreakdownXmlDocumentRoot»
«FILE "breakdown.xxx"-»
«this.toString()»
BREAKDOWN:
«ENDFILE»
«ENDDEFINE»

and get this error from the workflow:

SEVERE: Error in Component of type org.eclipse.xpand2.Generator:
EvaluationException : No Definition 'template::Template::Root for type::AnyType' found!
[23,41] on line 1 'EXPAND template::Template::Root FOR model'

As you might see I am a complete beginner with XPand and EMF. So please do not hesitate to mention basics.

Pease help me further.

br,
m
Re: XSD & Xpand (for xmt2test) [message #494589 is a reply to message #494582] Sat, 31 October 2009 18:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
could you please post your workflow / xsd / xml and folder structure.
and check if you use inhertiance in your metamodel - then you have to place the definition for the subtypes as well as for the supertype to match xpands polymorphim requirements


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 31 October 2009 18:32]

Report message to a moderator

Re: XSD & Xpand (for xmt2test) [message #494590 is a reply to message #494539] Sat, 31 October 2009 18:59 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
src
_model.xml
_metamodel.xsd
_wf.mwe
_template
__Template.xpt

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="Breakdown"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Breakdown">
<xs:complexType>
<xs:sequence>
<xs:element ref="DictDetail_Name"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="DictDetail_Name">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:NCName">
<xs:attribute name="Type" use="required" type="xs:NCName"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>

<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<Breakdown>
<DictDetail_Name Type="String">abc</DictDetail_Name>
</Breakdown>
</root>

<workflow>
<!-- load the file -->
<component class="org.eclipse.xtend.typesystem.xsd.XMLReader">
<modelSlot value="model" />
<uri value="model.xml" />
<metaModel id="mm"
class="org.eclipse.xtend.typesystem.xsd.XSDMetaModel">
</metaModel>
</component>

<!-- clean up the target directory -->
<component
class="org.eclipse.emf.mwe.utils.DirectoryCleaner">
<directory value="src-gen/mypackage" />
</component>

<!-- generate some code -->
<component class="org.eclipse.xpand2.Generator">
<metaModel idRef="mm" />
<expand value="template::Template::Root FOR model" />
<outlet path="src-gen" />
<beautifier
class="org.eclipse.xpand2.output.JavaBeautifier" />
</component>

</workflow>

«IMPORT metamodel»

«DEFINE Root FOR breakdownXml::BreakdownXmlDocumentRoot»
«FILE "breakdown.stm"-»
«this.toString()»
BREAKDOWN:
«ENDFILE»
«ENDDEFINE»
Re: XSD & Xpand (for xmt2test) [message #494591 is a reply to message #494590] Sat, 31 October 2009 19:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
your root element is a named root that has an anonymous complex type. these types are mapped to the EClass [[elementName]]Type. so in your case the root Element is of type metamodel::RootType and your template should looklike this

«IMPORT metamodel»

«DEFINE Root FOR RootType»
«FILE "breakdown.stm"-»
«this.toString()»
BREAKDOWN:
«ENDFILE»
«ENDDEFINE»


fore more information how xsd constructs are mapped to ecore construct have a look at http:// www.eclipse.org/modeling/emf/docs/overviews/XMLSchemaToEcore Mapping.pdf


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XSD & Xpand (for xmt2test) [message #494592 is a reply to message #494591] Sat, 31 October 2009 19:34 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
The result has not changed.

So still
'template::Template::Root for type::AnyType'
does not match
«DEFINE Root FOR metamodel::RootType» (also tried just RootType)

/m
Re: XSD & Xpand (for xmt2test) [message #494595 is a reply to message #494592] Sat, 31 October 2009 20:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
yes the other thing is that you xml should use xsd / refer to xsd
therefore the xsd should look like this

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns="http://www.example.org/test" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/test">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" ref="Breakdown"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Breakdown">
<xs:complexType>
<xs:sequence>
<xs:element ref="DictDetail_Name"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="DictDetail_Name">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:NCName">
<xs:attribute name="Type" type="xs:NCName" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:schema>



and the xml like this

<?xml version="1.0" encoding="ISO-8859-1"?>
<root xmlns="http://www.example.org/test"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.example.org/test metamodel.xsd ">
<Breakdown>
<DictDetail_Name Type="String">abc</DictDetail_Name>
</Breakdown>
</root>


or try the other possibilities described at http:// help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.xpand. doc/help/ch04s05.html


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XSD & Xpand (for xmt2test) [message #494597 is a reply to message #494539] Sat, 31 October 2009 21:24 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Thanks again for the suggestion.

I tried it all, except the import variant, but the result is still the same.

There is no message about a missing xsd.

Any more ideas?

br,
m
Re: XSD & Xpand (for xmt2test) [message #494599 is a reply to message #494539] Sat, 31 October 2009 21:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
could you please share a sample project, i tried your template and workflow with the xsd and xml i shared and it work wonderful
(see attachment)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 31 October 2009 21:56]

Report message to a moderator

Re: XSD & Xpand (for xmt2test) [message #494605 is a reply to message #494539] Sun, 01 November 2009 00:40 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hope the attached project archive helps to identify the problem.

br,
m

[Updated on: Sun, 01 November 2009 00:44]

Report message to a moderator

Re: XSD & Xpand (for xmt2test) [message #494606 is a reply to message #494605] Sun, 01 November 2009 00:46 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
The upload does not work despite the archive is smaller than 2MB.

How can I send you?

/m
Re: XSD & Xpand (for xmt2test) [message #494624 is a reply to message #494606] Sun, 01 November 2009 11:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
try something like drop.io

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XSD & Xpand (for xmt2test) [message #494625 is a reply to message #494624] Sun, 01 November 2009 11:37 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hi Christian,

Thx for another useful hint.

http://drop.io/0shwh6u

http://drop.io/0shwh6u

br
m
Re: XSD & Xpand (for xmt2test) [message #494628 is a reply to message #494625] Sun, 01 November 2009 11:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
hi, of course you have to class the right template from your workflow. in your case this might look like this

<component class="org.eclipse.xpand2.Generator">
		<metaModel idRef="mm" />
		<expand value="template::Template::Root FOR model" />
		<outlet path="src-gen" />
		<beautifier
			class="org.eclipse.xpand2.output.JavaBeautifier" />
	</component>


and you have to add some additional dependency

  • com.ibm.icu





Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: XSD & Xpand (for xmt2test) [message #494648 is a reply to message #494628] Sun, 01 November 2009 17:55 Go to previous messageGo to next message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hi Christian,

Thank you for finding the problem, and proofing my blindness Wink

br
m
Re: XSD & Xpand (for xmt2test) [message #498087 is a reply to message #494539] Sat, 14 November 2009 11:39 Go to previous message
Marco  is currently offline Marco Friend
Messages: 216
Registered: August 2009
Senior Member
Hi Christian,

Would you please help me another time with a maybe similar problem. -> Thread: http://www.eclipse.org/forums/index.php?t=msg&goto=49808 4&

br
Marco
Previous Topic:How to escape "<",">" in jet2?
Next Topic:XSD adapter and imports
Goto Forum:
  


Current Time: Tue Apr 16 18:42:30 GMT 2024

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

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

Back to the top