XML2XML [message #1059470] |
Sun, 19 May 2013 06:23  |
Eclipse User |
|
|
|
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 #1060138 is a reply to message #1060096] |
Thu, 23 May 2013 05:32   |
Eclipse User |
|
|
|
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.
|
|
|
Re: XML2XML [message #1060181 is a reply to message #1060138] |
Thu, 23 May 2013 08:13   |
Eclipse User |
|
|
|
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 13:11  |
Eclipse User |
|
|
|
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)
)
|
|
|
Powered by
FUDForum. Page generated in 0.09196 seconds