Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » XML2XML
XML2XML [message #1059470] Sun, 19 May 2013 10:23 Go to next message
samar sousou is currently offline samar sousouFriend
Messages: 63
Registered: March 2013
Member
Hi every body,
I have a problem when i want to transform an XML to another XML in ATL.
When i want to translate a root vers the other root, i have this error "Cannot set feature children to value [org.eclipse.emf.ecore.impl.DynamicEObjectImpl@106c28e (eClass: org.eclipse.emf.ecore.impl.EClassImpl@45a13b (name: Attribute) (instanceClassName: null) (abstract: false, interface: false)), org.eclipse.emf.ecore.impl.DynamicEObjectImpl@22610b (eClass: org.eclipse.emf.ecore.impl.EClassImpl@15c4245 (name: Text) (instanceClassName: null) (abstract: false, interface: false)), org.eclipse.emf.ecore.impl.DynamicEObjectImpl@cf16e8 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@e25e24 (name: Element) (instanceClassName: null) (abstract: false, interface: false)), org.eclipse.emf.ecore.impl.DynamicEObjectImpl@1112380 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@15c4245 (name: Text) (instanceClassName: null) (abstract: false, interface: false)), org.eclipse.emf.ecore.impl.DynamicEObjectImpl@122d2ad (eClass: org.eclipse.emf.ecore.impl.EClassImpl@e25e24 (name: Element) (instanceClassName: null) (abstract: false, interface: false)), org.eclipse.emf.ecore.impl.DynamicEObjectImpl@31d83c (eClass: org.eclipse.emf.ecore.impl.EClassImpl@15c4245 (name: Text) (instanceClassName: null) (abstract: false, interface: false)), org.eclipse.emf.ecore.impl.DynamicEObjectImpl@1a71ca6 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@e25e24 (name: Element) (instanceClassName: null) (abstract: false, interface: false)), org.eclipse.emf.ecore.impl.DynamicEObjectImpl@6b5372 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@15c4245 (name: Text) (instanceClassName: null) (abstract: false, interface: false))], inter-model references are forbidden. Configure launching options to allow them."

I didn't understand this error.

So, i need your help and this is my Root rule.
rule ROOT {
from
i : XMLS!Root
to
o: XMLC!Root (
name <- 'donneesMUDU',
startLine <- i.startLine,
startColumn <- i.startColumn,
endLine <- i.endLine,
endColumn <- i.endColumn,
children <- i.children

)
}
what should i do!

Thank you,
Samar
Re: XML2XML [message #1059554 is a reply to message #1059470] Mon, 20 May 2013 12:37 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

The error message says "inter-model references are forbidden. Configure launching options to allow them".
You should try to set the corresponding option to yes in your launch configuration and then run your transformation again.
Maybe this could solve your problem.


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: XML2XML [message #1059576 is a reply to message #1059554] Mon, 20 May 2013 14:45 Go to previous messageGo to next message
samar sousou is currently offline samar sousouFriend
Messages: 63
Registered: March 2013
Member
Thanks,
but when i execute this is the result:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="/projet2/metamodele/XML.xml">
<Root startLine="1" startColumn="1" endLine="11687" endColumn="13" name="donnees"/>
<Element name="OccurrenceDeComposant">
<children xsi:type="Attribute" name="typeComposant" value="F"/>
<children xsi:type="Attribute" name="repere" value="054"/>
<children xsi:type="Attribute" name="uid" value="83678fd1a6ab"/>
</Element>
.....
the root is not for all the element.

So how can i do to have the root containes all the element.


Thank you,
Samar
Re: XML2XML [message #1059696 is a reply to message #1059576] Tue, 21 May 2013 09:04 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

You first have to ensure that, in your XML.ecore file (i.e. your XML metamodel), the "children" reference is actually a containment one.
Then, this can also depends on your input model (is it correct?) and on the other rules in your transformation.


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: XML2XML [message #1059724 is a reply to message #1059696] Tue, 21 May 2013 11:37 Go to previous messageGo to next message
samar sousou is currently offline samar sousouFriend
Messages: 63
Registered: March 2013
Member
Hi,
After the XML2XML transformation ,I have as a result an xmi like this :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="XML">
<Root name="m">
<children xsi:type="Element" name="composant">
<children xsi:type="Attribute" name="typeComposant" value="F"/>
<children xsi:type="Attribute" name="r" value="015"/>
<children xsi:type="Attribute" name="uidComposant" value="1235"/>
</children>
</Root>
<Root name="m">
<children xsi:type="Element" name="composant">
<children xsi:type="Attribute" name="typeComposant" value="b"/>
<children xsi:type="Attribute" name="r" value="157"/>
<children xsi:type="Attribute" name="uidComposant" value="8320"/>
</children>
</Root>
<Root name="m">
<children xsi:type="Element" name="composant">
<children xsi:type="Attribute" name="typeComposant" value="b"/>
<children xsi:type="Attribute" name="r" value="1546"/>
<children xsi:type="Attribute" name="uidComposant" value="5990"/>
</children>
</Root>......

but i want it as a model xml like this
<?xml version="1.0" encoding="ISO-8859-1"?>
<Root xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="XML" name="m">
<children xsi:type="Element" name="composant">
<children xsi:type="Attribute" name="typeComposant" value="F"/>
<children xsi:type="Attribute" name="r" value="015"/>
<children xsi:type="Attribute" name="uidComposant" value="1235"/>
</children>
<children xsi:type="Element" name="composant">
<children xsi:type="Attribute" name="typeComposant" value="b"/>
<children xsi:type="Attribute" name="r" value="157"/>
<children xsi:type="Attribute" name="uidComposant" value="8320"/>
</children>
<children xsi:type="Element" name="composant">
<children xsi:type="Attribute" name="typeComposant" value="b"/>
<children xsi:type="Attribute" name="r" value="1546"/>
<children xsi:type="Attribute" name="uidComposant" value="5990"/>
</children>
...
</Root>

So how can i do!!

I need your help,
thank you,
Samar.
Re: XML2XML [message #1059748 is a reply to message #1059724] Tue, 21 May 2013 13:57 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Have you checked your input model as I told you before?
If you obtain such an output model according to your described transformation rule (which is basically a simple "Root element copy" rule), this means that you also have the same several Root elements in your input model.


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: XML2XML [message #1059767 is a reply to message #1059748] Tue, 21 May 2013 14:37 Go to previous messageGo to next message
samar sousou is currently offline samar sousouFriend
Messages: 63
Registered: March 2013
Member
my input is :
<?xml version="1.0" encoding="ISO-8859-1"?>
<Root xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="/projet2/metamodele/XML.xml" startLine="1" startColumn="1" endLine="11687" endColumn="13" name="x">
<children xsi:type="Text" startLine="2" startColumn="12" endLine="3" endColumn="4" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="3" startColumn="4" endLine="7" endColumn="10" name="h">
<children xsi:type="Text" startLine="3" startColumn="9" endLine="4" endColumn="6" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="4" startColumn="6" endLine="4" endColumn="42" name="m">
<children xsi:type="Attribute" name="name" value="T"/>
<children xsi:type="Attribute" name="content" value="E"/>
</children>
<children xsi:type="Text" startLine="4" startColumn="42" endLine="5" endColumn="6" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="5" startColumn="6" endLine="5" endColumn="51" name="m">
<children xsi:type="Attribute" name="name" value="F"/>
<children xsi:type="Attribute" name="content" value="1546"/>
</children>
<children xsi:type="Text" startLine="5" startColumn="51" endLine="6" endColumn="6" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="6" startColumn="6" endLine="6" endColumn="46" name="m">
<children xsi:type="Attribute" name="name" value="D"/>
<children xsi:type="Attribute" name="content" value="15445"/>
</children>
<children xsi:type="Text" startLine="6" startColumn="46" endLine="7" endColumn="5" name="#text" value="&#xA; "/>
</children>
<children xsi:type="Text" startLine="7" startColumn="10" endLine="8" endColumn="4" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="8" startColumn="4" endLine="505" endColumn="16" name="N">
<children xsi:type="Text" startLine="8" startColumn="15" endLine="9" endColumn="6" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="9" startColumn="6" endLine="9" endColumn="208" name="I">
.....
</Root>

Re: XML2XML [message #1059768 is a reply to message #1059748] Tue, 21 May 2013 14:39 Go to previous messageGo to next message
samar sousou is currently offline samar sousouFriend
Messages: 63
Registered: March 2013
Member
hi
my input is:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Root xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="/projet2/metamodele/XML.xml" startLine="1" startColumn="1" endLine="11687" endColumn="13" name="x">
<children xsi:type="Text" startLine="2" startColumn="12" endLine="3" endColumn="4" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="3" startColumn="4" endLine="7" endColumn="10" name="h">
<children xsi:type="Text" startLine="3" startColumn="9" endLine="4" endColumn="6" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="4" startColumn="6" endLine="4" endColumn="42" name="m">
<children xsi:type="Attribute" name="name" value="T"/>
<children xsi:type="Attribute" name="content" value="4585"/>
</children>
<children xsi:type="Text" startLine="4" startColumn="42" endLine="5" endColumn="6" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="5" startColumn="6" endLine="5" endColumn="51" name="m">
<children xsi:type="Attribute" name="name" value="F"/>
<children xsi:type="Attribute" name="content" value="1545"/>
</children>
<children xsi:type="Text" startLine="5" startColumn="51" endLine="6" endColumn="6" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="6" startColumn="6" endLine="6" endColumn="46" name="m">
<children xsi:type="Attribute" name="name" value="Date"/>
<children xsi:type="Attribute" name="content" value="1454"/>
</children>
<children xsi:type="Text" startLine="6" startColumn="46" endLine="7" endColumn="5" name="#text" value="&#xA; "/>
</children>
.....
</Root>

Re: XML2XML [message #1059787 is a reply to message #1059768] Tue, 21 May 2013 15:28 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
In your transformation, do you have only one rule matching elements of type Root (i.e. the one in the first post of this conversation)?
If yes, I cannot understand why ATL would create several Root elements in your output model from one Root element in your input model...


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: XML2XML [message #1059800 is a reply to message #1059768] Tue, 21 May 2013 16:12 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You will generally save a lot of your own time as well as other people's
time for non-obvious problems if you take the trouble to produce a
zipped project with launch configuration that demonstrates your
observations.

Regards

Ed Willink


On 21/05/2013 15:39, samar sousou wrote:
> hi
> my input is:
>
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <Root xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns="/projet2/metamodele/XML.xml" startLine="1" startColumn="1"
> endLine="11687" endColumn="13" name="x">
> <children xsi:type="Text" startLine="2" startColumn="12" endLine="3"
> endColumn="4" name="#text" value="
> "/>
> <children xsi:type="Element" startLine="3" startColumn="4"
> endLine="7" endColumn="10" name="h">
> <children xsi:type="Text" startLine="3" startColumn="9" endLine="4"
> endColumn="6" name="#text" value="
> "/>
> <children xsi:type="Element" startLine="4" startColumn="6"
> endLine="4" endColumn="42" name="m">
> <children xsi:type="Attribute" name="name" value="T"/>
> <children xsi:type="Attribute" name="content" value="4585"/>
> </children>
> <children xsi:type="Text" startLine="4" startColumn="42"
> endLine="5" endColumn="6" name="#text" value="
> "/>
> <children xsi:type="Element" startLine="5" startColumn="6"
> endLine="5" endColumn="51" name="m">
> <children xsi:type="Attribute" name="name" value="F"/>
> <children xsi:type="Attribute" name="content" value="1545"/>
> </children>
> <children xsi:type="Text" startLine="5" startColumn="51"
> endLine="6" endColumn="6" name="#text" value="
> "/>
> <children xsi:type="Element" startLine="6" startColumn="6"
> endLine="6" endColumn="46" name="m">
> <children xsi:type="Attribute" name="name" value="Date"/>
> <children xsi:type="Attribute" name="content" value="1454"/>
> </children>
> <children xsi:type="Text" startLine="6" startColumn="46"
> endLine="7" endColumn="5" name="#text" value="
> "/>
> </children>
> ....
> </Root>
>
>
Re: XML2XML [message #1060004 is a reply to message #1059800] Wed, 22 May 2013 13:56 Go to previous messageGo to next message
samar sousou is currently offline samar sousouFriend
Messages: 63
Registered: March 2013
Member
Hi,
but i haven't the right to put a project here so this is my different files:

model.xmi
<?xml version="1.0" encoding="ISO-8859-1"?>
<Root xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="XML" startLine="1" startColumn="1" endLine="11687" endColumn="13" name="x">
<children xsi:type="Text" startLine="2" startColumn="12" endLine="3" endColumn="4" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="8" startColumn="4" endLine="505" endColumn="16" name="N">
<children xsi:type="Text" startLine="8" startColumn="15" endLine="9" endColumn="6" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="95" startColumn="6" endLine="95" endColumn="136" name="C">
<children xsi:type="Attribute" name="TypC" value="4"/>
<children xsi:type="Attribute" name="V" value="E"/>
</children>
<children xsi:type="Text" startLine="95" startColumn="136" endLine="96" endColumn="6" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="96" startColumn="6" endLine="96" endColumn="142" name="C">
<children xsi:type="Attribute" name="TypC" value="5"/>
<children xsi:type="Attribute" name="V" value="045"/>
</children>
<children xsi:type="Text" startLine="96" startColumn="142" endLine="97" endColumn="6" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="97" startColumn="6" endLine="97" endColumn="146" name="C">
<children xsi:type="Attribute" name="TypC" value="6"/>
<children xsi:type="Attribute" name="V" value="478"/>
</children>
<children xsi:type="Text" startLine="97" startColumn="146" endLine="98" endColumn="6" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="98" startColumn="6" endLine="98" endColumn="138" name="C">
<children xsi:type="Attribute" name="TypC" value="4"/>
<children xsi:type="Attribute" name="V" value="470"/>
</children>
<children xsi:type="Text" startLine="98" startColumn="138" endLine="99" endColumn="6" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="99" startColumn="6" endLine="99" endColumn="147" name="C">
<children xsi:type="Attribute" name="TypC" value="6"/>
<children xsi:type="Attribute" name="V" value="145"/>
</children>
<children xsi:type="Text" startLine="99" startColumn="147" endLine="100" endColumn="6" name="#text" value="&#xA; "/>
<children xsi:type="Element" startLine="100" startColumn="6" endLine="100" endColumn="142" name="C">
<children xsi:type="Attribute" name="TypC" value="7"/>
<children xsi:type="Attribute" name="V" value="148"/>
</children>
<children xsi:type="Text" startLine="504" startColumn="107" endLine="505" endColumn="5" name="#text" value="&#xA; "/>
</children>
<children xsi:type="Text" startLine="11686" startColumn="19" endLine="11687" endColumn="3" name="#text" value="&#xA;"/>
</Root>



XML.ecore
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI 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">
<ecore:EPackage name="PrimitiveTypes">
<eClassifiers xsi:type="ecore:EDataType" name="Boolean"/>
<eClassifiers xsi:type="ecore:EDataType" name="Integer"/>
<eClassifiers xsi:type="ecore:EDataType" name="String"/>
</ecore:EPackage>
<ecore:EPackage name="XML">
<eClassifiers xsi:type="ecore:EClass" name="Node" abstract="true">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="startLine" ordered="false" eType="/0/Integer"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="startColumn" ordered="false" eType="/0/Integer"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="endLine" ordered="false" eType="/0/Integer"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="endColumn" ordered="false" eType="/0/Integer"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="name" ordered="false" lowerBound="1" eType="/0/String"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="value" ordered="false" lowerBound="1" eType="/0/String"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="parent" ordered="false" eType="/1/Element" eOpposite="/1/Element/children"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Attribute" eSuperTypes="/1/Node"/>
<eClassifiers xsi:type="ecore:EClass" name="Text" eSuperTypes="/1/Node"/>
<eClassifiers xsi:type="ecore:EClass" name="Element" eSuperTypes="/1/Node">
<eStructuralFeatures xsi:type="ecore:EReference" name="children" upperBound="-1" eType="/1/Node" containment="true" eOpposite="/1/Node/parent"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Root" eSuperTypes="/1/Element"/>
</ecore:EPackage>
</xmi:XMI>


xml2xml.atl

-- @path XMLC=/projetSQL/M2/XML.ecore
-- @path XMLS=/projetSQL/M2/XML.ecore

module xml2xml2;
create OUT : XMLC from IN : XMLS;

helper context XMLS!Element def: getStringAttrValue(attrName : String) : String =
let eltC : Sequence(XML!Attribute) =
self.children->select(a | a.oclIsTypeOf(XMLS!Attribute) and a.name = attrName)->asSequence()
in
if eltC->notEmpty()
then
eltC->first().value
else
''
endif;
--rule Root--
rule Root {
from
i: XMLS!Root,
i1:XMLS!Element(i1.name='C')
to
o : XMLC!Root (
name <- i.name,
children <- Sequence{comp}
),
comp:XMLC!Element(
name <- 'Composant',
children <- Sequence{tyComp}
),
tyComp:XMLC!Attribute(
name <- i1.getStringAttrValue('TypC')
)
}

and my result is:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="XML">
<Root name="x">
<children xsi:type="Element" name="Composant">
<children xsi:type="Attribute" name="4"/>
</children>
</Root>
<Root name="x">
<children xsi:type="Element" name="Composant">
<children xsi:type="Attribute" name="5"/>
</children>
</Root>
<Root name="x">
<children xsi:type="Element" name="Composant">
<children xsi:type="Attribute" name="6"/>
</children>
</Root>
<Root name="x">
<children xsi:type="Element" name="Composant">
<children xsi:type="Attribute" name="4"/>
</children>
</Root>
<Root name="x">
<children xsi:type="Element" name="Composant">
<children xsi:type="Attribute" name="6"/>
</children>
</Root>
<Root name="x">
<children xsi:type="Element" name="Composant">
<children xsi:type="Attribute" name="7"/>
</children>
</Root>
</xmi:XMI>


I need your help,
thank you,

Samar.
Re: XML2XML [message #1060048 is a reply to message #1060004] Wed, 22 May 2013 16:15 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

The transformation you've just shown in your last post is not the same than the one shown in your original post: please, in the future, be sure to provide the right transformation when asking your questions otherwise it is not possible for the community to provide you a good answer.

Anyway, the result model you obtain is normal according to the specified transformation: you are asking for a matching on each tuple of the Cartesian product between the Root and Element elements of your input model (as you have two elements in the rule input pattern), so you get in output as much Root elements as you have of Element elements in input.

If you go back to the initial ROOT rule (cf. your first post), you will get only one Root element in your output model.
You then have to create another rule to match the Element elements, etc.

Best regards,


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: XML2XML [message #1060049 is a reply to message #1060048] Wed, 22 May 2013 16:27 Go to previous messageGo to next message
samar sousou is currently offline samar sousouFriend
Messages: 63
Registered: March 2013
Member
thank you for the response,

yes i change the code but the first one what i want.

look i cearte now an other code:
-- @path XMLC=/projetSQL/M2/XML.ecore
-- @path XMLS=/projetSQL/M2/XML.ecore

module xml2xml2;
create OUT : XMLC from IN : XMLS;

helper context XMLS!Element def: getStringAttrValue(attrName : String) : String =
let eltC : Sequence(XML!Attribute) =
self.children->select(a | a.oclIsTypeOf(XMLS!Attribute) and a.name = attrName)->asSequence()
in
if eltC->notEmpty()
then
eltC->first().value
else
''
endif;
helper context XMLS!Element def : getChildrenbyNameElement(attr:String) : Set(XMLS!Element) =
self.children->select(a | a.oclIsTypeOf(XMLS!Element) and a.name=attr)->asSequence()
;
helper context XMLS!Root def : getChildrenbyName(attr:String) : Set(XMLS!Element) =
self.children->select(a | a.oclIsTypeOf(XMLS!Element) and a.name=attr)->asSequence()
;
helper context XMLS!Element def : getchildren(a:String) : String =
let e:Sequence(XMLS!Element)=
self.getChildrenbyNameElement('C')
in
if e->notEmpty()
then
e->first().getStringAttrValue(a)
else
''
endif
;


helper context XMLS!Root def : getCN(a:String) : String =
let e:Sequence(XMLS!Element)=
self.getChildrenbyName('N')->asSequence()
in
if e->notEmpty()
then
e->first().getchildren(a)
else
''
endif
;

--rule Root--
rule Root {
from
i: XMLS!Root
to
o : XMLC!Root (
name <- i.name,
children <- Sequence{comp}
),
comp:XMLC!Element(
name <- 'Composant',
children <- Sequence{tyComp}
),
tyComp:XMLC!Attribute(
name <- i.getCN('TypC')
)
}


but as a result with the same model, i get only the first instance:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Root xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="XML" name="x">
<children xsi:type="Element" name="Composant">
<children xsi:type="Attribute" name="4"/>
</children>
</Root>
Thank you,

Samar.
Re: XML2XML [message #1060096 is a reply to message #1060049] Thu, 23 May 2013 06:30 Go to previous messageGo to next message
samar sousou is currently offline samar sousouFriend
Messages: 63
Registered: March 2013
Member
I need your help please

Samar
Re: XML2XML [message #1060138 is a reply to message #1060096] Thu, 23 May 2013 09:32 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
Hello,

As I already said in my previous post:
If you go back to the initial ROOT rule (cf. your first post), you will get only one Root element in your output model.
You then have to create another rule to match the Element elements, etc.


So you should have a dedicated rule to deal with Element elements, another rule to deal with the Attribute elements, etc. The overall structure of your transformation should look like the following (please read carefully the ATL user guide that explains everything with a lot of details):
rule RootToRoot {
from
i: XMLS!Root
to 
o : XMLC!Root (
name <- i.name,
children <- i.children->union(Sequence{comp})
),
comp:XMLC!Element(
name <- 'Composant',
children <- Sequence{tyComp}
),
tyComp:XMLC!Attribute(
name <- i.getCN('TypC')
)
}

rule ElementToElement {
from
i: XMLS!Element
to 
o : XMLC!Element (
...
...
...
)
}

rule Attribute2Attribute {
from
i: XMLS!Attribute
to 
o : XMLC!Attribute (
...
...
...
)
}

Etc.


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Re: XML2XML [message #1060181 is a reply to message #1060138] Thu, 23 May 2013 12:13 Go to previous messageGo to next message
samar sousou is currently offline samar sousouFriend
Messages: 63
Registered: March 2013
Member
Thank you very much,
but when i run this code

-- @path XMLC=/XML2XMLproject/M2/XML.ecore
-- @path XMLS=/XML2XMLproject/M2/XML.ecore

module xml2xmlpropose;
create OUT : XMLC from IN : XMLS;

helper context XMLS!Root def : getCN(a:String) : String =
let e:Sequence(XMLS!Element)=
self.getChildrenbyName('N')->asSequence()
in
if e->notEmpty()
then
e->first().getchildren(a)
else
''
endif
;
helper context XMLS!Element def: getStringAttrValue(attrName : String) : String =
let eltC : Sequence(XML!Attribute) =
self.children->select(a | a.oclIsTypeOf(XMLS!Attribute) and a.name = attrName)->asSequence()
in
if eltC->notEmpty()
then
eltC->first().value
else
''
endif;
helper context XMLS!Root def : getChildrenbyName(attr:String) : Set(XMLS!Element) =
self.children->select(a | a.oclIsTypeOf(XMLS!Element) and a.name=attr)->asSequence()
;
helper context XMLS!Element def : getchildren(a:String) : String =
let e:Sequence(XMLS!Element)=
self.children->select(b |b.oclIsTypeOf(XMLS!Element)and b.name='C')->asSequence()
in
if e->notEmpty()
then
e->first().getStringAttrValue(a)
else
''
endif
;

rule RootToRoot {
from
i: XMLS!Root
to
o : XMLC!Root (
name <- i.name,
children <- i.children->union(Sequence{comp})
),
comp:XMLC!Element(
name <- 'Composant',
children <- Sequence{tyComp}
),
tyComp:XMLC!Attribute(
name <- i.getCN('TypC')
)
}
rule ElementToElement {
from
i: XMLS!Element
to
o : XMLC!Element (
name <- i.name
)
}

rule Attribute2Attribute {
from
i: XMLS!Attribute
to
o : XMLC!Attribute (
name <- i.name,
value <- i.value
)
}
I get an error "-- @path XMLC=/XML2XMLproject/M2/XML.ecore
-- @path XMLS=/XML2XMLproject/M2/XML.ecore

module xml2xmlpropose;
create OUT : XMLC from IN : XMLS;

helper context XMLS!Root def : getCN(a:String) : String =
let e:Sequence(XMLS!Element)=
self.getChildrenbyName('N')->asSequence()
in
if e->notEmpty()
then
e->first().getchildren(a)
else
''
endif
;
helper context XMLS!Element def: getStringAttrValue(attrName : String) : String =
let eltC : Sequence(XML!Attribute) =
self.children->select(a | a.oclIsTypeOf(XMLS!Attribute) and a.name = attrName)->asSequence()
in
if eltC->notEmpty()
then
eltC->first().value
else
''
endif;
helper context XMLS!Root def : getChildrenbyName(attr:String) : Set(XMLS!Element) =
self.children->select(a | a.oclIsTypeOf(XMLS!Element) and a.name=attr)->asSequence()
;
helper context XMLS!Element def : getchildren(a:String) : String =
let e:Sequence(XMLS!Element)=
self.children->select(b |b.oclIsTypeOf(XMLS!Element)and b.name='C')->asSequence()
in
if e->notEmpty()
then
e->first().getStringAttrValue(a)
else
''
endif
;

rule RootToRoot {
from
i: XMLS!Root
to
o : XMLC!Root (
name <- i.name,
children <- i.children->union(Sequence{comp})
),
comp:XMLC!Element(
name <- 'Composant',
children <- Sequence{tyComp}
),
tyComp:XMLC!Attribute(
name <- i.getCN('TypC')
)
}
rule ElementToElement {
from
i: XMLS!Element
to
o : XMLC!Element (
name <- i.name
)
}

rule Attribute2Attribute {
from
i: XMLS!Attribute
to
o : XMLC!Attribute (
name <- i.name,
value <- i.value
)
}
I get an error "-- @path XMLC=/XML2XMLproject/M2/XML.ecore
-- @path XMLS=/XML2XMLproject/M2/XML.ecore

module xml2xmlpropose;
create OUT : XMLC from IN : XMLS;

helper context XMLS!Root def : getCN(a:String) : String =
let e:Sequence(XMLS!Element)=
self.getChildrenbyName('N')->asSequence()
in
if e->notEmpty()
then
e->first().getchildren(a)
else
''
endif
;
helper context XMLS!Element def: getStringAttrValue(attrName : String) : String =
let eltC : Sequence(XML!Attribute) =
self.children->select(a | a.oclIsTypeOf(XMLS!Attribute) and a.name = attrName)->asSequence()
in
if eltC->notEmpty()
then
eltC->first().value
else
''
endif;
helper context XMLS!Root def : getChildrenbyName(attr:String) : Set(XMLS!Element) =
self.children->select(a | a.oclIsTypeOf(XMLS!Element) and a.name=attr)->asSequence()
;
helper context XMLS!Element def : getchildren(a:String) : String =
let e:Sequence(XMLS!Element)=
self.children->select(b |b.oclIsTypeOf(XMLS!Element)and b.name='C')->asSequence()
in
if e->notEmpty()
then
e->first().getStringAttrValue(a)
else
''
endif
;

rule RootToRoot {
from
i: XMLS!Root
to
o : XMLC!Root (
name <- i.name,
children <- i.children->union(Sequence{comp})
),
comp:XMLC!Element(
name <- 'Composant',
children <- Sequence{tyComp}
),
tyComp:XMLC!Attribute(
name <- i.getCN('TypC')
)
}
rule ElementToElement {
from
i: XMLS!Element
to
o : XMLC!Element (
name <- i.name
)
}

rule Attribute2Attribute {
from
i: XMLS!Attribute
to
o : XMLC!Attribute (
name <- i.name,
value <- i.value
)
}


I get an error "org.eclipse.m2m.atl.engine.emfvm.VMException: Trying to register several rules as default for element org.eclipse.emf.ecore.impl.DynamicEObjectImpl@1a24699 (eClass: org.eclipse.emf.ecore.impl.EClassImpl@1b25736 (name: Root) (instanceClassName: null) (abstract: false, interface: false)) : RootToRoot and ElementToElement"

It works for you!!
Thank you.
Samar
Re: XML2XML [message #1060255 is a reply to message #1060181] Thu, 23 May 2013 17:11 Go to previous message
Hugo Bruneliere is currently offline Hugo BruneliereFriend
Messages: 674
Registered: July 2009
Senior Member
If you look to the XML metamodel you are using, I guess you will see that Root is inheriting from Element (which means that a Root element is also an Element element, that could be why you have your error).
Thus, in your ElementToElement rule, you have to add a filter to avoid such a Root element to be matched twice (i.e. also by the RootToRoot rule):
rule ElementToElement {
from
i: XMLS!Element (
 not i.oclIsTypeOf(XMLS!Root)
)


--------------------------------------------------------
Hugo Bruneliere, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
Previous Topic:XML2XMLProject
Next Topic:Comparing Large Numbers Fails with ATL 3.2.1
Goto Forum:
  


Current Time: Thu Mar 28 22:50:29 GMT 2024

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

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

Back to the top