Home » Modeling » ATL » XML2XML
XML2XML [message #1059470] |
Sun, 19 May 2013 10:23 |
samar sousou 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 #1060048 is a reply to message #1060004] |
Wed, 22 May 2013 16:15 |
Hugo Bruneliere 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 #1060138 is a reply to message #1060096] |
Thu, 23 May 2013 09:32 |
Hugo Bruneliere 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 |
samar sousou 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 |
Hugo Bruneliere 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
--------------------------------------------------------
|
|
|
Goto Forum:
Current Time: Sat Sep 21 04:40:20 GMT 2024
Powered by FUDForum. Page generated in 0.06231 seconds
|